Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/PromiseDebuggingBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM PromiseDebugging.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AtomList.h"
4
#include "PromiseDebuggingBinding.h"
5
#include "WrapperFactory.h"
6
#include "jsapi.h"
7
#include "mozilla/OwningNonNull.h"
8
#include "mozilla/dom/BindingUtils.h"
9
#include "mozilla/dom/DOMJSClass.h"
10
#include "mozilla/dom/NonRefcountedDOMObject.h"
11
#include "mozilla/dom/Nullable.h"
12
#include "mozilla/dom/PrimitiveConversions.h"
13
#include "mozilla/dom/PromiseDebugging.h"
14
#include "mozilla/dom/ScriptSettings.h"
15
#include "mozilla/dom/XrayExpandoClass.h"
16
#include "nsContentUtils.h"
17
18
namespace mozilla {
19
namespace dom {
20
21
namespace binding_detail {}; // Just to make sure it's known as a namespace
22
using namespace mozilla::dom::binding_detail;
23
24
25
namespace PromiseDebuggingStateValues {
26
extern const EnumEntry strings[4] = {
27
  {"pending", 7},
28
  {"fulfilled", 9},
29
  {"rejected", 8},
30
  { nullptr, 0 }
31
};
32
} // namespace PromiseDebuggingStateValues
33
34
bool
35
ToJSValue(JSContext* aCx, PromiseDebuggingState aArgument, JS::MutableHandle<JS::Value> aValue)
36
0
{
37
0
  MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(PromiseDebuggingStateValues::strings));
38
0
  JSString* resultStr =
39
0
    JS_NewStringCopyN(aCx, PromiseDebuggingStateValues::strings[uint32_t(aArgument)].value,
40
0
                      PromiseDebuggingStateValues::strings[uint32_t(aArgument)].length);
41
0
  if (!resultStr) {
42
0
    return false;
43
0
  }
44
0
  aValue.setString(resultStr);
45
0
  return true;
46
0
}
47
48
49
50
PromiseDebuggingStateHolder::PromiseDebuggingStateHolder()
51
  : mReason(JS::UndefinedValue()),
52
    mValue(JS::UndefinedValue())
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
bool
60
PromiseDebuggingStateHolder::InitIds(JSContext* cx, PromiseDebuggingStateHolderAtoms* atomsCache)
61
0
{
62
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
63
0
64
0
  // Initialize these in reverse order so that any failure leaves the first one
65
0
  // uninitialized.
66
0
  if (!atomsCache->value_id.init(cx, "value") ||
67
0
      !atomsCache->state_id.init(cx, "state") ||
68
0
      !atomsCache->reason_id.init(cx, "reason")) {
69
0
    return false;
70
0
  }
71
0
  return true;
72
0
}
73
74
bool
75
PromiseDebuggingStateHolder::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
  PromiseDebuggingStateHolderAtoms* atomsCache = nullptr;
83
0
  if (cx) {
84
0
    atomsCache = GetAtomCache<PromiseDebuggingStateHolderAtoms>(cx);
85
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
86
0
      return false;
87
0
    }
88
0
  }
89
0
90
0
  if (!IsConvertibleToDictionary(val)) {
91
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
92
0
  }
93
0
94
0
  bool isNull = val.isNullOrUndefined();
95
0
  // We only need these if !isNull, in which case we have |cx|.
96
0
  Maybe<JS::Rooted<JSObject *> > object;
97
0
  Maybe<JS::Rooted<JS::Value> > temp;
98
0
  if (!isNull) {
99
0
    MOZ_ASSERT(cx);
100
0
    object.emplace(cx, &val.toObject());
101
0
    temp.emplace(cx);
102
0
  }
103
0
  if (!isNull) {
104
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->reason_id, temp.ptr())) {
105
0
      return false;
106
0
    }
107
0
  }
108
0
  if (!isNull && !temp->isUndefined()) {
109
0
#ifdef __clang__
110
0
#pragma clang diagnostic push
111
0
#pragma clang diagnostic ignored "-Wunreachable-code"
112
0
#pragma clang diagnostic ignored "-Wunreachable-code-return"
113
0
#endif // __clang__
114
0
    if ((passedToJSImpl) && !CallerSubsumes(temp.ref())) {
115
0
      ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "'reason' member of PromiseDebuggingStateHolder");
116
0
      return false;
117
0
    }
