Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/PresentationConnectionCloseEventBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM PresentationConnectionCloseEvent.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AtomList.h"
4
#include "EventBinding.h"
5
#include "PresentationConnectionCloseEventBinding.h"
6
#include "WrapperFactory.h"
7
#include "jsapi.h"
8
#include "mozilla/OwningNonNull.h"
9
#include "mozilla/Preferences.h"
10
#include "mozilla/dom/BindingUtils.h"
11
#include "mozilla/dom/DOMJSClass.h"
12
#include "mozilla/dom/NonRefcountedDOMObject.h"
13
#include "mozilla/dom/PresentationConnectionCloseEvent.h"
14
#include "mozilla/dom/PrimitiveConversions.h"
15
#include "mozilla/dom/ScriptSettings.h"
16
#include "mozilla/dom/SimpleGlobalObject.h"
17
#include "mozilla/dom/XrayExpandoClass.h"
18
19
namespace mozilla {
20
namespace dom {
21
22
namespace binding_detail {}; // Just to make sure it's known as a namespace
23
using namespace mozilla::dom::binding_detail;
24
25
26
namespace PresentationConnectionClosedReasonValues {
27
extern const EnumEntry strings[4] = {
28
  {"error", 5},
29
  {"closed", 6},
30
  {"wentaway", 8},
31
  { nullptr, 0 }
32
};
33
} // namespace PresentationConnectionClosedReasonValues
34
35
bool
36
ToJSValue(JSContext* aCx, PresentationConnectionClosedReason aArgument, JS::MutableHandle<JS::Value> aValue)
37
0
{
38
0
  MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(PresentationConnectionClosedReasonValues::strings));
39
0
  JSString* resultStr =
40
0
    JS_NewStringCopyN(aCx, PresentationConnectionClosedReasonValues::strings[uint32_t(aArgument)].value,
41
0
                      PresentationConnectionClosedReasonValues::strings[uint32_t(aArgument)].length);
42
0
  if (!resultStr) {
43
0
    return false;
44
0
  }
45
0
  aValue.setString(resultStr);
46
0
  return true;
47
0
}
48
49
50
51
PresentationConnectionCloseEventInit::PresentationConnectionCloseEventInit()
52
  : EventInit(FastDictionaryInitializer())
53
0
{
54
0
  // Safe to pass a null context if we pass a null value
55
0
  Init(nullptr, JS::NullHandleValue);
56
0
}
57
58
59
60
bool
61
PresentationConnectionCloseEventInit::InitIds(JSContext* cx, PresentationConnectionCloseEventInitAtoms* atomsCache)
62
0
{
63
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
64
0
65
0
  // Initialize these in reverse order so that any failure leaves the first one
66
0
  // uninitialized.
67
0
  if (!atomsCache->reason_id.init(cx, "reason") ||
68
0
      !atomsCache->message_id.init(cx, "message")) {
69
0
    return false;
70
0
  }
71
0
  return true;
72
0
}
73
74
bool
75
PresentationConnectionCloseEventInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
76
0
{
77
0
  // Passing a null JSContext is OK only if we're initing from null,
78
0
  // Since in that case we will not have to do any property gets
79
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
80
0
  // checkers by static analysis tools
81
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
82
0
  PresentationConnectionCloseEventInitAtoms* atomsCache = nullptr;
83
0
  if (cx) {
84
0
    atomsCache = GetAtomCache<PresentationConnectionCloseEventInitAtoms>(cx);
85
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
86
0
      return false;
87
0
    }
88
0
  }
89
0
90
0
  // Per spec, we init the parent's members first
91
0
  if (!EventInit::Init(cx, val)) {
92
0
    return false;
93
0
  }
94
0
95
0
  bool isNull = val.isNullOrUndefined();
96
0
  // We only need these if !isNull, in which case we have |cx|.
97
0
  Maybe<JS::Rooted<JSObject *> > object;
98
0
  Maybe<JS::Rooted<JS::Value> > temp;
99
0
  if (!isNull) {
100
0
    MOZ_ASSERT(cx);
101
0
    object.emplace(cx, &val.toObject());
102
0
    temp.emplace(cx);
103
0
  }
104
0
  if (!isNull) {
105
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->message_id, temp.ptr())) {
106
0
      return false;
107
0
    }
108
0
  }
