LCOV - code coverage report
Current view: top level - obj-x86_64-pc-linux-gnu/dom/bindings - BroadcastChannelBinding.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 22 172 12.8 %
Date: 2017-07-14 16:53:18 Functions: 3 16 18.8 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.13