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