109
0
  if (!isNull && !temp->isUndefined()) {
110
0
    if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mMessage)) {
111
0
      return false;
112
0
    }
113
0
  } else {
114
0
    static const char16_t data[] = { 0 };
115
0
    mMessage.Rebind(data, ArrayLength(data) - 1);
116
0
  }
117
0
  mIsAnyMemberPresent = true;
118
0
119
0
  if (!isNull) {
120
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->reason_id, temp.ptr())) {
121
0
      return false;
122
0
    }
123
0
  }
124
0
  if (!isNull && !temp->isUndefined()) {
125
0
    {
126
0
      int index;
127
0
      if (!FindEnumStringIndex<true>(cx, temp.ref(), PresentationConnectionClosedReasonValues::strings, "PresentationConnectionClosedReason", "'reason' member of PresentationConnectionCloseEventInit", &index)) {
128
0
        return false;
129
0
      }
130
0
      MOZ_ASSERT(index >= 0);
131
0
      mReason = static_cast<PresentationConnectionClosedReason>(index);
132
0
    }
133
0
    mIsAnyMemberPresent = true;
134
0
  } else if (cx) {
135
0
    // Don't error out if we have no cx.  In that
136
0
    // situation the caller is default-constructing us and we'll
137
0
    // just assume they know what they're doing.
138
0
    return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER,
139
0
                             "'reason' member of PresentationConnectionCloseEventInit");
140
0
  }
141
0
  return true;
142
0
}
143
144
bool
145
PresentationConnectionCloseEventInit::Init(const nsAString& aJSON)
146
0
{
147
0
  AutoJSAPI jsapi;
148
0
  JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
149
0
  if (!cleanGlobal) {
150
0
    return false;
151
0
  }
152
0
  if (!jsapi.Init(cleanGlobal)) {
153
0
    return false;
154
0
  }
155
0
  JSContext* cx = jsapi.cx();
156
0
  JS::Rooted<JS::Value> json(cx);
157
0
  bool ok = ParseJSON(cx, aJSON, &json);
158
0
  NS_ENSURE_TRUE(ok, false);
159
0
  return Init(cx, json);
160
0
}
161
162
bool
163
PresentationConnectionCloseEventInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
164
0
{
165
0
  PresentationConnectionCloseEventInitAtoms* atomsCache = GetAtomCache<PresentationConnectionCloseEventInitAtoms>(cx);
166
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
167
0
    return false;
168
0
  }
169
0
170
0
  // Per spec, we define the parent's members first
171
0
  if (!EventInit::ToObjectInternal(cx, rval)) {
172
0
    return false;
173
0
  }
174
0
  JS::Rooted<JSObject*> obj(cx, &rval.toObject());
175
0
176
0
  do {
177
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
178
0
    JS::Rooted<JS::Value> temp(cx);
179
0
    nsString const & currentValue = mMessage;
180
0
    if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
181
0
      return false;
182
0
    }
183
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->message_id, temp, JSPROP_ENUMERATE)) {
184
0
      return false;
185
0
    }
186
0
    break;
187
0
  } while(false);
188
0
189
0
  do {
190
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
191
0
    JS::Rooted<JS::Value> temp(cx);
192
0
    PresentationConnectionClosedReason const & currentValue = mReason;
193
0
    if (!ToJSValue(cx, currentValue, &temp)) {
194
0
      return false;
195
0
    }
196
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->reason_id, temp, JSPROP_ENUMERATE)) {
197
0
      return false;
198
0
    }
199
0
    break;
200
0
  } while(false);
201
0
202
0
  return true;
