LCOV - code coverage report
Current view: top level - obj-x86_64-pc-linux-gnu/dom/bindings - ServiceWorkerGlobalScopeBinding.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 5 318 1.6 %
Date: 2017-07-14 16:53:18 Functions: 1 32 3.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* THIS FILE IS AUTOGENERATED FROM ServiceWorkerGlobalScope.webidl BY Codegen.py - DO NOT EDIT */
       2             : 
       3             : #include "EventHandlerBinding.h"
       4             : #include "ServiceWorkerGlobalScopeBinding.h"
       5             : #include "WorkerGlobalScopeBinding.h"
       6             : #include "WrapperFactory.h"
       7             : #include "mozilla/OwningNonNull.h"
       8             : #include "mozilla/dom/BindingUtils.h"
       9             : #include "mozilla/dom/DOMJSClass.h"
      10             : #include "mozilla/dom/NonRefcountedDOMObject.h"
      11             : #include "mozilla/dom/Nullable.h"
      12             : #include "mozilla/dom/Promise.h"
      13             : #include "mozilla/dom/ServiceWorkerRegistration.h"
      14             : #include "mozilla/dom/ToJSValue.h"
      15             : #include "mozilla/dom/WorkerScope.h"
      16             : #include "mozilla/dom/workers/bindings/ServiceWorkerClients.h"
      17             : #include "nsThreadUtils.h"
      18             : 
      19             : namespace mozilla {
      20             : namespace dom {
      21             : 
      22             : namespace ServiceWorkerGlobalScopeBinding {
      23             : 
      24             : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<WorkerGlobalScopeBinding::NativeType>::value,
      25             :               "Can't inherit from an interface with a different ownership model.");
      26             : 
      27             : static bool
      28           0 : get_clients(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerGlobalScope* self, JSJitGetterCallArgs args)
      29             : {
      30           0 :   auto result(StrongOrRawPtr<mozilla::dom::workers::ServiceWorkerClients>(self->Clients()));
      31           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
      32           0 :   if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
      33           0 :     MOZ_ASSERT(true || JS_IsExceptionPending(cx));
      34           0 :     return false;
      35             :   }
      36           0 :   return true;
      37             : }
      38             : 
      39             : static const JSJitInfo clients_getterinfo = {
      40             :   { (JSJitGetterOp)get_clients },
      41             :   { prototypes::id::ServiceWorkerGlobalScope },
      42             :   { PrototypeTraits<prototypes::id::ServiceWorkerGlobalScope>::Depth },
      43             :   JSJitInfo::Getter,
      44             :   JSJitInfo::AliasNone, /* aliasSet.  Not relevant for setters. */
      45             :   JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
      46             :   false,  /* isInfallible. False in setters. */
      47             :   true,  /* isMovable.  Not relevant for setters. */
      48             :   true, /* isEliminatable.  Not relevant for setters. */
      49             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
      50             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
      51             :   false,  /* isTypedMethod.  Only relevant for methods. */
      52             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
      53             : };
      54             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
      55             : static_assert(0 < 3, "There is no slot for us");
      56             : 
      57             : static bool
      58           0 : get_registration(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerGlobalScope* self, JSJitGetterCallArgs args)
      59             : {
      60           0 :   auto result(StrongOrRawPtr<mozilla::dom::ServiceWorkerRegistration>(self->Registration()));
      61           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
      62           0 :   if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
      63           0 :     MOZ_ASSERT(true || JS_IsExceptionPending(cx));
      64           0 :     return false;
      65             :   }
      66           0 :   return true;
      67             : }
      68             : 
      69             : static const JSJitInfo registration_getterinfo = {
      70             :   { (JSJitGetterOp)get_registration },
      71             :   { prototypes::id::ServiceWorkerGlobalScope },
      72             :   { PrototypeTraits<prototypes::id::ServiceWorkerGlobalScope>::Depth },
      73             :   JSJitInfo::Getter,
      74             :   JSJitInfo::AliasNone, /* aliasSet.  Not relevant for setters. */
      75             :   JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
      76             :   false,  /* isInfallible. False in setters. */
      77             :   true,  /* isMovable.  Not relevant for setters. */
      78             :   true, /* isEliminatable.  Not relevant for setters. */
      79             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
      80             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
      81             :   false,  /* isTypedMethod.  Only relevant for methods. */
      82             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
      83             : };
      84             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
      85             : static_assert(0 < 3, "There is no slot for us");
      86             : 
      87             : static bool
      88           0 : skipWaiting(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerGlobalScope* self, const JSJitMethodCallArgs& args)
      89             : {
      90           0 :   binding_detail::FastErrorResult rv;
      91           0 :   auto result(StrongOrRawPtr<Promise>(self->SkipWaiting(rv)));
      92           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
      93           0 :     return false;
      94             :   }
      95           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
      96             :   static_assert(!IsPointer<decltype(result)>::value,
      97             :                 "NewObject implies that we need to keep the object alive with a strong reference.");
      98           0 :   if (!ToJSValue(cx, result, args.rval())) {
      99           0 :     return false;
     100             :   }
     101           0 :   return true;
     102             : }
     103             : 
     104             : static bool
     105           0 : skipWaiting_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerGlobalScope* self, const JSJitMethodCallArgs& args)
     106             : {
     107             :   // Make sure to save the callee before someone maybe messes
     108             :   // with rval().
     109           0 :   JS::Rooted<JSObject*> callee(cx, &args.callee());
     110           0 :   bool ok = skipWaiting(cx, obj, self, args);
     111           0 :   if (ok) {
     112           0 :     return true;
     113             :   }
     114           0 :   return ConvertExceptionToPromise(cx, xpc::XrayAwareCalleeGlobal(callee),
     115           0 :                                    args.rval());
     116             : }
     117             : 
     118             : static const JSJitInfo skipWaiting_methodinfo = {
     119             :   { (JSJitGetterOp)skipWaiting_promiseWrapper },
     120             :   { prototypes::id::ServiceWorkerGlobalScope },
     121             :   { PrototypeTraits<prototypes::id::ServiceWorkerGlobalScope>::Depth },
     122             :   JSJitInfo::Method,
     123             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     124             :   JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
     125             :   false,  /* isInfallible. False in setters. */
     126             :   false,  /* isMovable.  Not relevant for setters. */
     127             :   false, /* isEliminatable.  Not relevant for setters. */
     128             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     129             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     130             :   false,  /* isTypedMethod.  Only relevant for methods. */
     131             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     132             : };
     133             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     134             : static_assert(0 < 3, "There is no slot for us");
     135             : 
     136             : static bool
     137           0 : get_oninstall(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerGlobalScope* self, JSJitGetterCallArgs args)
     138             : {
     139           0 :   RefPtr<EventHandlerNonNull> result(self->GetOninstall());
     140           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     141           0 :   if (result) {
     142           0 :     args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
     143           0 :     if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
     144           0 :       return false;
     145             :     }
     146           0 :     return true;
     147             :   } else {
     148           0 :     args.rval().setNull();
     149           0 :     return true;
     150             :   }
     151             : }
     152             : 
     153             : static bool
     154           0 : set_oninstall(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerGlobalScope* self, JSJitSetterCallArgs args)
     155             : {
     156           0 :   RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
     157           0 :   if (args[0].isObject()) {
     158             :     { // scope for tempRoot
     159           0 :       JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
     160           0 :       arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
     161             :     }
     162             :   } else {
     163           0 :     arg0 = nullptr;
     164             :   }
     165           0 :   self->SetOninstall(Constify(arg0));
     166           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     167             : 
     168           0 :   return true;
     169             : }
     170             : 
     171             : static const JSJitInfo oninstall_getterinfo = {
     172             :   { (JSJitGetterOp)get_oninstall },
     173             :   { prototypes::id::ServiceWorkerGlobalScope },
     174             :   { PrototypeTraits<prototypes::id::ServiceWorkerGlobalScope>::Depth },
     175             :   JSJitInfo::Getter,
     176             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     177             :   JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
     178             :   false,  /* isInfallible. False in setters. */
     179             :   false,  /* isMovable.  Not relevant for setters. */
     180             :   false, /* isEliminatable.  Not relevant for setters. */
     181             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     182             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     183             :   false,  /* isTypedMethod.  Only relevant for methods. */
     184             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     185             : };
     186             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     187             : static_assert(0 < 3, "There is no slot for us");
     188             : static const JSJitInfo oninstall_setterinfo = {
     189             :   { (JSJitGetterOp)set_oninstall },
     190             :   { prototypes::id::ServiceWorkerGlobalScope },
     191             :   { PrototypeTraits<prototypes::id::ServiceWorkerGlobalScope>::Depth },
     192             :   JSJitInfo::Setter,
     193             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     194             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
     195             :   false,  /* isInfallible. False in setters. */
     196             :   false,  /* isMovable.  Not relevant for setters. */
     197             :   false, /* isEliminatable.  Not relevant for setters. */
     198             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     199             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     200             :   false,  /* isTypedMethod.  Only relevant for methods. */
     201             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     202             : };
     203             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     204             : static_assert(0 < 3, "There is no slot for us");
     205             : 
     206             : static bool
     207           0 : get_onactivate(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerGlobalScope* self, JSJitGetterCallArgs args)
     208             : {
     209           0 :   RefPtr<EventHandlerNonNull> result(self->GetOnactivate());
     210           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     211           0 :   if (result) {
     212           0 :     args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
     213           0 :     if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
     214           0 :       return false;
     215             :     }
     216           0 :     return true;
     217             :   } else {
     218           0 :     args.rval().setNull();
     219           0 :     return true;
     220             :   }
     221             : }
     222             : 
     223             : static bool
     224           0 : set_onactivate(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerGlobalScope* self, JSJitSetterCallArgs args)
     225             : {
     226           0 :   RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
     227           0 :   if (args[0].isObject()) {
     228             :     { // scope for tempRoot
     229           0 :       JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
     230           0 :       arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
     231             :     }
     232             :   } else {
     233           0 :     arg0 = nullptr;
     234             :   }
     235           0 :   self->SetOnactivate(Constify(arg0));
     236           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     237             : 
     238           0 :   return true;
     239             : }
     240             : 
     241             : static const JSJitInfo onactivate_getterinfo = {
     242             :   { (JSJitGetterOp)get_onactivate },
     243             :   { prototypes::id::ServiceWorkerGlobalScope },
     244             :   { PrototypeTraits<prototypes::id::ServiceWorkerGlobalScope>::Depth },
     245             :   JSJitInfo::Getter,
     246             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     247             :   JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
     248             :   false,  /* isInfallible. False in setters. */
     249             :   false,  /* isMovable.  Not relevant for setters. */
     250             :   false, /* isEliminatable.  Not relevant for setters. */
     251             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     252             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     253             :   false,  /* isTypedMethod.  Only relevant for methods. */
     254             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     255             : };
     256             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     257             : static_assert(0 < 3, "There is no slot for us");
     258             : static const JSJitInfo onactivate_setterinfo = {
     259             :   { (JSJitGetterOp)set_onactivate },
     260             :   { prototypes::id::ServiceWorkerGlobalScope },
     261             :   { PrototypeTraits<prototypes::id::ServiceWorkerGlobalScope>::Depth },
     262             :   JSJitInfo::Setter,
     263             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     264             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
     265             :   false,  /* isInfallible. False in setters. */
     266             :   false,  /* isMovable.  Not relevant for setters. */
     267             :   false, /* isEliminatable.  Not relevant for setters. */
     268             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     269             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     270             :   false,  /* isTypedMethod.  Only relevant for methods. */
     271             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     272             : };
     273             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     274             : static_assert(0 < 3, "There is no slot for us");
     275             : 
     276             : static bool
     277           0 : get_onfetch(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerGlobalScope* self, JSJitGetterCallArgs args)
     278             : {
     279           0 :   RefPtr<EventHandlerNonNull> result(self->GetOnfetch());
     280           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     281           0 :   if (result) {
     282           0 :     args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
     283           0 :     if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
     284           0 :       return false;
     285             :     }
     286           0 :     return true;
     287             :   } else {
     288           0 :     args.rval().setNull();
     289           0 :     return true;
     290             :   }
     291             : }
     292             : 
     293             : static bool
     294           0 : set_onfetch(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerGlobalScope* self, JSJitSetterCallArgs args)
     295             : {
     296           0 :   RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
     297           0 :   if (args[0].isObject()) {
     298             :     { // scope for tempRoot
     299           0 :       JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
     300           0 :       arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
     301             :     }
     302             :   } else {
     303           0 :     arg0 = nullptr;
     304             :   }
     305           0 :   self->SetOnfetch(Constify(arg0));
     306           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     307             : 
     308           0 :   return true;
     309             : }
     310             : 
     311             : static const JSJitInfo onfetch_getterinfo = {
     312             :   { (JSJitGetterOp)get_onfetch },
     313             :   { prototypes::id::ServiceWorkerGlobalScope },
     314             :   { PrototypeTraits<prototypes::id::ServiceWorkerGlobalScope>::Depth },
     315             :   JSJitInfo::Getter,
     316             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     317             :   JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
     318             :   false,  /* isInfallible. False in setters. */
     319             :   false,  /* isMovable.  Not relevant for setters. */
     320             :   false, /* isEliminatable.  Not relevant for setters. */
     321             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     322             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     323             :   false,  /* isTypedMethod.  Only relevant for methods. */
     324             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     325             : };
     326             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     327             : static_assert(0 < 3, "There is no slot for us");
     328             : static const JSJitInfo onfetch_setterinfo = {
     329             :   { (JSJitGetterOp)set_onfetch },
     330             :   { prototypes::id::ServiceWorkerGlobalScope },
     331             :   { PrototypeTraits<prototypes::id::ServiceWorkerGlobalScope>::Depth },
     332             :   JSJitInfo::Setter,
     333             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     334             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
     335             :   false,  /* isInfallible. False in setters. */
     336             :   false,  /* isMovable.  Not relevant for setters. */
     337             :   false, /* isEliminatable.  Not relevant for setters. */
     338             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     339             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     340             :   false,  /* isTypedMethod.  Only relevant for methods. */
     341             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     342             : };
     343             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     344             : static_assert(0 < 3, "There is no slot for us");
     345             : 
     346             : static bool
     347           0 : get_onmessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerGlobalScope* self, JSJitGetterCallArgs args)
     348             : {
     349           0 :   RefPtr<EventHandlerNonNull> result(self->GetOnmessage());
     350           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     351           0 :   if (result) {
     352           0 :     args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
     353           0 :     if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
     354           0 :       return false;
     355             :     }
     356           0 :     return true;
     357             :   } else {
     358           0 :     args.rval().setNull();
     359           0 :     return true;
     360             :   }
     361             : }
     362             : 
     363             : static bool
     364           0 : set_onmessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerGlobalScope* self, JSJitSetterCallArgs args)
     365             : {
     366           0 :   RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
     367           0 :   if (args[0].isObject()) {
     368             :     { // scope for tempRoot
     369           0 :       JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
     370           0 :       arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
     371             :     }
     372             :   } else {
     373           0 :     arg0 = nullptr;
     374             :   }
     375           0 :   self->SetOnmessage(Constify(arg0));
     376           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     377             : 
     378           0 :   return true;
     379             : }
     380             : 
     381             : static const JSJitInfo onmessage_getterinfo = {
     382             :   { (JSJitGetterOp)get_onmessage },
     383             :   { prototypes::id::ServiceWorkerGlobalScope },
     384             :   { PrototypeTraits<prototypes::id::ServiceWorkerGlobalScope>::Depth },
     385             :   JSJitInfo::Getter,
     386             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     387             :   JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
     388             :   false,  /* isInfallible. False in setters. */
     389             :   false,  /* isMovable.  Not relevant for setters. */
     390             :   false, /* isEliminatable.  Not relevant for setters. */
     391             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     392             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     393             :   false,  /* isTypedMethod.  Only relevant for methods. */
     394             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     395             : };
     396             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     397             : static_assert(0 < 3, "There is no slot for us");
     398             : static const JSJitInfo onmessage_setterinfo = {
     399             :   { (JSJitGetterOp)set_onmessage },
     400             :   { prototypes::id::ServiceWorkerGlobalScope },
     401             :   { PrototypeTraits<prototypes::id::ServiceWorkerGlobalScope>::Depth },
     402             :   JSJitInfo::Setter,
     403             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     404             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
     405             :   false,  /* isInfallible. False in setters. */
     406             :   false,  /* isMovable.  Not relevant for setters. */
     407             :   false, /* isEliminatable.  Not relevant for setters. */
     408             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     409             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     410             :   false,  /* isTypedMethod.  Only relevant for methods. */
     411             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     412             : };
     413             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     414             : static_assert(0 < 3, "There is no slot for us");
     415             : 
     416             : static bool
     417           0 : get_onpush(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerGlobalScope* self, JSJitGetterCallArgs args)
     418             : {
     419           0 :   RefPtr<EventHandlerNonNull> result(self->GetOnpush());
     420           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     421           0 :   if (result) {
     422           0 :     args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
     423           0 :     if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
     424           0 :       return false;
     425             :     }
     426           0 :     return true;
     427             :   } else {
     428           0 :     args.rval().setNull();
     429           0 :     return true;
     430             :   }
     431             : }
     432             : 
     433             : static bool
     434           0 : set_onpush(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerGlobalScope* self, JSJitSetterCallArgs args)
     435             : {
     436           0 :   RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
     437           0 :   if (args[0].isObject()) {
     438             :     { // scope for tempRoot
     439           0 :       JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
     440           0 :       arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
     441             :     }
     442             :   } else {
     443           0 :     arg0 = nullptr;
     444             :   }
     445           0 :   self->SetOnpush(Constify(arg0));
     446           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     447             : 
     448           0 :   return true;
     449             : }
     450             : 
     451             : static const JSJitInfo onpush_getterinfo = {
     452             :   { (JSJitGetterOp)get_onpush },
     453             :   { prototypes::id::ServiceWorkerGlobalScope },
     454             :   { PrototypeTraits<prototypes::id::ServiceWorkerGlobalScope>::Depth },
     455             :   JSJitInfo::Getter,
     456             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     457             :   JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
     458             :   false,  /* isInfallible. False in setters. */
     459             :   false,  /* isMovable.  Not relevant for setters. */
     460             :   false, /* isEliminatable.  Not relevant for setters. */
     461             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     462             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     463             :   false,  /* isTypedMethod.  Only relevant for methods. */
     464             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     465             : };
     466             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     467             : static_assert(0 < 3, "There is no slot for us");
     468             : static const JSJitInfo onpush_setterinfo = {
     469             :   { (JSJitGetterOp)set_onpush },
     470             :   { prototypes::id::ServiceWorkerGlobalScope },
     471             :   { PrototypeTraits<prototypes::id::ServiceWorkerGlobalScope>::Depth },
     472             :   JSJitInfo::Setter,
     473             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     474             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
     475             :   false,  /* isInfallible. False in setters. */
     476             :   false,  /* isMovable.  Not relevant for setters. */
     477             :   false, /* isEliminatable.  Not relevant for setters. */
     478             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     479             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     480             :   false,  /* isTypedMethod.  Only relevant for methods. */
     481             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     482             : };
     483             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     484             : static_assert(0 < 3, "There is no slot for us");
     485             : 
     486             : static bool
     487           0 : get_onpushsubscriptionchange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerGlobalScope* self, JSJitGetterCallArgs args)
     488             : {
     489           0 :   RefPtr<EventHandlerNonNull> result(self->GetOnpushsubscriptionchange());
     490           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     491           0 :   if (result) {
     492           0 :     args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
     493           0 :     if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
     494           0 :       return false;
     495             :     }
     496           0 :     return true;
     497             :   } else {
     498           0 :     args.rval().setNull();
     499           0 :     return true;
     500             :   }
     501             : }
     502             : 
     503             : static bool
     504           0 : set_onpushsubscriptionchange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerGlobalScope* self, JSJitSetterCallArgs args)
     505             : {
     506           0 :   RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
     507           0 :   if (args[0].isObject()) {
     508             :     { // scope for tempRoot
     509           0 :       JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
     510           0 :       arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
     511             :     }
     512             :   } else {
     513           0 :     arg0 = nullptr;
     514             :   }
     515           0 :   self->SetOnpushsubscriptionchange(Constify(arg0));
     516           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     517             : 
     518           0 :   return true;
     519             : }
     520             : 
     521             : static const JSJitInfo onpushsubscriptionchange_getterinfo = {
     522             :   { (JSJitGetterOp)get_onpushsubscriptionchange },
     523             :   { prototypes::id::ServiceWorkerGlobalScope },
     524             :   { PrototypeTraits<prototypes::id::ServiceWorkerGlobalScope>::Depth },
     525             :   JSJitInfo::Getter,
     526             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     527             :   JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
     528             :   false,  /* isInfallible. False in setters. */
     529             :   false,  /* isMovable.  Not relevant for setters. */
     530             :   false, /* isEliminatable.  Not relevant for setters. */
     531             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     532             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     533             :   false,  /* isTypedMethod.  Only relevant for methods. */
     534             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     535             : };
     536             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     537             : static_assert(0 < 3, "There is no slot for us");
     538             : static const JSJitInfo onpushsubscriptionchange_setterinfo = {
     539             :   { (JSJitGetterOp)set_onpushsubscriptionchange },
     540             :   { prototypes::id::ServiceWorkerGlobalScope },
     541             :   { PrototypeTraits<prototypes::id::ServiceWorkerGlobalScope>::Depth },
     542             :   JSJitInfo::Setter,
     543             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     544             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
     545             :   false,  /* isInfallible. False in setters. */
     546             :   false,  /* isMovable.  Not relevant for setters. */
     547             :   false, /* isEliminatable.  Not relevant for setters. */
     548             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     549             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     550             :   false,  /* isTypedMethod.  Only relevant for methods. */
     551             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     552             : };
     553             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     554             : static_assert(0 < 3, "There is no slot for us");
     555             : 
     556             : static bool
     557           0 : get_onnotificationclick(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerGlobalScope* self, JSJitGetterCallArgs args)
     558             : {
     559           0 :   RefPtr<EventHandlerNonNull> result(self->GetOnnotificationclick());
     560           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     561           0 :   if (result) {
     562           0 :     args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
     563           0 :     if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
     564           0 :       return false;
     565             :     }
     566           0 :     return true;
     567             :   } else {
     568           0 :     args.rval().setNull();
     569           0 :     return true;
     570             :   }
     571             : }
     572             : 
     573             : static bool
     574           0 : set_onnotificationclick(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerGlobalScope* self, JSJitSetterCallArgs args)
     575             : {
     576           0 :   RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
     577           0 :   if (args[0].isObject()) {
     578             :     { // scope for tempRoot
     579           0 :       JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
     580           0 :       arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
     581             :     }
     582             :   } else {
     583           0 :     arg0 = nullptr;
     584             :   }
     585           0 :   self->SetOnnotificationclick(Constify(arg0));
     586           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     587             : 
     588           0 :   return true;
     589             : }
     590             : 
     591             : static const JSJitInfo onnotificationclick_getterinfo = {
     592             :   { (JSJitGetterOp)get_onnotificationclick },
     593             :   { prototypes::id::ServiceWorkerGlobalScope },
     594             :   { PrototypeTraits<prototypes::id::ServiceWorkerGlobalScope>::Depth },
     595             :   JSJitInfo::Getter,
     596             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     597             :   JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
     598             :   false,  /* isInfallible. False in setters. */
     599             :   false,  /* isMovable.  Not relevant for setters. */
     600             :   false, /* isEliminatable.  Not relevant for setters. */
     601             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     602             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     603             :   false,  /* isTypedMethod.  Only relevant for methods. */
     604             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     605             : };
     606             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     607             : static_assert(0 < 3, "There is no slot for us");
     608             : static const JSJitInfo onnotificationclick_setterinfo = {
     609             :   { (JSJitGetterOp)set_onnotificationclick },
     610             :   { prototypes::id::ServiceWorkerGlobalScope },
     611             :   { PrototypeTraits<prototypes::id::ServiceWorkerGlobalScope>::Depth },
     612             :   JSJitInfo::Setter,
     613             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     614             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
     615             :   false,  /* isInfallible. False in setters. */
     616             :   false,  /* isMovable.  Not relevant for setters. */
     617             :   false, /* isEliminatable.  Not relevant for setters. */
     618             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     619             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     620             :   false,  /* isTypedMethod.  Only relevant for methods. */
     621             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     622             : };
     623             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     624             : static_assert(0 < 3, "There is no slot for us");
     625             : 
     626             : static bool
     627           0 : get_onnotificationclose(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerGlobalScope* self, JSJitGetterCallArgs args)
     628             : {
     629           0 :   RefPtr<EventHandlerNonNull> result(self->GetOnnotificationclose());
     630           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     631           0 :   if (result) {
     632           0 :     args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
     633           0 :     if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
     634           0 :       return false;
     635             :     }
     636           0 :     return true;
     637             :   } else {
     638           0 :     args.rval().setNull();
     639           0 :     return true;
     640             :   }
     641             : }
     642             : 
     643             : static bool
     644           0 : set_onnotificationclose(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ServiceWorkerGlobalScope* self, JSJitSetterCallArgs args)
     645             : {
     646           0 :   RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
     647           0 :   if (args[0].isObject()) {
     648             :     { // scope for tempRoot
     649           0 :       JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
     650           0 :       arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
     651             :     }
     652             :   } else {
     653           0 :     arg0 = nullptr;
     654             :   }
     655           0 :   self->SetOnnotificationclose(Constify(arg0));
     656           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     657             : 
     658           0 :   return true;
     659             : }
     660             : 
     661             : static const JSJitInfo onnotificationclose_getterinfo = {
     662             :   { (JSJitGetterOp)get_onnotificationclose },
     663             :   { prototypes::id::ServiceWorkerGlobalScope },
     664             :   { PrototypeTraits<prototypes::id::ServiceWorkerGlobalScope>::Depth },
     665             :   JSJitInfo::Getter,
     666             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     667             :   JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
     668             :   false,  /* isInfallible. False in setters. */
     669             :   false,  /* isMovable.  Not relevant for setters. */
     670             :   false, /* isEliminatable.  Not relevant for setters. */
     671             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     672             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     673             :   false,  /* isTypedMethod.  Only relevant for methods. */
     674             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     675             : };
     676             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     677             : static_assert(0 < 3, "There is no slot for us");
     678             : static const JSJitInfo onnotificationclose_setterinfo = {
     679             :   { (JSJitGetterOp)set_onnotificationclose },
     680             :   { prototypes::id::ServiceWorkerGlobalScope },
     681             :   { PrototypeTraits<prototypes::id::ServiceWorkerGlobalScope>::Depth },
     682             :   JSJitInfo::Setter,
     683             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     684             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
     685             :   false,  /* isInfallible. False in setters. */
     686             :   false,  /* isMovable.  Not relevant for setters. */
     687             :   false, /* isEliminatable.  Not relevant for setters. */
     688             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     689             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     690             :   false,  /* isTypedMethod.  Only relevant for methods. */
     691             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     692             : };
     693             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     694             : static_assert(0 < 3, "There is no slot for us");
     695             : 
     696             : static bool
     697           0 : genericPromiseReturningMethod(JSContext* cx, unsigned argc, JS::Value* vp)
     698             : {
     699           0 :   JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
     700             :   // Make sure to save the callee before someone maybe messes with rval().
     701           0 :   JS::Rooted<JSObject*> callee(cx, &args.callee());
     702           0 :   if (!args.thisv().isNullOrUndefined() && !args.thisv().isObject()) {
     703           0 :     ThrowInvalidThis(cx, args, false, "ServiceWorkerGlobalScope");
     704             : 
     705           0 :     return ConvertExceptionToPromise(cx, xpc::XrayAwareCalleeGlobal(callee),
     706           0 :                                      args.rval());
     707             :   }
     708           0 :   JS::Rooted<JSObject*> obj(cx, args.thisv().isObject() ? &args.thisv().toObject() : js::GetGlobalForObjectCrossCompartment(&args.callee()));
     709             : 
     710             :   mozilla::dom::ServiceWorkerGlobalScope* self;
     711           0 :   JS::Rooted<JS::Value> rootSelf(cx, JS::ObjectValue(*obj));
     712             :   {
     713           0 :     nsresult rv = UnwrapObject<prototypes::id::ServiceWorkerGlobalScope, mozilla::dom::ServiceWorkerGlobalScope>(&rootSelf, self);
     714           0 :     if (NS_FAILED(rv)) {
     715           0 :       ThrowInvalidThis(cx, args, rv == NS_ERROR_XPC_SECURITY_MANAGER_VETO, "ServiceWorkerGlobalScope");
     716             : 
     717           0 :       return ConvertExceptionToPromise(cx, xpc::XrayAwareCalleeGlobal(callee),
     718           0 :                                        args.rval());
     719             :     }
     720             :   }
     721           0 :   const JSJitInfo *info = FUNCTION_VALUE_TO_JITINFO(args.calleev());
     722           0 :   MOZ_ASSERT(info->type() == JSJitInfo::Method);
     723           0 :   JSJitMethodOp method = info->method;
     724           0 :   bool ok = method(cx, obj, self, JSJitMethodCallArgs(args));
     725           0 :   if (ok) {
     726             : #ifdef DEBUG
     727           0 :     AssertReturnTypeMatchesJitinfo(info, args.rval());
     728             : #endif
     729           0 :     return true;
     730             :   }
     731             : 
     732           0 :   MOZ_ASSERT(info->returnType() == JSVAL_TYPE_OBJECT);
     733           0 :   return ConvertExceptionToPromise(cx, xpc::XrayAwareCalleeGlobal(callee),
     734           0 :                                    args.rval());
     735             : }
     736             : 
     737             : static bool
     738           0 : genericGetter(JSContext* cx, unsigned argc, JS::Value* vp)
     739             : {
     740           0 :   JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
     741           0 :   if (!args.thisv().isNullOrUndefined() && !args.thisv().isObject()) {
     742           0 :     return ThrowInvalidThis(cx, args, false, "ServiceWorkerGlobalScope");
     743             :   }
     744           0 :   JS::Rooted<JSObject*> obj(cx, args.thisv().isObject() ? &args.thisv().toObject() : js::GetGlobalForObjectCrossCompartment(&args.callee()));
     745             : 
     746             :   mozilla::dom::ServiceWorkerGlobalScope* self;
     747           0 :   JS::Rooted<JS::Value> rootSelf(cx, JS::ObjectValue(*obj));
     748             :   {
     749           0 :     nsresult rv = UnwrapObject<prototypes::id::ServiceWorkerGlobalScope, mozilla::dom::ServiceWorkerGlobalScope>(&rootSelf, self);
     750           0 :     if (NS_FAILED(rv)) {
     751           0 :       return ThrowInvalidThis(cx, args, rv == NS_ERROR_XPC_SECURITY_MANAGER_VETO, "ServiceWorkerGlobalScope");
     752             :     }
     753             :   }
     754           0 :   const JSJitInfo *info = FUNCTION_VALUE_TO_JITINFO(args.calleev());
     755           0 :   MOZ_ASSERT(info->type() == JSJitInfo::Getter);
     756           0 :   JSJitGetterOp getter = info->getter;
     757           0 :   bool ok = getter(cx, obj, self, JSJitGetterCallArgs(args));
     758             : #ifdef DEBUG
     759           0 :   if (ok) {
     760           0 :     AssertReturnTypeMatchesJitinfo(info, args.rval());
     761             :   }
     762             : #endif
     763           0 :   return ok;
     764             : }
     765             : 
     766             : static bool
     767           0 : genericSetter(JSContext* cx, unsigned argc, JS::Value* vp)
     768             : {
     769           0 :   JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
     770           0 :   if (!args.thisv().isNullOrUndefined() && !args.thisv().isObject()) {
     771           0 :     return ThrowInvalidThis(cx, args, false, "ServiceWorkerGlobalScope");
     772             :   }
     773           0 :   JS::Rooted<JSObject*> obj(cx, args.thisv().isObject() ? &args.thisv().toObject() : js::GetGlobalForObjectCrossCompartment(&args.callee()));
     774             : 
     775             :   mozilla::dom::ServiceWorkerGlobalScope* self;
     776           0 :   JS::Rooted<JS::Value> rootSelf(cx, JS::ObjectValue(*obj));
     777             :   {
     778           0 :     nsresult rv = UnwrapObject<prototypes::id::ServiceWorkerGlobalScope, mozilla::dom::ServiceWorkerGlobalScope>(&rootSelf, self);
     779           0 :     if (NS_FAILED(rv)) {
     780           0 :       return ThrowInvalidThis(cx, args, rv == NS_ERROR_XPC_SECURITY_MANAGER_VETO, "ServiceWorkerGlobalScope");
     781             :     }
     782             :   }
     783           0 :   if (args.length() == 0) {
     784           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ServiceWorkerGlobalScope attribute setter");
     785             :   }
     786           0 :   const JSJitInfo *info = FUNCTION_VALUE_TO_JITINFO(args.calleev());
     787           0 :   MOZ_ASSERT(info->type() == JSJitInfo::Setter);
     788           0 :   JSJitSetterOp setter = info->setter;
     789           0 :   if (!setter(cx, obj, self, JSJitSetterCallArgs(args))) {
     790           0 :     return false;
     791             :   }
     792           0 :   args.rval().setUndefined();
     793             : #ifdef DEBUG
     794           0 :   AssertReturnTypeMatchesJitinfo(info, args.rval());
     795             : #endif
     796           0 :   return true;
     797             : }
     798             : 
     799             : static void
     800           0 : _finalize(js::FreeOp* fop, JSObject* obj)
     801             : {
     802           0 :   mozilla::dom::ServiceWorkerGlobalScope* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ServiceWorkerGlobalScope>(obj);
     803           0 :   if (self) {
     804           0 :     ClearWrapper(self, self, obj);
     805           0 :     mozilla::dom::FinalizeGlobal(CastToJSFreeOp(fop), obj);
     806           0 :     AddForDeferredFinalization<mozilla::dom::ServiceWorkerGlobalScope>(self);
     807             :   }
     808           0 : }
     809             : 
     810             : static void
     811           0 : _objectMoved(JSObject* obj, const JSObject* old)
     812             : {
     813           0 :   mozilla::dom::ServiceWorkerGlobalScope* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ServiceWorkerGlobalScope>(obj);
     814           0 :   if (self) {
     815           0 :     UpdateWrapper(self, self, obj, old);
     816             :   }
     817           0 : }
     818             : 
     819             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
     820             : #if defined(__clang__)
     821             : #pragma clang diagnostic push
     822             : #pragma clang diagnostic ignored "-Wmissing-braces"
     823             : #endif
     824             : static const JSFunctionSpec sMethods_specs[] = {
     825             :   JS_FNSPEC("skipWaiting", genericPromiseReturningMethod, reinterpret_cast<const JSJitInfo*>(&skipWaiting_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
     826             :   JS_FS_END
     827             : };
     828             : #if defined(__clang__)
     829             : #pragma clang diagnostic pop
     830             : #endif
     831             : 
     832             : 
     833             : // Can't be const because the pref-enabled boolean needs to be writable
     834             : static Prefable<const JSFunctionSpec> sMethods[] = {
     835             :   { nullptr, &sMethods_specs[0] },
     836             :   { nullptr, nullptr }
     837             : };
     838             : 
     839             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
     840             : #if defined(__clang__)
     841             : #pragma clang diagnostic push
     842             : #pragma clang diagnostic ignored "-Wmissing-braces"
     843             : #endif
     844             : static const JSPropertySpec sAttributes_specs[] = {
     845             :   { "clients", JSPROP_SHARED | JSPROP_ENUMERATE, genericGetter, &clients_getterinfo, nullptr, nullptr },
     846             :   { "registration", JSPROP_SHARED | JSPROP_ENUMERATE, genericGetter, &registration_getterinfo, nullptr, nullptr },
     847             :   { "oninstall", JSPROP_SHARED | JSPROP_ENUMERATE, genericGetter, &oninstall_getterinfo, genericSetter, &oninstall_setterinfo },
     848             :   { "onactivate", JSPROP_SHARED | JSPROP_ENUMERATE, genericGetter, &onactivate_getterinfo, genericSetter, &onactivate_setterinfo },
     849             :   { "onfetch", JSPROP_SHARED | JSPROP_ENUMERATE, genericGetter, &onfetch_getterinfo, genericSetter, &onfetch_setterinfo },
     850             :   { "onmessage", JSPROP_SHARED | JSPROP_ENUMERATE, genericGetter, &onmessage_getterinfo, genericSetter, &onmessage_setterinfo },
     851             :   { "onpush", JSPROP_SHARED | JSPROP_ENUMERATE, genericGetter, &onpush_getterinfo, genericSetter, &onpush_setterinfo },
     852             :   { "onpushsubscriptionchange", JSPROP_SHARED | JSPROP_ENUMERATE, genericGetter, &onpushsubscriptionchange_getterinfo, genericSetter, &onpushsubscriptionchange_setterinfo },
     853             :   { "onnotificationclick", JSPROP_SHARED | JSPROP_ENUMERATE, genericGetter, &onnotificationclick_getterinfo, genericSetter, &onnotificationclick_setterinfo },
     854             :   { "onnotificationclose", JSPROP_SHARED | JSPROP_ENUMERATE, genericGetter, &onnotificationclose_getterinfo, genericSetter, &onnotificationclose_setterinfo },
     855             :   { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
     856             : };
     857             : #if defined(__clang__)
     858             : #pragma clang diagnostic pop
     859             : #endif
     860             : 
     861             : 
     862             : // Can't be const because the pref-enabled boolean needs to be writable
     863             : static Prefable<const JSPropertySpec> sAttributes[] = {
     864             :   { nullptr, &sAttributes_specs[0] },
     865             :   { nullptr, nullptr }
     866             : };
     867             : 
     868             : 
     869             : static const NativePropertiesN<2> sNativeProperties = {
     870             :   false, 0,
     871             :   false, 0,
     872             :   true,  0 /* sMethods */,
     873             :   true,  1 /* sAttributes */,
     874             :   false, 0,
     875             :   false, 0,
     876             :   false, 0,
     877             :   -1,
     878             :   0,
     879             :   nullptr,
     880             :   {
     881             :     { sMethods, nullptr },
     882             :     { sAttributes, nullptr }
     883             :   }
     884             : };
     885             : 
     886             : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
     887             :   {
     888             :     "Function",
     889             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
     890             :     &sBoringInterfaceObjectClassClassOps,
     891             :     JS_NULL_CLASS_SPEC,
     892             :     JS_NULL_CLASS_EXT,
     893             :     &sInterfaceObjectClassObjectOps
     894             :   },
     895             :   eInterface,
     896             :   true,
     897             :   prototypes::id::ServiceWorkerGlobalScope,
     898             :   PrototypeTraits<prototypes::id::ServiceWorkerGlobalScope>::Depth,
     899             :   &sEmptyNativePropertyHooks,
     900             :   "function ServiceWorkerGlobalScope() {\n    [native code]\n}",
     901             :   WorkerGlobalScopeBinding::GetConstructorObject
     902             : };
     903             : 
     904             : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
     905             :   {
     906             :     "ServiceWorkerGlobalScopePrototype",
     907             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
     908             :     JS_NULL_CLASS_OPS,
     909             :     JS_NULL_CLASS_SPEC,
     910             :     JS_NULL_CLASS_EXT,
     911             :     JS_NULL_OBJECT_OPS
     912             :   },
     913             :   eGlobalInterfacePrototype,
     914             :   false,
     915             :   prototypes::id::ServiceWorkerGlobalScope,
     916             :   PrototypeTraits<prototypes::id::ServiceWorkerGlobalScope>::Depth,
     917             :   &sEmptyNativePropertyHooks,
     918             :   "[object ServiceWorkerGlobalScopePrototype]",
     919             :   WorkerGlobalScopeBinding::GetProtoObject
     920             : };
     921             : 
     922             : bool
     923           1 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
     924             : {
     925           1 :   MOZ_ASSERT(!NS_IsMainThread(), "Why did we even get called?");
     926             : 
     927           1 :   const char* name = js::GetObjectClass(aObj)->name;
     928           1 :   if (strcmp(name, "ServiceWorkerGlobalScope")) {
     929           1 :     return false;
     930             :   }
     931             : 
     932           0 :   return true;
     933             : }
     934             : 
     935             : static const js::ClassOps sClassOps = {
     936             :   nullptr, /* addProperty */
     937             :   nullptr,               /* delProperty */
     938             :   nullptr,               /* getProperty */
     939             :   nullptr,               /* setProperty */
     940             :   nullptr,               /* enumerate */
     941             :   mozilla::dom::EnumerateGlobal, /* newEnumerate */
     942             :   mozilla::dom::ResolveGlobal, /* resolve */
     943             :   mozilla::dom::MayResolveGlobal, /* mayResolve */
     944             :   _finalize, /* finalize */
     945             :   nullptr, /* call */
     946             :   nullptr,               /* hasInstance */
     947             :   nullptr,               /* construct */
     948             :   JS_GlobalObjectTraceHook, /* trace */
     949             : };
     950             : 
     951             : static const js::ClassExtension sClassExtension = {
     952             :   nullptr, /* weakmapKeyDelegateOp */
     953             :   _objectMoved /* objectMovedOp */
     954             : };
     955             : 
     956             : static const DOMJSClass sClass = {
     957             :   { "ServiceWorkerGlobalScope",
     958             :     JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_DOM_GLOBAL | JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(DOM_GLOBAL_SLOTS),
     959             :     &sClassOps,
     960             :     JS_NULL_CLASS_SPEC,
     961             :     &sClassExtension,
     962             :     JS_NULL_OBJECT_OPS
     963             :   },
     964             :   { prototypes::id::EventTarget, prototypes::id::WorkerGlobalScope, prototypes::id::ServiceWorkerGlobalScope, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
     965             :   IsBaseOf<nsISupports, mozilla::dom::ServiceWorkerGlobalScope >::value,
     966             :   &sEmptyNativePropertyHooks,
     967             :   FindAssociatedGlobalForNative<mozilla::dom::ServiceWorkerGlobalScope>::Get,
     968             :   GetProtoObjectHandle,
     969             :   GetCCParticipant<mozilla::dom::ServiceWorkerGlobalScope>::Get()
     970             : };
     971             : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
     972             :               "Must have the right minimal number of reserved slots.");
     973             : static_assert(JSCLASS_GLOBAL_APPLICATION_SLOTS >= 3,
     974             :               "Must have enough reserved slots.");
     975             : 
     976             : const JSClass*
     977           0 : GetJSClass()
     978             : {
     979           0 :   return sClass.ToJSClass();
     980             : }
     981             : 
     982             : bool
     983           0 : Wrap(JSContext* aCx, mozilla::dom::ServiceWorkerGlobalScope* aObject, nsWrapperCache* aCache, JS::CompartmentOptions& aOptions, JSPrincipals* aPrincipal, bool aInitStandardClasses, JS::MutableHandle<JSObject*> aReflector)
     984             : {
     985             :   MOZ_ASSERT(static_cast<mozilla::dom::ServiceWorkerGlobalScope*>(aObject) ==
     986             :              reinterpret_cast<mozilla::dom::ServiceWorkerGlobalScope*>(aObject),
     987             :              "Multiple inheritance for mozilla::dom::ServiceWorkerGlobalScope is broken.");
     988             :   MOZ_ASSERT(static_cast<mozilla::dom::WorkerGlobalScope*>(aObject) ==
     989             :              reinterpret_cast<mozilla::dom::WorkerGlobalScope*>(aObject),
     990             :              "Multiple inheritance for mozilla::dom::WorkerGlobalScope is broken.");
     991             :   MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
     992             :              reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
     993             :              "Multiple inheritance for mozilla::dom::EventTarget is broken.");
     994           0 :   MOZ_ASSERT(ToSupportsIsCorrect(aObject));
     995           0 :   MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
     996             :              "nsISupports must be on our primary inheritance chain");
     997             : 
     998           0 :   if (!CreateGlobal<mozilla::dom::ServiceWorkerGlobalScope, GetProtoObjectHandle>(aCx,
     999             :                                    aObject,
    1000             :                                    aCache,
    1001             :                                    sClass.ToJSClass(),
    1002             :                                    aOptions,
    1003             :                                    aPrincipal,
    1004             :                                    aInitStandardClasses,
    1005             :                                    aReflector)) {
    1006           0 :     aCache->ReleaseWrapper(aObject);
    1007           0 :     aCache->ClearWrapper();
    1008           0 :     return false;
    1009             :   }
    1010             : 
    1011             :   // aReflector is a new global, so has a new compartment.  Enter it
    1012             :   // before doing anything with it.
    1013           0 :   JSAutoCompartment ac(aCx, aReflector);
    1014             : 
    1015           0 :   if (!DefineProperties(aCx, aReflector, sNativeProperties.Upcast(), nullptr)) {
    1016           0 :     aCache->ReleaseWrapper(aObject);
    1017           0 :     aCache->ClearWrapper();
    1018           0 :     return false;
    1019             :   }
    1020             : 
    1021             : 
    1022           0 :   return true;
    1023             : }
    1024             : 
    1025             : void
    1026           0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
    1027             : {
    1028           0 :   JS::Handle<JSObject*> parentProto(WorkerGlobalScopeBinding::GetProtoObjectHandle(aCx));
    1029           0 :   if (!parentProto) {
    1030           0 :     return;
    1031             :   }
    1032             : 
    1033           0 :   JS::Handle<JSObject*> constructorProto(WorkerGlobalScopeBinding::GetConstructorObjectHandle(aCx));
    1034           0 :   if (!constructorProto) {
    1035           0 :     return;
    1036             :   }
    1037             : 
    1038           0 :   JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::ServiceWorkerGlobalScope);
    1039           0 :   JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::ServiceWorkerGlobalScope);
    1040           0 :   dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
    1041             :                               &sPrototypeClass.mBase, protoCache,
    1042             :                               constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
    1043             :                               interfaceCache,
    1044             :                               sNativeProperties.Upcast(),
    1045             :                               nullptr,
    1046             :                               "ServiceWorkerGlobalScope", aDefineOnGlobal,
    1047             :                               nullptr,
    1048           0 :                               true);
    1049             : 
    1050           0 :   if (*&aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::ServiceWorkerGlobalScope)) {
    1051             :     bool succeeded;
    1052           0 :     JS::Handle<JSObject*> prot = GetProtoObjectHandle(aCx);
    1053           0 :     if (!JS_SetImmutablePrototype(aCx, prot, &succeeded)) {
    1054           0 :       *protoCache = nullptr;
    1055           0 :       if (interfaceCache) {
    1056           0 :         *interfaceCache = nullptr;
    1057             :       }
    1058           0 :       return;
    1059             :     }
    1060             : 
    1061           0 :     MOZ_ASSERT(succeeded,
    1062             :                "making a fresh prototype object's [[Prototype]] "
    1063             :                "immutable can internally fail, but it should "
    1064             :                "never be unsuccessful");
    1065             :   }
    1066             : }
    1067             : 
    1068             : JS::Handle<JSObject*>
    1069           0 : GetProtoObjectHandle(JSContext* aCx)
    1070             : {
    1071             :   /* Get the interface prototype object for this class.  This will create the
    1072             :      object as needed. */
    1073           0 :   bool aDefineOnGlobal = true;
    1074             : 
    1075             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
    1076           0 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
    1077           0 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
    1078           0 :     return nullptr;
    1079             :   }
    1080             : 
    1081             :   /* Check to see whether the interface objects are already installed */
    1082           0 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
    1083           0 :   if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::ServiceWorkerGlobalScope)) {
    1084           0 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
    1085           0 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
    1086             :   }
    1087             : 
    1088             :   /*
    1089             :    * The object might _still_ be null, but that's OK.
    1090             :    *
    1091             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
    1092             :    * traced by TraceProtoAndIfaceCache() and its contents are never
    1093             :    * changed after they have been set.
    1094             :    *
    1095             :    * Calling address() avoids the read read barrier that does gray
    1096             :    * unmarking, but it's not possible for the object to be gray here.
    1097             :    */
    1098             : 
    1099           0 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::ServiceWorkerGlobalScope);
    1100           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
    1101           0 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
    1102             : }
    1103             : 
    1104             : JS::Handle<JSObject*>
    1105           0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
    1106             : {
    1107             :   /* Get the interface object for this class.  This will create the object as
    1108             :      needed. */
    1109             : 
    1110             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
    1111           0 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
    1112           0 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
    1113           0 :     return nullptr;
    1114             :   }
    1115             : 
    1116             :   /* Check to see whether the interface objects are already installed */
    1117           0 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
    1118           0 :   if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::ServiceWorkerGlobalScope)) {
    1119           0 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
    1120           0 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
    1121             :   }
    1122             : 
    1123             :   /*
    1124             :    * The object might _still_ be null, but that's OK.
    1125             :    *
    1126             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
    1127             :    * traced by TraceProtoAndIfaceCache() and its contents are never
    1128             :    * changed after they have been set.
    1129             :    *
    1130             :    * Calling address() avoids the read read barrier that does gray
    1131             :    * unmarking, but it's not possible for the object to be gray here.
    1132             :    */
    1133             : 
    1134           0 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::ServiceWorkerGlobalScope);
    1135           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
    1136           0 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
    1137             : }
    1138             : 
    1139             : JSObject*
    1140           0 : GetConstructorObject(JSContext* aCx)
    1141             : {
    1142           0 :   return GetConstructorObjectHandle(aCx);
    1143             : }
    1144             : 
    1145             : } // namespace ServiceWorkerGlobalScopeBinding
    1146             : 
    1147             : 
    1148             : 
    1149             : } // namespace dom
    1150             : } // namespace mozilla

Generated by: LCOV version 1.13