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

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

Generated by: LCOV version 1.13