118
0
#ifdef __clang__
119
0
#pragma clang diagnostic pop
120
0
#endif // __clang__
121
0
    mReason = temp.ref();
122
0
  } else {
123
0
    mReason = JS::UndefinedValue();
124
0
  }
125
0
  mIsAnyMemberPresent = true;
126
0
127
0
  if (!isNull) {
128
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->state_id, temp.ptr())) {
129
0
      return false;
130
0
    }
131
0
  }
132
0
  if (!isNull && !temp->isUndefined()) {
133
0
    {
134
0
      int index;
135
0
      if (!FindEnumStringIndex<true>(cx, temp.ref(), PromiseDebuggingStateValues::strings, "PromiseDebuggingState", "'state' member of PromiseDebuggingStateHolder", &index)) {
136
0
        return false;
137
0
      }
138
0
      MOZ_ASSERT(index >= 0);
139
0
      mState = static_cast<PromiseDebuggingState>(index);
140
0
    }
141
0
  } else {
142
0
    mState = PromiseDebuggingState::Pending;
143
0
  }
144
0
  mIsAnyMemberPresent = true;
145
0
146
0
  if (!isNull) {
147
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->value_id, temp.ptr())) {
148
0
      return false;
149
0
    }
150
0
  }
151
0
  if (!isNull && !temp->isUndefined()) {
152
0
#ifdef __clang__
153
0
#pragma clang diagnostic push
154
0
#pragma clang diagnostic ignored "-Wunreachable-code"
155
0
#pragma clang diagnostic ignored "-Wunreachable-code-return"
156
0
#endif // __clang__
157
0
    if ((passedToJSImpl) && !CallerSubsumes(temp.ref())) {
158
0
      ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "'value' member of PromiseDebuggingStateHolder");
159
0
      return false;
160
0
    }
161
0
#ifdef __clang__
162
0
#pragma clang diagnostic pop
163
0
#endif // __clang__
164
0
    mValue = temp.ref();
165
0
  } else {
166
0
    mValue = JS::UndefinedValue();
167
0
  }
168
0
  mIsAnyMemberPresent = true;
169
0
  return true;
170
0
}
171
172
bool
173
PromiseDebuggingStateHolder::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
174
0
{
175
0
  PromiseDebuggingStateHolderAtoms* atomsCache = GetAtomCache<PromiseDebuggingStateHolderAtoms>(cx);
176
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
177
0
    return false;
178
0
  }
179
0
180
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
181
0
  if (!obj) {
182
0
    return false;
183
0
  }
184
0
  rval.set(JS::ObjectValue(*obj));
185
0
186
0
  do {
187
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
188
0
    JS::Rooted<JS::Value> temp(cx);
189
0
    JS::Value const & currentValue = mReason;
190
0
    JS::ExposeValueToActiveJS(currentValue);
191
0
    temp.set(currentValue);
192
0
    if (!MaybeWrapValue(cx, &temp)) {
193
0
      return false;
194
0
    }
195
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->reason_id, temp, JSPROP_ENUMERATE)) {
196
0
      return false;
197
0
    }
198
0
    break;
199
0
  } while(false);
200
0
201
0
  do {
202
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
203
0
    JS::Rooted<JS::Value> temp(cx);
204
0
    PromiseDebuggingState const & currentValue = mState;
205
0
    if (!ToJSValue(cx, currentValue, &temp)) {
206
0
      return false;
207
0
    }
208
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->state_id, temp, JSPROP_ENUMERATE)) {
209
0
      return false;
210
0
    }
211
0
    break;
212
0
  } while(false);
213
0
214
0
  do {
215
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
216
0
    JS::Rooted<JS::Value> temp(cx);
217
0
    JS::Value const & currentValue = mValue;
218
0
    JS::ExposeValueToActiveJS(currentValue);
219
0
    temp.set(currentValue);
220
0
    if (!MaybeWrapValue(cx, &temp)) {
221
0
      return false;
222
0
    }
223
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->value_id, temp, JSPROP_ENUMERATE)) {
224
0
      return false;
225
0
    }
226
0
    break;
227
0
  } while(false);
228
0
229
0
  return true;
