LCOV - code coverage report
Current view: top level - obj-x86_64-pc-linux-gnu/dom/bindings - PromiseRejectionEventBinding.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 2 277 0.7 %
Date: 2017-07-14 16:53:18 Functions: 1 21 4.8 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.13