LCOV - code coverage report
Current view: top level - obj-x86_64-pc-linux-gnu/dom/bindings - EventSourceBinding.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 27 293 9.2 %
Date: 2017-07-14 16:53:18 Functions: 4 30 13.3 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.13