203
0
}
204
205
bool
206
PresentationConnectionCloseEventInit::ToJSON(nsAString& aJSON) const
207
0
{
208
0
  AutoJSAPI jsapi;
209
0
  jsapi.Init();
210
0
  JSContext *cx = jsapi.cx();
211
0
  // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
212
0
  // because we'll only be creating objects, in ways that have no
213
0
  // side-effects, followed by a call to JS::ToJSONMaybeSafely,
214
0
  // which likewise guarantees no side-effects for the sorts of
215
0
  // things we will pass it.
216
0
  JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
217
0
  JS::Rooted<JS::Value> val(cx);
218
0
  if (!ToObjectInternal(cx, &val)) {
219
0
    return false;
220
0
  }
221
0
  JS::Rooted<JSObject*> obj(cx, &val.toObject());
222
0
  return StringifyToJSON(cx, obj, aJSON);
223
0
}
224
225
void
226
PresentationConnectionCloseEventInit::TraceDictionary(JSTracer* trc)
227
0
{
228
0
  EventInit::TraceDictionary(trc);
229
0
}
230
231
PresentationConnectionCloseEventInit&
232
PresentationConnectionCloseEventInit::operator=(const PresentationConnectionCloseEventInit& aOther)
233
0
{
234
0
  EventInit::operator=(aOther);
235
0
  mMessage = aOther.mMessage;
236
0
  mReason = aOther.mReason;
237
0
  return *this;
238
0
}
239
240
namespace binding_detail {
241
} // namespace binding_detail
242
243
244
namespace PresentationConnectionCloseEvent_Binding {
245
246
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<Event_Binding::NativeType>::value,
247
              "Can't inherit from an interface with a different ownership model.");
248
249
MOZ_CAN_RUN_SCRIPT static bool
250
get_reason(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PresentationConnectionCloseEvent* self, JSJitGetterCallArgs args)
251
0
{
252
0
  AUTO_PROFILER_LABEL_FAST("get PresentationConnectionCloseEvent.reason", DOM, cx);
253
0
254
0
  PresentationConnectionClosedReason result(self->Reason());
255
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
256
0
  if (!ToJSValue(cx, result, args.rval())) {
257
0
    return false;
258
0
  }
259
0
  return true;
260
0
}
261
262
static const JSJitInfo reason_getterinfo = {
263
  { (JSJitGetterOp)get_reason },
264
  { prototypes::id::PresentationConnectionCloseEvent },
265
  { PrototypeTraits<prototypes::id::PresentationConnectionCloseEvent>::Depth },
266
  JSJitInfo::Getter,
267
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
268
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
269
  false,  /* isInfallible. False in setters. */
270
  false,  /* isMovable.  Not relevant for setters. */
271
  false, /* isEliminatable.  Not relevant for setters. */
272
  false, /* isAlwaysInSlot.  Only relevant for getters. */
273
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
274
  false,  /* isTypedMethod.  Only relevant for methods. */
275
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
276
};
277
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
278
static_assert(0 < 1, "There is no slot for us");
279
280
MOZ_CAN_RUN_SCRIPT static bool
281
get_message(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PresentationConnectionCloseEvent* self, JSJitGetterCallArgs args)
282
0
{
283
0
  AUTO_PROFILER_LABEL_FAST("get PresentationConnectionCloseEvent.message", DOM, cx);
284
0
285
0
  DOMString result;
286
0
  self->GetMessage(result);
287
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
288
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
289
0
    return false;
290
0
  }
291
0
  return true;