230
0
}
231
232
void
233
PromiseDebuggingStateHolder::TraceDictionary(JSTracer* trc)
234
0
{
235
0
  JS::UnsafeTraceRoot(trc, &mReason, "PromiseDebuggingStateHolder.mReason");
236
0
237
0
  JS::UnsafeTraceRoot(trc, &mValue, "PromiseDebuggingStateHolder.mValue");
238
0
}
239
240
namespace binding_detail {
241
} // namespace binding_detail
242
243
244
namespace PromiseDebugging_Binding {
245
246
static bool
247
getState(JSContext* cx, unsigned argc, JS::Value* vp)
248
0
{
249
0
  AUTO_PROFILER_LABEL_FAST("PromiseDebugging.getState", DOM, cx);
250
0
251
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
252
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
253
0
254
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
255
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "PromiseDebugging.getState");
256
0
  }
257
0
  GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
258
0
  if (global.Failed()) {
259
0
    return false;
260
0
  }
261
0
262
0
  JS::Rooted<JSObject*> arg0(cx);
263
0
  if (args[0].isObject()) {
264
0
    arg0 = &args[0].toObject();
265
0
  } else {
266
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of PromiseDebugging.getState");
267
0
    return false;
268
0
  }
269
0
  FastErrorResult rv;
270
0
  RootedDictionary<PromiseDebuggingStateHolder> result(cx);
271
0
  mozilla::dom::PromiseDebugging::GetState(global, arg0, result, rv);
272
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
273
0
    return false;
274
0
  }
275
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
276
0
  if (!result.ToObjectInternal(cx, args.rval())) {
277
0
    return false;
278
0
  }
279
0
  return true;
280
0
}
281
282
static bool
283
getPromiseID(JSContext* cx, unsigned argc, JS::Value* vp)
284
0
{
285
0
  AUTO_PROFILER_LABEL_FAST("PromiseDebugging.getPromiseID", DOM, cx);
286
0
287
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
288
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
289
0
290
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
291
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "PromiseDebugging.getPromiseID");
292
0
  }
293
0
  GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
294
0
  if (global.Failed()) {
295
0
    return false;
296
0
  }
297
0
298
0
  JS::Rooted<JSObject*> arg0(cx);
299
0
  if (args[0].isObject()) {
300
0
    arg0 = &args[0].toObject();
301
0
  } else {
302
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of PromiseDebugging.getPromiseID");
303
0
    return false;
304
0
  }
305
0
  FastErrorResult rv;
306
0
  DOMString result;
307
0
  mozilla::dom::PromiseDebugging::GetPromiseID(global, arg0, result, rv);
308
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
309
0
    return false;
310
0
  }
311
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
312
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
313
0
    return false;
314
0
  }
315
0
  return true;
316
0
}
317
318
static bool
319
getAllocationStack(JSContext* cx, unsigned argc, JS::Value* vp)
320
0
{
321
0
  AUTO_PROFILER_LABEL_FAST("PromiseDebugging.getAllocationStack", DOM, cx);
322
0
323
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
324
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
325
0
326
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
327
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "PromiseDebugging.getAllocationStack");
328
0
  }
329
0
  GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
330
0
  if (global.Failed()) {
331
0
    return false;
332
0
  }
333
0
334
0
  JS::Rooted<JSObject*> arg0(cx);
335
0
  if (args[0].isObject()) {
336
0
    arg0 = &args[0].toObject();
337
0
  } else {
338
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of PromiseDebugging.getAllocationStack");
339
0
    return false;
340
0
  }
341
0
  FastErrorResult rv;
342
0
  JS::Rooted<JSObject*> result(cx);
343
0
  mozilla::dom::PromiseDebugging::GetAllocationStack(global, arg0, &result, rv);
344
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
345
0
    return false;
346
0
  }
347
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
348
0
  if (result) {
349
0
                JS::ExposeObjectToActiveJS(result);
350
0
              }
351
0
              args.rval().setObjectOrNull(result);
352
0
  if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
353
0
    return false;
354
0
  }
355
0
  return true;
356
0
}
357
358
static bool
359
getRejectionStack(JSContext* cx, unsigned argc, JS::Value* vp)
360
0
{
361
0
  AUTO_PROFILER_LABEL_FAST("PromiseDebugging.getRejectionStack", DOM, cx);
362
0
363
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
364
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
365
0
366
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
367
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "PromiseDebugging.getRejectionStack");
368
0
  }
369
0
  GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
370
0
  if (global.Failed()) {
371
0
    return false;
372
0
  }
373
0
374
0
  JS::Rooted<JSObject*> arg0(cx);
