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

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

Generated by: LCOV version 1.13