292
0
}
293
294
static const JSJitInfo message_getterinfo = {
295
  { (JSJitGetterOp)get_message },
296
  { prototypes::id::PresentationConnectionCloseEvent },
297
  { PrototypeTraits<prototypes::id::PresentationConnectionCloseEvent>::Depth },
298
  JSJitInfo::Getter,
299
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
300
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
301
  false,  /* isInfallible. False in setters. */
302
  false,  /* isMovable.  Not relevant for setters. */
303
  false, /* isEliminatable.  Not relevant for setters. */
304
  false, /* isAlwaysInSlot.  Only relevant for getters. */
305
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
306
  false,  /* isTypedMethod.  Only relevant for methods. */
307
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
308
};
309
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
310
static_assert(0 < 1, "There is no slot for us");
311
312
MOZ_CAN_RUN_SCRIPT static bool
313
get_isTrusted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PresentationConnectionCloseEvent* self, JSJitGetterCallArgs args)
314
0
{
315
0
  AUTO_PROFILER_LABEL_FAST("get PresentationConnectionCloseEvent.isTrusted", DOM, cx);
316
0
317
0
  bool result(self->IsTrusted());
318
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
319
0
  args.rval().setBoolean(result);
320
0
  return true;
321
0
}
322
323
static const JSJitInfo isTrusted_getterinfo = {
324
  { (JSJitGetterOp)get_isTrusted },
325
  { prototypes::id::PresentationConnectionCloseEvent },
326
  { PrototypeTraits<prototypes::id::PresentationConnectionCloseEvent>::Depth },
327
  JSJitInfo::Getter,
328
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
329
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
330
  true,  /* isInfallible. False in setters. */
331
  true,  /* isMovable.  Not relevant for setters. */
332
  true, /* isEliminatable.  Not relevant for setters. */
333
  false, /* isAlwaysInSlot.  Only relevant for getters. */
334
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
335
  false,  /* isTypedMethod.  Only relevant for methods. */
336
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
337
};
338
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
339
static_assert(0 < 1, "There is no slot for us");
340
341
static bool
342
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
343
0
{
344
0
  mozilla::dom::PresentationConnectionCloseEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PresentationConnectionCloseEvent>(obj);
345
0
  // We don't want to preserve if we don't have a wrapper, and we
346
0
  // obviously can't preserve if we're not initialized.
347
0
  if (self && self->GetWrapperPreserveColor()) {
348
0
    PreserveWrapper(self);
349
0
  }
350
0
  return true;
351
0
}
352
353
static void
354
_finalize(js::FreeOp* fop, JSObject* obj)
355
0
{
356
0
  mozilla::dom::PresentationConnectionCloseEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PresentationConnectionCloseEvent>(obj);
357
0
  if (self) {
358
0
    ClearWrapper(self, self, obj);
359
0
    AddForDeferredFinalization<mozilla::dom::PresentationConnectionCloseEvent>(self);
360
0
  }
361
0
}
362
363
static size_t
364
_objectMoved(JSObject* obj, JSObject* old)
365
0
{
366
0
  mozilla::dom::PresentationConnectionCloseEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PresentationConnectionCloseEvent>(obj);
367
0
  if (self) {
368
0
    UpdateWrapper(self, self, obj, old);
369
0
  }
370
0
371
0
  return 0;
372
0
}
373
374
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
375
#if defined(__clang__)
376
#pragma clang diagnostic push
377
#pragma clang diagnostic ignored "-Wmissing-braces"
378
#endif
379
static const JSPropertySpec sAttributes_specs[] = {
380
  { "reason", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &reason_getterinfo, nullptr, nullptr },
381
  { "message", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &message_getterinfo, nullptr, nullptr },
382
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
383
};
384
#if defined(__clang__)
385
#pragma clang diagnostic pop
386
#endif
387
388
389
static const Prefable<const JSPropertySpec> sAttributes[] = {
390
  { nullptr, &sAttributes_specs[0] },
391
  { nullptr, nullptr }
392
};
393
394
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
395
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
396
static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
397
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
398
399
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
400
#if defined(__clang__)
401
#pragma clang diagnostic push
402
#pragma clang diagnostic ignored "-Wmissing-braces"
403
#endif
404
static const JSPropertySpec sUnforgeableAttributes_specs[] = {
405
  { "isTrusted", JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericGetter<NormalThisPolicy, ThrowExceptions>, &isTrusted_getterinfo, nullptr, nullptr },
406
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
407
};
408
#if defined(__clang__)
409
#pragma clang diagnostic pop
410
#endif
411
412
413
static const Prefable<const JSPropertySpec> sUnforgeableAttributes[] = {
414
  { nullptr, &sUnforgeableAttributes_specs[0] },
415
  { nullptr, nullptr }
416
};
417
418
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
419
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
420
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
421
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
422
423
424
static uint16_t sNativeProperties_sortedPropertyIndices[3];
425
static PropertyInfo sNativeProperties_propertyInfos[3];
426
427
static const NativePropertiesN<2> sNativeProperties = {
428
  false, 0,
429
  false, 0,
430
  false, 0,
431
  true,  0 /* sAttributes */,
432
  false, 0,
433
  true,  1 /* sUnforgeableAttributes */,
434
  false, 0,
435
  -1,
436
  3,
437
  sNativeProperties_sortedPropertyIndices,
438
  {
439
    { sAttributes, &sNativeProperties_propertyInfos[0] },
440
    { sUnforgeableAttributes, &sNativeProperties_propertyInfos[2] }
441
  }
442
};
443
static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
444
    "We have a property info count that is oversized");
