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

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

Generated by: LCOV version 1.13