375
0
  if (args[0].isObject()) {
376
0
    arg0 = &args[0].toObject();
377
0
  } else {
378
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of PromiseDebugging.getRejectionStack");
379
0
    return false;
380
0
  }
381
0
  FastErrorResult rv;
382
0
  JS::Rooted<JSObject*> result(cx);
383
0
  mozilla::dom::PromiseDebugging::GetRejectionStack(global, arg0, &result, rv);
384
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
385
0
    return false;
386
0
  }
387
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
388
0
  if (result) {
389
0
                JS::ExposeObjectToActiveJS(result);
390
0
              }
391
0
              args.rval().setObjectOrNull(result);
392
0
  if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
393
0
    return false;
394
0
  }
395
0
  return true;
396
0
}
397
398
static bool
399
getFullfillmentStack(JSContext* cx, unsigned argc, JS::Value* vp)
400
0
{
401
0
  AUTO_PROFILER_LABEL_FAST("PromiseDebugging.getFullfillmentStack", DOM, cx);
402
0
403
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
404
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
405
0
406
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
407
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "PromiseDebugging.getFullfillmentStack");
408
0
  }
409
0
  GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
410
0
  if (global.Failed()) {
411
0
    return false;
412
0
  }
413
0
414
0
  JS::Rooted<JSObject*> arg0(cx);
415
0
  if (args[0].isObject()) {
416
0
    arg0 = &args[0].toObject();
417
0
  } else {
418
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of PromiseDebugging.getFullfillmentStack");
419
0
    return false;
420
0
  }
421
0
  FastErrorResult rv;
422
0
  JS::Rooted<JSObject*> result(cx);
423
0
  mozilla::dom::PromiseDebugging::GetFullfillmentStack(global, arg0, &result, rv);
424
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
425
0
    return false;
426
0
  }
427
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
428
0
  if (result) {
429
0
                JS::ExposeObjectToActiveJS(result);
430
0
              }
431
0
              args.rval().setObjectOrNull(result);
432
0
  if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
433
0
    return false;
434
0
  }
435
0
  return true;
436
0
}
437
438
static bool
439
addUncaughtRejectionObserver(JSContext* cx, unsigned argc, JS::Value* vp)
440
0
{
441
0
  AUTO_PROFILER_LABEL_FAST("PromiseDebugging.addUncaughtRejectionObserver", DOM, cx);
442
0
443
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
444
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
445
0
446
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
447
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "PromiseDebugging.addUncaughtRejectionObserver");
448
0
  }
449
0
  GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
450
0
  if (global.Failed()) {
451
0
    return false;
452
0
  }
453
0
454
0
  RootedCallback<OwningNonNull<binding_detail::FastUncaughtRejectionObserver>> arg0(cx);
455
0
  if (args[0].isObject()) {
456
0
    { // scope for tempRoot and tempGlobalRoot if needed
457
0
      arg0 = new binding_detail::FastUncaughtRejectionObserver(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
458
0
    }
459
0
  } else {
460
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of PromiseDebugging.addUncaughtRejectionObserver");
461
0
    return false;
462
0
  }
463
0
  mozilla::dom::PromiseDebugging::AddUncaughtRejectionObserver(global, MOZ_KnownLive(NonNullHelper(arg0)));
464
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
465
0
  args.rval().setUndefined();
466
0
  return true;
467
0
}
468
469
static bool
470
removeUncaughtRejectionObserver(JSContext* cx, unsigned argc, JS::Value* vp)
471
0
{
472
0
  AUTO_PROFILER_LABEL_FAST("PromiseDebugging.removeUncaughtRejectionObserver", DOM, cx);
473
0
474
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
475
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
476
0
477
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
478
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "PromiseDebugging.removeUncaughtRejectionObserver");
479
0
  }
480
0
  GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
481
0
  if (global.Failed()) {
482
0
    return false;
483
0
  }
484
0
485
0
  RootedCallback<OwningNonNull<binding_detail::FastUncaughtRejectionObserver>> arg0(cx);