445
446
static bool
447
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
448
0
{
449
0
  AUTO_PROFILER_LABEL_FAST("PresentationConnectionCloseEvent constructor", DOM, cx);
450
0
451
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
452
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
453
0
  if (!args.isConstructing()) {
454
0
    // XXXbz wish I could get the name from the callee instead of
455
0
    // Adding more relocations
456
0
    return ThrowConstructorWithoutNew(cx, "PresentationConnectionCloseEvent");
457
0
  }
458
0
459
0
  JS::Rooted<JSObject*> desiredProto(cx);
460
0
  if (!GetDesiredProto(cx, args, &desiredProto)) {
461
0
    return false;
462
0
  }
463
0
464
0
  if (MOZ_UNLIKELY(args.length() < 2)) {
465
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "PresentationConnectionCloseEvent");
466
0
  }
467
0
  GlobalObject global(cx, obj);
468
0
  if (global.Failed()) {
469
0
    return false;
470
0
  }
471
0
472
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
473
0
  binding_detail::FakeString arg0;
474
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
475
0
    return false;
476
0
  }
477
0
  binding_detail::FastPresentationConnectionCloseEventInit arg1;
478
0
  if (!arg1.Init(cx, args[1],  "Argument 2 of PresentationConnectionCloseEvent.constructor", false)) {
479
0
    return false;
480
0
  }
481
0
  Maybe<JSAutoRealm> ar;
482
0
  if (objIsXray) {
483
0
    obj = js::CheckedUnwrap(obj);
484
0
    if (!obj) {
485
0
      return false;
486
0
    }
487
0
    ar.emplace(cx, obj);
488
0
    if (!JS_WrapObject(cx, &desiredProto)) {
489
0
      return false;
490
0
    }
491
0
  }
492
0
  FastErrorResult rv;
493
0
  auto result(StrongOrRawPtr<mozilla::dom::PresentationConnectionCloseEvent>(mozilla::dom::PresentationConnectionCloseEvent::Constructor(global, NonNullHelper(Constify(arg0)), Constify(arg1), rv)));
494
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
495
0
    return false;
496
0
  }
497
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
498
0
  static_assert(!IsPointer<decltype(result)>::value,
499
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
500
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
501
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
502
0
    return false;
503
0
  }
504
0
  return true;
505
0
}
506
507
static const js::ClassOps sInterfaceObjectClassOps = {
508
    nullptr,               /* addProperty */
509
    nullptr,               /* delProperty */
510
    nullptr,               /* enumerate */
511
    nullptr,               /* newEnumerate */
512
    nullptr,               /* resolve */
513
    nullptr,               /* mayResolve */
514
    nullptr,               /* finalize */
515
    _constructor, /* call */
516
    nullptr,               /* hasInstance */
517
    _constructor, /* construct */
518
    nullptr,               /* trace */
519
};
520
521
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
522
  {
523
    "Function",
524
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
525
    &sInterfaceObjectClassOps,
526
    JS_NULL_CLASS_SPEC,
527
    JS_NULL_CLASS_EXT,
528
    &sInterfaceObjectClassObjectOps
529
  },
530
  eInterface,
531
  true,
532
  prototypes::id::PresentationConnectionCloseEvent,
533
  PrototypeTraits<prototypes::id::PresentationConnectionCloseEvent>::Depth,
534
  sNativePropertyHooks,
535
  "function PresentationConnectionCloseEvent() {\n    [native code]\n}",
536
  Event_Binding::GetConstructorObject
537
};
538
539
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
540
  {
541
    "PresentationConnectionCloseEventPrototype",
542
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */),
543
    JS_NULL_CLASS_OPS,
544
    JS_NULL_CLASS_SPEC,
545
    JS_NULL_CLASS_EXT,
546
    JS_NULL_OBJECT_OPS
547
  },
548
  eInterfacePrototype,
549
  false,
550
  prototypes::id::PresentationConnectionCloseEvent,
551
  PrototypeTraits<prototypes::id::PresentationConnectionCloseEvent>::Depth,
552
  sNativePropertyHooks,
553
  "[object PresentationConnectionCloseEventPrototype]",
554
  Event_Binding::GetProtoObject
