Coverage Report

Created: 2018-09-25 14:53

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