486
0
  if (args[0].isObject()) {
487
0
    { // scope for tempRoot and tempGlobalRoot if needed
488
0
      arg0 = new binding_detail::FastUncaughtRejectionObserver(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
489
0
    }
490
0
  } else {
491
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of PromiseDebugging.removeUncaughtRejectionObserver");
492
0
    return false;
493
0
  }
494
0
  bool result(mozilla::dom::PromiseDebugging::RemoveUncaughtRejectionObserver(global, MOZ_KnownLive(NonNullHelper(arg0))));
495
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
496
0
  args.rval().setBoolean(result);
497
0
  return true;
498
0
}
499
500
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
501
#if defined(__clang__)
502
#pragma clang diagnostic push
503
#pragma clang diagnostic ignored "-Wmissing-braces"
504
#endif
505
static const JSFunctionSpec sStaticMethods_specs[] = {
506
  JS_FNSPEC("getState", getState, nullptr, 1, JSPROP_ENUMERATE, nullptr),
507
  JS_FNSPEC("getPromiseID", getPromiseID, nullptr, 1, JSPROP_ENUMERATE, nullptr),
508
  JS_FNSPEC("getAllocationStack", getAllocationStack, nullptr, 1, JSPROP_ENUMERATE, nullptr),
509
  JS_FNSPEC("getRejectionStack", getRejectionStack, nullptr, 1, JSPROP_ENUMERATE, nullptr),
510
  JS_FNSPEC("getFullfillmentStack", getFullfillmentStack, nullptr, 1, JSPROP_ENUMERATE, nullptr),
511
  JS_FNSPEC("addUncaughtRejectionObserver", addUncaughtRejectionObserver, nullptr, 1, JSPROP_ENUMERATE, nullptr),
512
  JS_FNSPEC("removeUncaughtRejectionObserver", removeUncaughtRejectionObserver, nullptr, 1, JSPROP_ENUMERATE, nullptr),
513
  JS_FS_END
514
};
515
#if defined(__clang__)
516
#pragma clang diagnostic pop
517
#endif
518
519
520
static const Prefable<const JSFunctionSpec> sStaticMethods[] = {
521
  { nullptr, &sStaticMethods_specs[0] },
522
  { nullptr, nullptr }
523
};
524
525
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
526
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
527
static_assert(7 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
528
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
529
530
531
static uint16_t sNativeProperties_sortedPropertyIndices[7];
532
static PropertyInfo sNativeProperties_propertyInfos[7];
533
534
static const NativePropertiesN<1> sNativeProperties = {
535
  true,  0 /* sStaticMethods */,
536
  false, 0,
537
  false, 0,
538
  false, 0,
539
  false, 0,
540
  false, 0,
541
  false, 0,
542
  -1,
543
  7,
544
  sNativeProperties_sortedPropertyIndices,
545
  {
546
    { sStaticMethods, &sNativeProperties_propertyInfos[0] }
547
  }
548
};
549
static_assert(7 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
550
    "We have a property info count that is oversized");
551
552
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
553
  {
554
    "Function",
555
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
556
    &sBoringInterfaceObjectClassClassOps,
557
    JS_NULL_CLASS_SPEC,
558
    JS_NULL_CLASS_EXT,
559
    &sInterfaceObjectClassObjectOps
560
  },
561
  eInterface,
562
  false,
563
  prototypes::id::_ID_Count,
564
  0,
565
  sNativePropertyHooks,
566
  "function PromiseDebugging() {\n    [native code]\n}",
567
  JS::GetRealmFunctionPrototype
568
};
569
570
bool
571
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
572
0
{
573
0
  return nsContentUtils::ThreadsafeIsSystemCaller(aCx);
574
0
}
575
576
const NativePropertyHooks sNativePropertyHooks[] = { {
577
  nullptr,
578
  nullptr,
579
  nullptr,
580
  { sNativeProperties.Upcast(), nullptr },
581
  prototypes::id::_ID_Count,
582
  constructors::id::PromiseDebugging,
583
  nullptr,
584
  &DefaultXrayExpandoObjectClass
585
} };
586
587
void
588
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
589
0
{
590
0
  JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
591
0
  if (!constructorProto) {
592
0
    return;
593
0
  }
594
0
595
0
  static bool sIdsInited = false;
596
0
  if (!sIdsInited && NS_IsMainThread()) {
597
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
598
0
      return;
599
0
    }
600
0
    sIdsInited = true;
601
0
  }
602
0
603
0
  JS::Heap<JSObject*>* protoCache = nullptr;
604
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::PromiseDebugging);
605
0
  dom::CreateInterfaceObjects(aCx, aGlobal, nullptr,
606
0
                              nullptr, protoCache,
607
0
                              nullptr,
608
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
609
0
                              interfaceCache,
610
0
                              sNativeProperties.Upcast(),
611
0
                              nullptr,
612
0
                              "PromiseDebugging", aDefineOnGlobal,
613
0
                              nullptr,
614
0
                              false);