555
};
556
557
bool
558
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
559
0
{
560
0
  static bool sPrefValue;
561
0
  static bool sPrefCacheSetUp = false;
562
0
  if (!sPrefCacheSetUp) {
563
0
    sPrefCacheSetUp = true;
564
0
    Preferences::AddBoolVarCache(&sPrefValue, "dom.presentation.enabled");
565
0
  }
566
0
567
0
  return sPrefValue;
568
0
}
569
570
static const js::ClassOps sClassOps = {
571
  _addProperty, /* addProperty */
572
  nullptr,               /* delProperty */
573
  nullptr,               /* enumerate */
574
  nullptr, /* newEnumerate */
575
  nullptr, /* resolve */
576
  nullptr, /* mayResolve */
577
  _finalize, /* finalize */
578
  nullptr, /* call */
579
  nullptr,               /* hasInstance */
580
  nullptr,               /* construct */
581
  nullptr, /* trace */
582
};
583
584
static const js::ClassExtension sClassExtension = {
585
  nullptr, /* weakmapKeyDelegateOp */
586
  _objectMoved /* objectMovedOp */
587
};
588
589
static const DOMJSClass sClass = {
590
  { "PresentationConnectionCloseEvent",
591
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_SKIP_NURSERY_FINALIZE,
592
    &sClassOps,
593
    JS_NULL_CLASS_SPEC,
594
    &sClassExtension,
595
    JS_NULL_OBJECT_OPS
596
  },
597
  { prototypes::id::Event, prototypes::id::PresentationConnectionCloseEvent, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
598
  IsBaseOf<nsISupports, mozilla::dom::PresentationConnectionCloseEvent >::value,
599
  sNativePropertyHooks,
600
  FindAssociatedGlobalForNative<mozilla::dom::PresentationConnectionCloseEvent>::Get,
601
  GetProtoObjectHandle,
602
  GetCCParticipant<mozilla::dom::PresentationConnectionCloseEvent>::Get()
603
};
604
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
605
              "Must have the right minimal number of reserved slots.");
606
static_assert(1 >= 1,
607
              "Must have enough reserved slots.");
608
609
const JSClass*
610
GetJSClass()
611
0
{
612
0
  return sClass.ToJSClass();
613
0
}
614
615
bool
616
Wrap(JSContext* aCx, mozilla::dom::PresentationConnectionCloseEvent* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
617
0
{
618
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::PresentationConnectionCloseEvent>::value,
619
0
                "Shouldn't have wrappercached things that are not refcounted.");
620
0
  MOZ_ASSERT(static_cast<mozilla::dom::PresentationConnectionCloseEvent*>(aObject) ==
621
0
             reinterpret_cast<mozilla::dom::PresentationConnectionCloseEvent*>(aObject),
622
0
             "Multiple inheritance for mozilla::dom::PresentationConnectionCloseEvent is broken.");
623
0
  MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) ==
624
0
             reinterpret_cast<mozilla::dom::Event*>(aObject),
625
0
             "Multiple inheritance for mozilla::dom::Event is broken.");
626
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
627
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
628
0
  MOZ_ASSERT(!aCache->GetWrapper(),
629
0
             "You should probably not be using Wrap() directly; use "
630
0
             "GetOrCreateDOMReflector instead");
631
0
632
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
633
0
             "nsISupports must be on our primary inheritance chain");
634
0
635
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
636
0
  if (!global) {
637
0
    return false;
638
0
  }
639
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
640
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
641
0
642
0
  // That might have ended up wrapping us already, due to the wonders
643
0
  // of XBL.  Check for that, and bail out as needed.
644
0
  aReflector.set(aCache->GetWrapper());
645
0
  if (aReflector) {
646
#ifdef DEBUG
647
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
648
#endif // DEBUG
649
    return true;
650
0
  }
651
0
652
0
  JSAutoRealm ar(aCx, global);
653
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
654
0
  if (!canonicalProto) {
655
0
    return false;
656
0
  }
657
0
  JS::Rooted<JSObject*> proto(aCx);
658
0
  if (aGivenProto) {
659
0
    proto = aGivenProto;
660
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
661
0
    // coming in, we changed compartments to that of "parent" so may need
662
0
    // to wrap the proto here.
663
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
664
0
      if (!JS_WrapObject(aCx, &proto)) {
665
0
        return false;
666
0
      }
667
0
    }
668
0
  } else {
669
0
    proto = canonicalProto;
670
0
  }
671
0
672
0
  BindingJSObjectCreator<mozilla::dom::PresentationConnectionCloseEvent> creator(aCx);
