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

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

Generated by: LCOV version 1.13