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

          Line data    Source code
       1             : /* THIS FILE IS AUTOGENERATED FROM HTMLStyleElement.webidl BY Codegen.py - DO NOT EDIT */
       2             : 
       3             : #include "HTMLElementBinding.h"
       4             : #include "HTMLStyleElementBinding.h"
       5             : #include "WrapperFactory.h"
       6             : #include "mozilla/OwningNonNull.h"
       7             : #include "mozilla/Preferences.h"
       8             : #include "mozilla/StyleSheetInlines.h"
       9             : #include "mozilla/dom/BindingUtils.h"
      10             : #include "mozilla/dom/CustomElementRegistry.h"
      11             : #include "mozilla/dom/DOMJSClass.h"
      12             : #include "mozilla/dom/HTMLStyleElement.h"
      13             : #include "mozilla/dom/NonRefcountedDOMObject.h"
      14             : #include "mozilla/dom/Nullable.h"
      15             : #include "mozilla/dom/PrimitiveConversions.h"
      16             : #include "mozilla/dom/XrayExpandoClass.h"
      17             : 
      18             : namespace mozilla {
      19             : namespace dom {
      20             : 
      21             : namespace HTMLStyleElementBinding {
      22             : 
      23             : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<HTMLElementBinding::NativeType>::value,
      24             :               "Can't inherit from an interface with a different ownership model.");
      25             : 
      26             : static bool
      27           0 : get_disabled(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLStyleElement* self, JSJitGetterCallArgs args)
      28             : {
      29           0 :   bool result(self->Disabled());
      30           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
      31           0 :   args.rval().setBoolean(result);
      32           0 :   return true;
      33             : }
      34             : 
      35             : static bool
      36           0 : set_disabled(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLStyleElement* self, JSJitSetterCallArgs args)
      37             : {
      38             :   bool arg0;
      39           0 :   if (!ValueToPrimitive<bool, eDefault>(cx, args[0], &arg0)) {
      40           0 :     return false;
      41             :   }
      42           0 :   self->SetDisabled(arg0);
      43           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
      44             : 
      45           0 :   return true;
      46             : }
      47             : 
      48             : static const JSJitInfo disabled_getterinfo = {
      49             :   { (JSJitGetterOp)get_disabled },
      50             :   { prototypes::id::HTMLStyleElement },
      51             :   { PrototypeTraits<prototypes::id::HTMLStyleElement>::Depth },
      52             :   JSJitInfo::Getter,
      53             :   JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
      54             :   JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
      55             :   true,  /* isInfallible. False in setters. */
      56             :   true,  /* isMovable.  Not relevant for setters. */
      57             :   true, /* isEliminatable.  Not relevant for setters. */
      58             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
      59             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
      60             :   false,  /* isTypedMethod.  Only relevant for methods. */
      61             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
      62             : };
      63             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
      64             : static_assert(0 < 1, "There is no slot for us");
      65             : static const JSJitInfo disabled_setterinfo = {
      66             :   { (JSJitGetterOp)set_disabled },
      67             :   { prototypes::id::HTMLStyleElement },
      68             :   { PrototypeTraits<prototypes::id::HTMLStyleElement>::Depth },
      69             :   JSJitInfo::Setter,
      70             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
      71             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
      72             :   false,  /* isInfallible. False in setters. */
      73             :   false,  /* isMovable.  Not relevant for setters. */
      74             :   false, /* isEliminatable.  Not relevant for setters. */
      75             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
      76             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
      77             :   false,  /* isTypedMethod.  Only relevant for methods. */
      78             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
      79             : };
      80             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
      81             : static_assert(0 < 1, "There is no slot for us");
      82             : 
      83             : static bool
      84           0 : get_media(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLStyleElement* self, JSJitGetterCallArgs args)
      85             : {
      86           0 :   DOMString result;
      87           0 :   self->GetMedia(result);
      88           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
      89           0 :   if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
      90           0 :     return false;
      91             :   }
      92           0 :   return true;
      93             : }
      94             : 
      95             : static bool
      96           0 : set_media(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLStyleElement* self, JSJitSetterCallArgs args)
      97             : {
      98           0 :   binding_detail::FakeString arg0;
      99           0 :   if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
     100           0 :     return false;
     101             :   }
     102           0 :   CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(obj);
     103           0 :   Maybe<AutoCEReaction> ceReaction;
     104           0 :   if (reactionsStack) {
     105           0 :     ceReaction.emplace(reactionsStack);
     106             :   }
     107           0 :   binding_detail::FastErrorResult rv;
     108           0 :   self->SetMedia(NonNullHelper(Constify(arg0)), rv);
     109           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     110           0 :     return false;
     111             :   }
     112           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     113             : 
     114           0 :   return true;
     115             : }
     116             : 
     117             : static const JSJitInfo media_getterinfo = {
     118             :   { (JSJitGetterOp)get_media },
     119             :   { prototypes::id::HTMLStyleElement },
     120             :   { PrototypeTraits<prototypes::id::HTMLStyleElement>::Depth },
     121             :   JSJitInfo::Getter,
     122             :   JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
     123             :   JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
     124             :   false,  /* isInfallible. False in setters. */
     125             :   true,  /* isMovable.  Not relevant for setters. */
     126             :   true, /* isEliminatable.  Not relevant for setters. */
     127             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     128             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     129             :   false,  /* isTypedMethod.  Only relevant for methods. */
     130             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     131             : };
     132             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     133             : static_assert(0 < 1, "There is no slot for us");
     134             : static const JSJitInfo media_setterinfo = {
     135             :   { (JSJitGetterOp)set_media },
     136             :   { prototypes::id::HTMLStyleElement },
     137             :   { PrototypeTraits<prototypes::id::HTMLStyleElement>::Depth },
     138             :   JSJitInfo::Setter,
     139             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     140             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
     141             :   false,  /* isInfallible. False in setters. */
     142             :   false,  /* isMovable.  Not relevant for setters. */
     143             :   false, /* isEliminatable.  Not relevant for setters. */
     144             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     145             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     146             :   false,  /* isTypedMethod.  Only relevant for methods. */
     147             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     148             : };
     149             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     150             : static_assert(0 < 1, "There is no slot for us");
     151             : 
     152             : static bool
     153           0 : get_type(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLStyleElement* self, JSJitGetterCallArgs args)
     154             : {
     155           0 :   DOMString result;
     156           0 :   self->GetType(result);
     157           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     158           0 :   if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
     159           0 :     return false;
     160             :   }
     161           0 :   return true;
     162             : }
     163             : 
     164             : static bool
     165           0 : set_type(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLStyleElement* self, JSJitSetterCallArgs args)
     166             : {
     167           0 :   binding_detail::FakeString arg0;
     168           0 :   if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
     169           0 :     return false;
     170             :   }
     171           0 :   CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(obj);
     172           0 :   Maybe<AutoCEReaction> ceReaction;
     173           0 :   if (reactionsStack) {
     174           0 :     ceReaction.emplace(reactionsStack);
     175             :   }
     176           0 :   binding_detail::FastErrorResult rv;
     177           0 :   self->SetType(NonNullHelper(Constify(arg0)), rv);
     178           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     179           0 :     return false;
     180             :   }
     181           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     182             : 
     183           0 :   return true;
     184             : }
     185             : 
     186             : static const JSJitInfo type_getterinfo = {
     187             :   { (JSJitGetterOp)get_type },
     188             :   { prototypes::id::HTMLStyleElement },
     189             :   { PrototypeTraits<prototypes::id::HTMLStyleElement>::Depth },
     190             :   JSJitInfo::Getter,
     191             :   JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
     192             :   JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
     193             :   false,  /* isInfallible. False in setters. */
     194             :   true,  /* isMovable.  Not relevant for setters. */
     195             :   true, /* isEliminatable.  Not relevant for setters. */
     196             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     197             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     198             :   false,  /* isTypedMethod.  Only relevant for methods. */
     199             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     200             : };
     201             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     202             : static_assert(0 < 1, "There is no slot for us");
     203             : static const JSJitInfo type_setterinfo = {
     204             :   { (JSJitGetterOp)set_type },
     205             :   { prototypes::id::HTMLStyleElement },
     206             :   { PrototypeTraits<prototypes::id::HTMLStyleElement>::Depth },
     207             :   JSJitInfo::Setter,
     208             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     209             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
     210             :   false,  /* isInfallible. False in setters. */
     211             :   false,  /* isMovable.  Not relevant for setters. */
     212             :   false, /* isEliminatable.  Not relevant for setters. */
     213             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     214             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     215             :   false,  /* isTypedMethod.  Only relevant for methods. */
     216             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     217             : };
     218             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     219             : static_assert(0 < 1, "There is no slot for us");
     220             : 
     221             : static bool
     222           0 : get_scoped(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLStyleElement* self, JSJitGetterCallArgs args)
     223             : {
     224           0 :   bool result(self->Scoped());
     225           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     226           0 :   args.rval().setBoolean(result);
     227           0 :   return true;
     228             : }
     229             : 
     230             : static bool
     231           0 : set_scoped(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLStyleElement* self, JSJitSetterCallArgs args)
     232             : {
     233             :   bool arg0;
     234           0 :   if (!ValueToPrimitive<bool, eDefault>(cx, args[0], &arg0)) {
     235           0 :     return false;
     236             :   }
     237           0 :   binding_detail::FastErrorResult rv;
     238           0 :   self->SetScoped(arg0, rv);
     239           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     240           0 :     return false;
     241             :   }
     242           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     243             : 
     244           0 :   return true;
     245             : }
     246             : 
     247             : static const JSJitInfo scoped_getterinfo = {
     248             :   { (JSJitGetterOp)get_scoped },
     249             :   { prototypes::id::HTMLStyleElement },
     250             :   { PrototypeTraits<prototypes::id::HTMLStyleElement>::Depth },
     251             :   JSJitInfo::Getter,
     252             :   JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
     253             :   JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
     254             :   true,  /* isInfallible. False in setters. */
     255             :   true,  /* isMovable.  Not relevant for setters. */
     256             :   true, /* isEliminatable.  Not relevant for setters. */
     257             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     258             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     259             :   false,  /* isTypedMethod.  Only relevant for methods. */
     260             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     261             : };
     262             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     263             : static_assert(0 < 1, "There is no slot for us");
     264             : static const JSJitInfo scoped_setterinfo = {
     265             :   { (JSJitGetterOp)set_scoped },
     266             :   { prototypes::id::HTMLStyleElement },
     267             :   { PrototypeTraits<prototypes::id::HTMLStyleElement>::Depth },
     268             :   JSJitInfo::Setter,
     269             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     270             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
     271             :   false,  /* isInfallible. False in setters. */
     272             :   false,  /* isMovable.  Not relevant for setters. */
     273             :   false, /* isEliminatable.  Not relevant for setters. */
     274             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     275             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     276             :   false,  /* isTypedMethod.  Only relevant for methods. */
     277             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     278             : };
     279             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     280             : static_assert(0 < 1, "There is no slot for us");
     281             : 
     282             : static bool
     283           0 : get_sheet(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLStyleElement* self, JSJitGetterCallArgs args)
     284             : {
     285           0 :   auto result(StrongOrRawPtr<mozilla::StyleSheet>(self->GetSheet()));
     286           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     287           0 :   if (!result) {
     288           0 :     args.rval().setNull();
     289           0 :     return true;
     290             :   }
     291           0 :   if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
     292           0 :     MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     293           0 :     return false;
     294             :   }
     295           0 :   return true;
     296             : }
     297             : 
     298             : static const JSJitInfo sheet_getterinfo = {
     299             :   { (JSJitGetterOp)get_sheet },
     300             :   { prototypes::id::HTMLStyleElement },
     301             :   { PrototypeTraits<prototypes::id::HTMLStyleElement>::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             : 
     316             : static bool
     317           0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
     318             : {
     319           0 :   mozilla::dom::HTMLStyleElement* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::HTMLStyleElement>(obj);
     320             :   // We don't want to preserve if we don't have a wrapper, and we
     321             :   // obviously can't preserve if we're not initialized.
     322           0 :   if (self && self->GetWrapperPreserveColor()) {
     323           0 :     PreserveWrapper(self);
     324             :   }
     325           0 :   return true;
     326             : }
     327             : 
     328             : static void
     329           0 : _finalize(js::FreeOp* fop, JSObject* obj)
     330             : {
     331           0 :   mozilla::dom::HTMLStyleElement* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::HTMLStyleElement>(obj);
     332           0 :   if (self) {
     333           0 :     ClearWrapper(self, self, obj);
     334           0 :     AddForDeferredFinalization<mozilla::dom::HTMLStyleElement>(self);
     335             :   }
     336           0 : }
     337             : 
     338             : static void
     339           0 : _objectMoved(JSObject* obj, const JSObject* old)
     340             : {
     341           0 :   mozilla::dom::HTMLStyleElement* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::HTMLStyleElement>(obj);
     342           0 :   if (self) {
     343           0 :     UpdateWrapper(self, self, obj, old);
     344             :   }
     345           0 : }
     346             : 
     347             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
     348             : #if defined(__clang__)
     349             : #pragma clang diagnostic push
     350             : #pragma clang diagnostic ignored "-Wmissing-braces"
     351             : #endif
     352             : static const JSPropertySpec sAttributes_specs[] = {
     353             :   { "disabled", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &disabled_getterinfo, GenericBindingSetter, &disabled_setterinfo },
     354             :   { "media", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &media_getterinfo, GenericBindingSetter, &media_setterinfo },
     355             :   { "type", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &type_getterinfo, GenericBindingSetter, &type_setterinfo },
     356             :   { nullptr, 0, nullptr, nullptr, nullptr, nullptr },
     357             :   { "scoped", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &scoped_getterinfo, GenericBindingSetter, &scoped_setterinfo },
     358             :   { nullptr, 0, nullptr, nullptr, nullptr, nullptr },
     359             :   { "sheet", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &sheet_getterinfo, nullptr, nullptr },
     360             :   { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
     361             : };
     362             : #if defined(__clang__)
     363             : #pragma clang diagnostic pop
     364             : #endif
     365             : 
     366             : static PrefableDisablers sAttributes_disablers4 = {
     367             :   true, false, 0, nullptr
     368             : };
     369             : 
     370             : // Can't be const because the pref-enabled boolean needs to be writable
     371             : static Prefable<const JSPropertySpec> sAttributes[] = {
     372             :   { nullptr, &sAttributes_specs[0] },
     373             :   { &sAttributes_disablers4, &sAttributes_specs[4] },
     374             :   { nullptr, &sAttributes_specs[6] },
     375             :   { nullptr, nullptr }
     376             : };
     377             : 
     378             : static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
     379             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
     380             : static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
     381             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
     382             : 
     383             : 
     384             : static uint16_t sNativeProperties_sortedPropertyIndices[5];
     385             : static PropertyInfo sNativeProperties_propertyInfos[5];
     386             : 
     387             : static const NativePropertiesN<1> sNativeProperties = {
     388             :   false, 0,
     389             :   false, 0,
     390             :   false, 0,
     391             :   true,  0 /* sAttributes */,
     392             :   false, 0,
     393             :   false, 0,
     394             :   false, 0,
     395             :   -1,
     396             :   5,
     397             :   sNativeProperties_sortedPropertyIndices,
     398             :   {
     399             :     { sAttributes, &sNativeProperties_propertyInfos[0] }
     400             :   }
     401             : };
     402             : static_assert(5 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
     403             :     "We have a property info count that is oversized");
     404             : 
     405             : static bool
     406           0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
     407             : {
     408           0 :   JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
     409           0 :   JS::Rooted<JSObject*> obj(cx, &args.callee());
     410           0 :   if (!args.isConstructing()) {
     411             :     // XXXbz wish I could get the name from the callee instead of
     412             :     // Adding more relocations
     413           0 :     return ThrowConstructorWithoutNew(cx, "HTMLStyleElement");
     414             :   }
     415             : 
     416           0 :   GlobalObject global(cx, obj);
     417           0 :   if (global.Failed()) {
     418           0 :     return false;
     419             :   }
     420             : 
     421             :   // The newTarget might be a cross-compartment wrapper. Get the underlying object
     422             :   // so we can do the spec's object-identity checks.
     423           0 :   JS::Rooted<JSObject*> newTarget(cx, js::CheckedUnwrap(&args.newTarget().toObject()));
     424           0 :   if (!newTarget) {
     425           0 :     return ThrowErrorMessage(cx, MSG_ILLEGAL_CONSTRUCTOR);
     426             :   }
     427             : 
     428             :   // Step 2 of https://html.spec.whatwg.org/multipage/dom.html#htmlconstructor.
     429             :   // Enter the compartment of our underlying newTarget object, so we end
     430             :   // up comparing to the constructor object for our interface from that global.
     431             :   {
     432           0 :     JSAutoCompartment ac(cx, newTarget);
     433           0 :     JS::Handle<JSObject*> constructor(GetConstructorObjectHandle(cx));
     434           0 :     if (!constructor) {
     435           0 :       return false;
     436             :     }
     437           0 :     if (newTarget == constructor) {
     438           0 :       return ThrowErrorMessage(cx, MSG_ILLEGAL_CONSTRUCTOR);
     439             :     }
     440             :   }
     441             : 
     442           0 :   JS::Rooted<JSObject*> desiredProto(cx);
     443           0 :   if (!GetDesiredProto(cx, args, &desiredProto)) {
     444           0 :     return false;
     445             :   }
     446           0 :   if (!desiredProto) {
     447             :     // Step 7 of https://html.spec.whatwg.org/multipage/dom.html#htmlconstructor.
     448             :     // This fallback behavior is designed to match analogous behavior for the
     449             :     // JavaScript built-ins. So we enter the compartment of our underlying
     450             :     // newTarget object and fall back to the prototype object from that global.
     451             :     // XXX The spec says to use GetFunctionRealm(), which is not actually
     452             :     // the same thing as what we have here (e.g. in the case of scripted callable proxies
     453             :     // whose target is not same-compartment with the proxy, or bound functions, etc).
     454             :     // https://bugzilla.mozilla.org/show_bug.cgi?id=1317658
     455             :     {
     456           0 :       JSAutoCompartment ac(cx, newTarget);
     457           0 :       desiredProto = GetProtoObjectHandle(cx);
     458           0 :       if (!desiredProto) {
     459           0 :           return false;
     460             :       }
     461             :     }
     462             : 
     463             :     // desiredProto is in the compartment of the underlying newTarget object.
     464             :     // Wrap it into the context compartment.
     465           0 :     if (!JS_WrapObject(cx, &desiredProto)) {
     466           0 :       return false;
     467             :     }
     468             :   }
     469             : 
     470           0 :   bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
     471           0 :   Maybe<JSAutoCompartment> ac;
     472           0 :   if (objIsXray) {
     473           0 :     obj = js::CheckedUnwrap(obj);
     474           0 :     if (!obj) {
     475           0 :       return false;
     476             :     }
     477           0 :     ac.emplace(cx, obj);
     478           0 :     if (!JS_WrapObject(cx, &desiredProto)) {
     479           0 :       return false;
     480             :     }
     481             :   }
     482           0 :   binding_detail::FastErrorResult rv;
     483           0 :   auto result(StrongOrRawPtr<mozilla::dom::HTMLStyleElement>(CreateHTMLElement(global, args, rv)));
     484           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     485           0 :     return false;
     486             :   }
     487           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     488             :   static_assert(!IsPointer<decltype(result)>::value,
     489             :                 "NewObject implies that we need to keep the object alive with a strong reference.");
     490           0 :   if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
     491           0 :     MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     492           0 :     return false;
     493             :   }
     494           0 :   return true;
     495             : }
     496             : 
     497             : static const js::ClassOps sInterfaceObjectClassOps = {
     498             :     nullptr,               /* addProperty */
     499             :     nullptr,               /* delProperty */
     500             :     nullptr,               /* getProperty */
     501             :     nullptr,               /* setProperty */
     502             :     nullptr,               /* enumerate */
     503             :     nullptr,               /* newEnumerate */
     504             :     nullptr,               /* resolve */
     505             :     nullptr,               /* mayResolve */
     506             :     nullptr,               /* finalize */
     507             :     _constructor, /* call */
     508             :     nullptr,               /* hasInstance */
     509             :     _constructor, /* construct */
     510             :     nullptr,               /* trace */
     511             : };
     512             : 
     513             : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
     514             :   {
     515             :     "Function",
     516             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
     517             :     &sInterfaceObjectClassOps,
     518             :     JS_NULL_CLASS_SPEC,
     519             :     JS_NULL_CLASS_EXT,
     520             :     &sInterfaceObjectClassObjectOps
     521             :   },
     522             :   eInterface,
     523             :   true,
     524             :   prototypes::id::HTMLStyleElement,
     525             :   PrototypeTraits<prototypes::id::HTMLStyleElement>::Depth,
     526             :   sNativePropertyHooks,
     527             :   "function HTMLStyleElement() {\n    [native code]\n}",
     528             :   HTMLElementBinding::GetConstructorObject
     529             : };
     530             : 
     531             : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
     532             :   {
     533             :     "HTMLStyleElementPrototype",
     534             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
     535             :     JS_NULL_CLASS_OPS,
     536             :     JS_NULL_CLASS_SPEC,
     537             :     JS_NULL_CLASS_EXT,
     538             :     JS_NULL_OBJECT_OPS
     539             :   },
     540             :   eInterfacePrototype,
     541             :   false,
     542             :   prototypes::id::HTMLStyleElement,
     543             :   PrototypeTraits<prototypes::id::HTMLStyleElement>::Depth,
     544             :   sNativePropertyHooks,
     545             :   "[object HTMLStyleElementPrototype]",
     546             :   HTMLElementBinding::GetProtoObject
     547             : };
     548             : 
     549             : JSObject*
     550           0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
     551             : {
     552           0 :   return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
     553             : }
     554             : 
     555             : static const js::ClassOps sClassOps = {
     556             :   _addProperty, /* addProperty */
     557             :   nullptr,               /* delProperty */
     558             :   nullptr,               /* getProperty */
     559             :   nullptr,               /* setProperty */
     560             :   nullptr,               /* enumerate */
     561             :   nullptr, /* newEnumerate */
     562             :   nullptr, /* resolve */
     563             :   nullptr, /* mayResolve */
     564             :   _finalize, /* finalize */
     565             :   nullptr, /* call */
     566             :   nullptr,               /* hasInstance */
     567             :   nullptr,               /* construct */
     568             :   nullptr, /* trace */
     569             : };
     570             : 
     571             : static const js::ClassExtension sClassExtension = {
     572             :   nullptr, /* weakmapKeyDelegateOp */
     573             :   _objectMoved /* objectMovedOp */
     574             : };
     575             : 
     576             : static const DOMJSClass sClass = {
     577             :   { "HTMLStyleElement",
     578             :     JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
     579             :     &sClassOps,
     580             :     JS_NULL_CLASS_SPEC,
     581             :     &sClassExtension,
     582             :     JS_NULL_OBJECT_OPS
     583             :   },
     584             :   { prototypes::id::EventTarget, prototypes::id::Node, prototypes::id::Element, prototypes::id::HTMLElement, prototypes::id::HTMLStyleElement, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
     585             :   IsBaseOf<nsISupports, mozilla::dom::HTMLStyleElement >::value,
     586             :   sNativePropertyHooks,
     587             :   FindAssociatedGlobalForNative<mozilla::dom::HTMLStyleElement>::Get,
     588             :   GetProtoObjectHandle,
     589             :   GetCCParticipant<mozilla::dom::HTMLStyleElement>::Get()
     590             : };
     591             : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
     592             :               "Must have the right minimal number of reserved slots.");
     593             : static_assert(1 >= 1,
     594             :               "Must have enough reserved slots.");
     595             : 
     596             : const JSClass*
     597           0 : GetJSClass()
     598             : {
     599           0 :   return sClass.ToJSClass();
     600             : }
     601             : 
     602             : bool
     603           0 : Wrap(JSContext* aCx, mozilla::dom::HTMLStyleElement* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
     604             : {
     605             :   MOZ_ASSERT(static_cast<mozilla::dom::HTMLStyleElement*>(aObject) ==
     606             :              reinterpret_cast<mozilla::dom::HTMLStyleElement*>(aObject),
     607             :              "Multiple inheritance for mozilla::dom::HTMLStyleElement is broken.");
     608             :   MOZ_ASSERT(static_cast<nsGenericHTMLElement*>(aObject) ==
     609             :              reinterpret_cast<nsGenericHTMLElement*>(aObject),
     610             :              "Multiple inheritance for nsGenericHTMLElement is broken.");
     611             :   MOZ_ASSERT(static_cast<mozilla::dom::Element*>(aObject) ==
     612             :              reinterpret_cast<mozilla::dom::Element*>(aObject),
     613             :              "Multiple inheritance for mozilla::dom::Element is broken.");
     614             :   MOZ_ASSERT(static_cast<nsINode*>(aObject) ==
     615             :              reinterpret_cast<nsINode*>(aObject),
     616             :              "Multiple inheritance for nsINode is broken.");
     617             :   MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
     618             :              reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
     619             :              "Multiple inheritance for mozilla::dom::EventTarget is broken.");
     620           0 :   MOZ_ASSERT(ToSupportsIsCorrect(aObject));
     621           0 :   MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
     622           0 :   MOZ_ASSERT(!aCache->GetWrapper(),
     623             :              "You should probably not be using Wrap() directly; use "
     624             :              "GetOrCreateDOMReflector instead");
     625             : 
     626           0 :   MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
     627             :              "nsISupports must be on our primary inheritance chain");
     628             : 
     629           0 :   JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
     630           0 :   if (!global) {
     631           0 :     return false;
     632             :   }
     633           0 :   MOZ_ASSERT(JS_IsGlobalObject(global));
     634           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(global));
     635             : 
     636             :   // That might have ended up wrapping us already, due to the wonders
     637             :   // of XBL.  Check for that, and bail out as needed.
     638           0 :   aReflector.set(aCache->GetWrapper());
     639           0 :   if (aReflector) {
     640             : #ifdef DEBUG
     641           0 :     binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
     642             : #endif // DEBUG
     643           0 :     return true;
     644             :   }
     645             : 
     646           0 :   JSAutoCompartment ac(aCx, global);
     647           0 :   JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
     648           0 :   if (!canonicalProto) {
     649           0 :     return false;
     650             :   }
     651           0 :   JS::Rooted<JSObject*> proto(aCx);
     652           0 :   if (aGivenProto) {
     653           0 :     proto = aGivenProto;
     654             :     // Unfortunately, while aGivenProto was in the compartment of aCx
     655             :     // coming in, we changed compartments to that of "parent" so may need
     656             :     // to wrap the proto here.
     657           0 :     if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
     658           0 :       if (!JS_WrapObject(aCx, &proto)) {
     659           0 :         return false;
     660             :       }
     661             :     }
     662             :   } else {
     663           0 :     proto = canonicalProto;
     664             :   }
     665             : 
     666           0 :   BindingJSObjectCreator<mozilla::dom::HTMLStyleElement> creator(aCx);
     667           0 :   creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
     668           0 :   if (!aReflector) {
     669           0 :     return false;
     670             :   }
     671             : 
     672           0 :   aCache->SetWrapper(aReflector);
     673           0 :   creator.InitializationSucceeded();
     674             : 
     675           0 :   MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
     676             :              aCache->GetWrapperPreserveColor() == aReflector);
     677             :   // If proto != canonicalProto, we have to preserve our wrapper;
     678             :   // otherwise we won't be able to properly recreate it later, since
     679             :   // we won't know what proto to use.  Note that we don't check
     680             :   // aGivenProto here, since it's entirely possible (and even
     681             :   // somewhat common) to have a non-null aGivenProto which is the
     682             :   // same as canonicalProto.
     683           0 :   if (proto != canonicalProto) {
     684           0 :     PreserveWrapper(aObject);
     685             :   }
     686             : 
     687           0 :   return true;
     688             : }
     689             : 
     690             : const NativePropertyHooks sNativePropertyHooks[] = { {
     691             :   nullptr,
     692             :   nullptr,
     693             :   nullptr,
     694             :   { sNativeProperties.Upcast(), nullptr },
     695             :   prototypes::id::HTMLStyleElement,
     696             :   constructors::id::HTMLStyleElement,
     697             :   HTMLElementBinding::sNativePropertyHooks,
     698             :   &DefaultXrayExpandoObjectClass
     699             : } };
     700             : 
     701             : void
     702           0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
     703             : {
     704           0 :   JS::Handle<JSObject*> parentProto(HTMLElementBinding::GetProtoObjectHandle(aCx));
     705           0 :   if (!parentProto) {
     706           0 :     return;
     707             :   }
     708             : 
     709           0 :   JS::Handle<JSObject*> constructorProto(HTMLElementBinding::GetConstructorObjectHandle(aCx));
     710           0 :   if (!constructorProto) {
     711           0 :     return;
     712             :   }
     713             : 
     714             :   static bool sIdsInited = false;
     715           0 :   if (!sIdsInited && NS_IsMainThread()) {
     716           0 :     if (!InitIds(aCx, sNativeProperties.Upcast())) {
     717           0 :       return;
     718             :     }
     719           0 :     sIdsInited = true;
     720             :   }
     721             : 
     722             :   static bool sPrefCachesInited = false;
     723           0 :   if (!sPrefCachesInited && NS_IsMainThread()) {
     724           0 :     sPrefCachesInited = true;
     725           0 :     Preferences::AddBoolVarCache(&sAttributes[1].disablers->enabled, "layout.css.scoped-style.enabled");
     726             :   }
     727             : 
     728           0 :   JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::HTMLStyleElement);
     729           0 :   JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::HTMLStyleElement);
     730           0 :   dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
     731             :                               &sPrototypeClass.mBase, protoCache,
     732             :                               constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
     733             :                               interfaceCache,
     734             :                               sNativeProperties.Upcast(),
     735             :                               nullptr,
     736             :                               "HTMLStyleElement", aDefineOnGlobal,
     737             :                               nullptr,
     738           0 :                               false);
     739             : }
     740             : 
     741             : JS::Handle<JSObject*>
     742           0 : GetProtoObjectHandle(JSContext* aCx)
     743             : {
     744             :   /* Get the interface prototype object for this class.  This will create the
     745             :      object as needed. */
     746           0 :   bool aDefineOnGlobal = true;
     747             : 
     748             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
     749           0 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
     750           0 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
     751           0 :     return nullptr;
     752             :   }
     753             : 
     754             :   /* Check to see whether the interface objects are already installed */
     755           0 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
     756           0 :   if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::HTMLStyleElement)) {
     757           0 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
     758           0 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
     759             :   }
     760             : 
     761             :   /*
     762             :    * The object might _still_ be null, but that's OK.
     763             :    *
     764             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
     765             :    * traced by TraceProtoAndIfaceCache() and its contents are never
     766             :    * changed after they have been set.
     767             :    *
     768             :    * Calling address() avoids the read read barrier that does gray
     769             :    * unmarking, but it's not possible for the object to be gray here.
     770             :    */
     771             : 
     772           0 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::HTMLStyleElement);
     773           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
     774           0 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
     775             : }
     776             : 
     777             : JS::Handle<JSObject*>
     778           0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
     779             : {
     780             :   /* Get the interface object for this class.  This will create the object as
     781             :      needed. */
     782             : 
     783             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
     784           0 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
     785           0 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
     786           0 :     return nullptr;
     787             :   }
     788             : 
     789             :   /* Check to see whether the interface objects are already installed */
     790           0 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
     791           0 :   if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::HTMLStyleElement)) {
     792           0 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
     793           0 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
     794             :   }
     795             : 
     796             :   /*
     797             :    * The object might _still_ be null, but that's OK.
     798             :    *
     799             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
     800             :    * traced by TraceProtoAndIfaceCache() and its contents are never
     801             :    * changed after they have been set.
     802             :    *
     803             :    * Calling address() avoids the read read barrier that does gray
     804             :    * unmarking, but it's not possible for the object to be gray here.
     805             :    */
     806             : 
     807           0 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::HTMLStyleElement);
     808           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
     809           0 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
     810             : }
     811             : 
     812             : JSObject*
     813           0 : GetConstructorObject(JSContext* aCx)
     814             : {
     815           0 :   return GetConstructorObjectHandle(aCx);
     816             : }
     817             : 
     818             : } // namespace HTMLStyleElementBinding
     819             : 
     820             : 
     821             : 
     822             : } // namespace dom
     823             : } // namespace mozilla

Generated by: LCOV version 1.13