673
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
674
0
  if (!aReflector) {
675
0
    return false;
676
0
  }
677
0
678
0
  aCache->SetWrapper(aReflector);
679
0
680
0
  // Important: do unforgeable property setup after we have handed
681
0
  // over ownership of the C++ object to obj as needed, so that if
682
0
  // we fail and it ends up GCed it won't have problems in the
683
0
  // finalizer trying to drop its ownership of the C++ object.
684
0
  JS::Rooted<JSObject*> unforgeableHolder(aCx,
685
0
    &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject());
686
0
  if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) {
687
0
    aCache->ReleaseWrapper(aObject);
688
0
    aCache->ClearWrapper();
689
0
    return false;
690
0
  }
691
0
  creator.InitializationSucceeded();
692
0
693
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
694
0
             aCache->GetWrapperPreserveColor() == aReflector);
695
0
  // If proto != canonicalProto, we have to preserve our wrapper;
696
0
  // otherwise we won't be able to properly recreate it later, since
697
0
  // we won't know what proto to use.  Note that we don't check
698
0
  // aGivenProto here, since it's entirely possible (and even
699
0
  // somewhat common) to have a non-null aGivenProto which is the
700
0
  // same as canonicalProto.
701
0
  if (proto != canonicalProto) {
702
0
    PreserveWrapper(aObject);
703
0
  }
704
0
705
0
  return true;
706
0
}
707
708
const NativePropertyHooks sNativePropertyHooks[] = { {
709
  nullptr,
710
  nullptr,
711
  nullptr,
712
  { sNativeProperties.Upcast(), nullptr },
713
  prototypes::id::PresentationConnectionCloseEvent,
714
  constructors::id::PresentationConnectionCloseEvent,
715
  Event_Binding::sNativePropertyHooks,
716
  &DefaultXrayExpandoObjectClass
717
} };
718
719
void
720
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
721
0
{
722
0
  JS::Handle<JSObject*> parentProto(Event_Binding::GetProtoObjectHandle(aCx));
723
0
  if (!parentProto) {
724
0
    return;
725
0
  }
726
0
727
0
  JS::Handle<JSObject*> constructorProto(Event_Binding::GetConstructorObjectHandle(aCx));
728
0
  if (!constructorProto) {
729
0
    return;
730
0
  }
731
0
732
0
  static bool sIdsInited = false;
733
0
  if (!sIdsInited && NS_IsMainThread()) {
734
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
735
0
      return;
736
0
    }
737
0
    sIdsInited = true;
738
0
  }
739
0
740
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::PresentationConnectionCloseEvent);
741
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::PresentationConnectionCloseEvent);
742
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
743
0
                              &sPrototypeClass.mBase, protoCache,
744
0
                              nullptr,
745
0
                              constructorProto, &sInterfaceObjectClass.mBase, 2, nullptr,
746
0
                              interfaceCache,
747
0
                              sNativeProperties.Upcast(),
748
0
                              nullptr,
749
0
                              "PresentationConnectionCloseEvent", aDefineOnGlobal,
750
0
                              nullptr,
751
0
                              false);
752
0
753
0
  JS::Rooted<JSObject*> unforgeableHolder(aCx);
754
0
  {
755
0
    JS::Rooted<JSObject*> holderProto(aCx, *protoCache);
756
0
    unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto);
757
0
    if (!unforgeableHolder) {
758
0
      *protoCache = nullptr;
759
0
      if (interfaceCache) {
760
0
        *interfaceCache = nullptr;
761
0
      }
762
0
      return;
763
0
    }
764
0
  }
765
0
766
0
  if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) {
767
0
    *protoCache = nullptr;
768
0
    if (interfaceCache) {
769
0
      *interfaceCache = nullptr;
770
0
    }
771
0
    return;
772
0
  }
773
0
774
0
  if (*protoCache) {
775
0
    js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE,
776
0
                        JS::ObjectValue(*unforgeableHolder));
777
0
  }
778
0
}
779
780
JSObject*
781
GetConstructorObject(JSContext* aCx)
782
0
{
783
0
  return GetConstructorObjectHandle(aCx);
784
0
}
785
786
} // namespace PresentationConnectionCloseEvent_Binding
787
788
789
790
} // namespace dom
791
} // namespace mozilla