LCOV - code coverage report
Current view: top level - obj-x86_64-pc-linux-gnu/dom/bindings - CloseEventBinding.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 34 285 11.9 %
Date: 2017-07-14 16:53:18 Functions: 4 23 17.4 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.13