615
0
}
616
617
JSObject*
618
GetConstructorObject(JSContext* aCx)
619
0
{
620
0
  return GetConstructorObjectHandle(aCx);
621
0
}
622
623
} // namespace PromiseDebugging_Binding
624
625
626
627
void
628
UncaughtRejectionObserver::OnLeftUncaught(JS::Handle<JSObject*> p, ErrorResult& aRv, const char* aExecutionReason, ExceptionHandling aExceptionHandling, JS::Realm* aRealm)
629
0
{
630
0
  CallSetup s(this, aRv, "UncaughtRejectionObserver.onLeftUncaught", aExceptionHandling, aRealm);
631
0
  JSContext* cx = s.GetContext();
632
0
  if (!cx) {
633
0
    MOZ_ASSERT(aRv.Failed());
634
0
    return;
635
0
  }
636
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
637
0
  JS::AutoValueVector argv(cx);
638
0
  if (!argv.resize(1)) {
639
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
640
0
    return;
641
0
  }
642
0
  unsigned argc = 1;
643
0
644
0
  do {
645
0
    JS::ExposeObjectToActiveJS(p);
646
0
    argv[0].setObject(*p);
647
0
    if (!MaybeWrapObjectValue(cx, argv[0])) {
648
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
649
0
      return;
650
0
    }
651
0
    break;
652
0
  } while (false);
653
0
654
0
  JS::Rooted<JS::Value> callable(cx);
655
0
  UncaughtRejectionObserverAtoms* atomsCache = GetAtomCache<UncaughtRejectionObserverAtoms>(cx);
656
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
657
0
      !GetCallableProperty(cx, atomsCache->onLeftUncaught_id, &callable)) {
658
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
659
0
    return;
660
0
  }
661
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
662
0
  if (!JS::Call(cx, thisValue, callable,
663
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
664
0
    aRv.NoteJSContextException(cx);
665
0
    return;
666
0
  }
667
0
}
668
669
void
670
UncaughtRejectionObserver::OnConsumed(JS::Handle<JSObject*> p, ErrorResult& aRv, const char* aExecutionReason, ExceptionHandling aExceptionHandling, JS::Realm* aRealm)
671
0
{
672
0
  CallSetup s(this, aRv, "UncaughtRejectionObserver.onConsumed", aExceptionHandling, aRealm);
673
0
  JSContext* cx = s.GetContext();
674
0
  if (!cx) {
675
0
    MOZ_ASSERT(aRv.Failed());
676
0
    return;
677
0
  }
678
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
679
0
  JS::AutoValueVector argv(cx);
680
0
  if (!argv.resize(1)) {
681
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
682
0
    return;
683
0
  }
684
0
  unsigned argc = 1;
685
0
686
0
  do {
687
0
    JS::ExposeObjectToActiveJS(p);
688
0
    argv[0].setObject(*p);
689
0
    if (!MaybeWrapObjectValue(cx, argv[0])) {
690
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
691
0
      return;
692
0
    }
693
0
    break;
694
0
  } while (false);
695
0
696
0
  JS::Rooted<JS::Value> callable(cx);
697
0
  UncaughtRejectionObserverAtoms* atomsCache = GetAtomCache<UncaughtRejectionObserverAtoms>(cx);
698
0
  if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
699
0
      !GetCallableProperty(cx, atomsCache->onConsumed_id, &callable)) {
700
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
701
0
    return;
702
0
  }
703
0
  JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback));
704
0
  if (!JS::Call(cx, thisValue, callable,
705
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
706
0
    aRv.NoteJSContextException(cx);
707
0
    return;
708
0
  }
709
0
}
710
711
bool
712
UncaughtRejectionObserver::InitIds(JSContext* cx, UncaughtRejectionObserverAtoms* atomsCache)
713
0
{
714
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
715
0
716
0
  // Initialize these in reverse order so that any failure leaves the first one
717
0
  // uninitialized.
718
0
  if (!atomsCache->onConsumed_id.init(cx, "onConsumed") ||
719
0
      !atomsCache->onLeftUncaught_id.init(cx, "onLeftUncaught")) {
720
0
    return false;
721
0
  }
722
0
  return true;
723
0
}
724
725
726
727
namespace binding_detail {
728
} // namespace binding_detail
729
730
731
} // namespace dom
732
} // namespace mozilla