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

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

Generated by: LCOV version 1.13