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

          Line data    Source code
       1             : /* THIS FILE IS AUTOGENERATED FROM CSSRuleList.webidl BY Codegen.py - DO NOT EDIT */
       2             : 
       3             : #include "CSSRuleListBinding.h"
       4             : #include "WrapperFactory.h"
       5             : #include "mozilla/OwningNonNull.h"
       6             : #include "mozilla/css/Rule.h"
       7             : #include "mozilla/dom/BindingUtils.h"
       8             : #include "mozilla/dom/CSSRuleList.h"
       9             : #include "mozilla/dom/DOMJSClass.h"
      10             : #include "mozilla/dom/DOMJSProxyHandler.h"
      11             : #include "mozilla/dom/NonRefcountedDOMObject.h"
      12             : #include "mozilla/dom/Nullable.h"
      13             : #include "mozilla/dom/PrimitiveConversions.h"
      14             : #include "mozilla/dom/XrayExpandoClass.h"
      15             : 
      16             : namespace mozilla {
      17             : namespace dom {
      18             : 
      19             : namespace CSSRuleListBinding {
      20             : 
      21             : static bool
      22           0 : get_length(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::CSSRuleList* self, JSJitGetterCallArgs args)
      23             : {
      24           0 :   uint32_t result(self->Length());
      25           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
      26           0 :   args.rval().setNumber(result);
      27           0 :   return true;
      28             : }
      29             : 
      30             : static const JSJitInfo length_getterinfo = {
      31             :   { (JSJitGetterOp)get_length },
      32             :   { prototypes::id::CSSRuleList },
      33             :   { PrototypeTraits<prototypes::id::CSSRuleList>::Depth },
      34             :   JSJitInfo::Getter,
      35             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
      36             :   JSVAL_TYPE_DOUBLE,  /* returnType.  Not relevant for setters. */
      37             :   true,  /* isInfallible. False in setters. */
      38             :   false,  /* isMovable.  Not relevant for setters. */
      39             :   false, /* isEliminatable.  Not relevant for setters. */
      40             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
      41             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
      42             :   false,  /* isTypedMethod.  Only relevant for methods. */
      43             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
      44             : };
      45             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
      46             : static_assert(0 < 1, "There is no slot for us");
      47             : 
      48             : static bool
      49           0 : item(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::CSSRuleList* self, const JSJitMethodCallArgs& args)
      50             : {
      51           0 :   if (MOZ_UNLIKELY(args.length() < 1)) {
      52           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "CSSRuleList.item");
      53             :   }
      54             :   uint32_t arg0;
      55           0 :   if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) {
      56           0 :     return false;
      57             :   }
      58           0 :   auto result(StrongOrRawPtr<mozilla::css::Rule>(self->Item(arg0)));
      59           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
      60           0 :   if (!result) {
      61           0 :     args.rval().setNull();
      62           0 :     return true;
      63             :   }
      64           0 :   if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
      65           0 :     MOZ_ASSERT(true || JS_IsExceptionPending(cx));
      66           0 :     return false;
      67             :   }
      68           0 :   return true;
      69             : }
      70             : 
      71             : static const JSJitInfo item_methodinfo = {
      72             :   { (JSJitGetterOp)item },
      73             :   { prototypes::id::CSSRuleList },
      74             :   { PrototypeTraits<prototypes::id::CSSRuleList>::Depth },
      75             :   JSJitInfo::Method,
      76             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
      77             :   JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
      78             :   false,  /* isInfallible. False in setters. */
      79             :   false,  /* isMovable.  Not relevant for setters. */
      80             :   false, /* isEliminatable.  Not relevant for setters. */
      81             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
      82             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
      83             :   false,  /* isTypedMethod.  Only relevant for methods. */
      84             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
      85             : };
      86             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
      87             : static_assert(0 < 1, "There is no slot for us");
      88             : 
      89             : static void
      90           0 : _objectMoved(JSObject* obj, const JSObject* old)
      91             : {
      92           0 :   mozilla::dom::CSSRuleList* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::CSSRuleList>(obj);
      93           0 :   if (self) {
      94           0 :     UpdateWrapper(self, self, obj, old);
      95             :   }
      96           0 : }
      97             : 
      98             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
      99             : #if defined(__clang__)
     100             : #pragma clang diagnostic push
     101             : #pragma clang diagnostic ignored "-Wmissing-braces"
     102             : #endif
     103             : static const JSFunctionSpec sMethods_specs[] = {
     104             :   JS_FNSPEC("item", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&item_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
     105             :   JS_SYM_FNSPEC(iterator, nullptr, nullptr, 0, 0, "ArrayValues"),
     106             :   JS_FS_END
     107             : };
     108             : #if defined(__clang__)
     109             : #pragma clang diagnostic pop
     110             : #endif
     111             : 
     112             : 
     113             : // Can't be const because the pref-enabled boolean needs to be writable
     114             : static Prefable<const JSFunctionSpec> sMethods[] = {
     115             :   { nullptr, &sMethods_specs[0] },
     116             :   { nullptr, nullptr }
     117             : };
     118             : 
     119             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
     120             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
     121             : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
     122             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
     123             : 
     124             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
     125             : #if defined(__clang__)
     126             : #pragma clang diagnostic push
     127             : #pragma clang diagnostic ignored "-Wmissing-braces"
     128             : #endif
     129             : static const JSPropertySpec sAttributes_specs[] = {
     130             :   { "length", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &length_getterinfo, nullptr, nullptr },
     131             :   { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
     132             : };
     133             : #if defined(__clang__)
     134             : #pragma clang diagnostic pop
     135             : #endif
     136             : 
     137             : 
     138             : // Can't be const because the pref-enabled boolean needs to be writable
     139             : static Prefable<const JSPropertySpec> sAttributes[] = {
     140             :   { nullptr, &sAttributes_specs[0] },
     141             :   { nullptr, nullptr }
     142             : };
     143             : 
     144             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
     145             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
     146             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
     147             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
     148             : 
     149             : 
     150             : static uint16_t sNativeProperties_sortedPropertyIndices[3];
     151             : static PropertyInfo sNativeProperties_propertyInfos[3];
     152             : 
     153             : static const NativePropertiesN<2> sNativeProperties = {
     154             :   false, 0,
     155             :   false, 0,
     156             :   true,  0 /* sMethods */,
     157             :   true,  1 /* sAttributes */,
     158             :   false, 0,
     159             :   false, 0,
     160             :   false, 0,
     161             :   -1,
     162             :   3,
     163             :   sNativeProperties_sortedPropertyIndices,
     164             :   {
     165             :     { sMethods, &sNativeProperties_propertyInfos[0] },
     166             :     { sAttributes, &sNativeProperties_propertyInfos[2] }
     167             :   }
     168             : };
     169             : static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
     170             :     "We have a property info count that is oversized");
     171             : 
     172             : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
     173             :   {
     174             :     "Function",
     175             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
     176             :     &sBoringInterfaceObjectClassClassOps,
     177             :     JS_NULL_CLASS_SPEC,
     178             :     JS_NULL_CLASS_EXT,
     179             :     &sInterfaceObjectClassObjectOps
     180             :   },
     181             :   eInterface,
     182             :   true,
     183             :   prototypes::id::CSSRuleList,
     184             :   PrototypeTraits<prototypes::id::CSSRuleList>::Depth,
     185             :   sNativePropertyHooks,
     186             :   "function CSSRuleList() {\n    [native code]\n}",
     187             :   JS::GetRealmFunctionPrototype
     188             : };
     189             : 
     190             : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
     191             :   {
     192             :     "CSSRuleListPrototype",
     193             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
     194             :     JS_NULL_CLASS_OPS,
     195             :     JS_NULL_CLASS_SPEC,
     196             :     JS_NULL_CLASS_EXT,
     197             :     JS_NULL_OBJECT_OPS
     198             :   },
     199             :   eInterfacePrototype,
     200             :   false,
     201             :   prototypes::id::CSSRuleList,
     202             :   PrototypeTraits<prototypes::id::CSSRuleList>::Depth,
     203             :   sNativePropertyHooks,
     204             :   "[object CSSRuleListPrototype]",
     205             :   JS::GetRealmObjectPrototype
     206             : };
     207             : 
     208             : JSObject*
     209           0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
     210             : {
     211           0 :   return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
     212             : }
     213             : 
     214             : static_assert(IsBaseOf<nsISupports, mozilla::dom::CSSRuleList >::value,
     215             :                   "We don't support non-nsISupports native classes for "
     216             :                   "proxy-based bindings yet");
     217             : 
     218             : 
     219             : class DOMProxyHandler : public mozilla::dom::DOMProxyHandler
     220             : {
     221             : public:
     222             :   explicit constexpr DOMProxyHandler()
     223             :   {
     224             :   }
     225             : 
     226             :   virtual bool
     227             :   getOwnPropDescriptor(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool ignoreNamedProps, JS::MutableHandle<JS::PropertyDescriptor> desc) const override;
     228             : 
     229             :   virtual bool
     230             :   defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult& opresult, bool* defined) const override;
     231             : 
     232             :   using mozilla::dom::DOMProxyHandler::defineProperty;
     233             : 
     234             :   virtual bool
     235             :   ownPropNames(JSContext* cx, JS::Handle<JSObject*> proxy, unsigned flags, JS::AutoIdVector& props) const override;
     236             : 
     237             :   virtual bool
     238             :   hasOwn(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool* bp) const override;
     239             : 
     240             :   virtual bool
     241             :   get(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<JS::Value> receiver, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) const override;
     242             : 
     243             :   virtual const char*
     244             :   className(JSContext* cx, JS::Handle<JSObject*> proxy) const override;
     245             : 
     246             :   virtual bool
     247             :   finalizeInBackground(const JS::Value& priv) const override;
     248             : 
     249             :   virtual void
     250             :   finalize(JSFreeOp* fop, JSObject* proxy) const override;
     251             : 
     252             :   static const DOMProxyHandler*
     253             :   getInstance();
     254             : 
     255             :   virtual bool
     256             :   delete_(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::ObjectOpResult& opresult) const override;
     257             : 
     258             :   virtual bool
     259             :   getElements(JSContext* cx, JS::Handle<JSObject*> proxy, uint32_t begin, uint32_t end, js::ElementAdder* adder) const override;
     260             : };
     261             : 
     262             : MOZ_ALWAYS_INLINE bool
     263           0 : IsProxy(JSObject* obj)
     264             : {
     265           0 :   return js::IsProxy(obj) && js::GetProxyHandler(obj) == DOMProxyHandler::getInstance();
     266             : }
     267             : 
     268             : MOZ_ALWAYS_INLINE mozilla::dom::CSSRuleList*
     269           0 : UnwrapProxy(JSObject* obj)
     270             : {
     271           0 :   MOZ_ASSERT(js::IsProxy(obj));
     272           0 :   if (js::GetProxyHandler(obj) != DOMProxyHandler::getInstance()) {
     273           0 :     MOZ_ASSERT(xpc::WrapperFactory::IsXrayWrapper(obj));
     274           0 :     obj = js::UncheckedUnwrap(obj);
     275             :   }
     276           0 :   MOZ_ASSERT(IsProxy(obj));
     277           0 :   return static_cast<mozilla::dom::CSSRuleList*>(js::GetProxyReservedSlot(obj, DOM_OBJECT_SLOT).toPrivate());
     278             : }
     279             : 
     280             : bool
     281           0 : DOMProxyHandler::getOwnPropDescriptor(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool ignoreNamedProps, JS::MutableHandle<JS::PropertyDescriptor> desc) const
     282             : {
     283           0 :   bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy);
     284           0 :   uint32_t index = GetArrayIndexFromId(cx, id);
     285           0 :   if (IsArrayIndex(index)) {
     286           0 :     mozilla::dom::CSSRuleList* self = UnwrapProxy(proxy);
     287           0 :     bool found = false;
     288           0 :     auto result(StrongOrRawPtr<mozilla::css::Rule>(self->IndexedGetter(index, found)));
     289           0 :     MOZ_ASSERT(!JS_IsExceptionPending(cx));
     290             : 
     291           0 :     if (found) {
     292           0 :       if (!result) {
     293           0 :         desc.value().setNull();
     294           0 :         FillPropertyDescriptor(desc, proxy, true);
     295           0 :         return true;
     296             :       }
     297           0 :       if (!GetOrCreateDOMReflector(cx, result, desc.value())) {
     298           0 :         MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     299           0 :         return false;
     300             :       }
     301           0 :       FillPropertyDescriptor(desc, proxy, true);
     302           0 :       return true;
     303             :     }
     304             :   }
     305             : 
     306           0 :   JS::Rooted<JSObject*> expando(cx);
     307           0 :   if (!isXray && (expando = GetExpandoObject(proxy))) {
     308           0 :     if (!JS_GetOwnPropertyDescriptorById(cx, expando, id, desc)) {
     309           0 :       return false;
     310             :     }
     311           0 :     if (desc.object()) {
     312             :       // Pretend the property lives on the wrapper.
     313           0 :       desc.object().set(proxy);
     314           0 :       return true;
     315             :     }
     316             :   }
     317             : 
     318           0 :   desc.object().set(nullptr);
     319           0 :   return true;
     320             : }
     321             : 
     322             : bool
     323           0 : DOMProxyHandler::defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult& opresult, bool* defined) const
     324             : {
     325           0 :   if (IsArrayIndex(GetArrayIndexFromId(cx, id))) {
     326           0 :     *defined = true;
     327           0 :     return opresult.failNoIndexedSetter();
     328             :   }
     329           0 :   return mozilla::dom::DOMProxyHandler::defineProperty(cx, proxy, id, desc, opresult, defined);
     330             : }
     331             : 
     332             : 
     333             : bool
     334           0 : DOMProxyHandler::ownPropNames(JSContext* cx, JS::Handle<JSObject*> proxy, unsigned flags, JS::AutoIdVector& props) const
     335             : {
     336           0 :   bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy);
     337             : 
     338           0 :   uint32_t length = UnwrapProxy(proxy)->Length();
     339           0 :   MOZ_ASSERT(int32_t(length) >= 0);
     340           0 :   for (int32_t i = 0; i < int32_t(length); ++i) {
     341           0 :     if (!props.append(INT_TO_JSID(i))) {
     342           0 :       return false;
     343             :     }
     344             :   }
     345             : 
     346           0 :   JS::Rooted<JSObject*> expando(cx);
     347           0 :   if (!isXray && (expando = DOMProxyHandler::GetExpandoObject(proxy)) &&
     348           0 :       !js::GetPropertyKeys(cx, expando, flags, &props)) {
     349           0 :     return false;
     350             :   }
     351             : 
     352           0 :   return true;
     353             : }
     354             : 
     355             : bool
     356           0 : DOMProxyHandler::hasOwn(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool* bp) const
     357             : {
     358           0 :   MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
     359             :             "Should not have a XrayWrapper here");
     360             : 
     361           0 :   uint32_t index = GetArrayIndexFromId(cx, id);
     362           0 :   if (IsArrayIndex(index)) {
     363           0 :     bool found = false;
     364           0 :     mozilla::dom::CSSRuleList* self = UnwrapProxy(proxy);
     365           0 :     auto result(StrongOrRawPtr<mozilla::css::Rule>(self->IndexedGetter(index, found)));
     366           0 :     MOZ_ASSERT(!JS_IsExceptionPending(cx));
     367             :     (void)result;
     368             : 
     369           0 :     *bp = found;
     370           0 :     return true;
     371             :   }
     372             : 
     373             : 
     374           0 :   JS::Rooted<JSObject*> expando(cx, GetExpandoObject(proxy));
     375           0 :   if (expando) {
     376           0 :     bool b = true;
     377           0 :     bool ok = JS_HasPropertyById(cx, expando, id, &b);
     378           0 :     *bp = !!b;
     379           0 :     if (!ok || *bp) {
     380           0 :       return ok;
     381             :     }
     382             :   }
     383             : 
     384           0 :   *bp = false;
     385           0 :   return true;
     386             : }
     387             : 
     388             : bool
     389           0 : DOMProxyHandler::get(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<JS::Value> receiver, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) const
     390             : {
     391           0 :   MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
     392             :               "Should not have a XrayWrapper here");
     393             : 
     394           0 :   uint32_t index = GetArrayIndexFromId(cx, id);
     395           0 :   if (IsArrayIndex(index)) {
     396           0 :     mozilla::dom::CSSRuleList* self = UnwrapProxy(proxy);
     397           0 :     bool found = false;
     398           0 :     auto result(StrongOrRawPtr<mozilla::css::Rule>(self->IndexedGetter(index, found)));
     399           0 :     MOZ_ASSERT(!JS_IsExceptionPending(cx));
     400             : 
     401           0 :     if (found) {
     402           0 :       if (!result) {
     403           0 :         vp.setNull();
     404           0 :         return true;
     405             :       }
     406           0 :       if (!GetOrCreateDOMReflector(cx, result, vp)) {
     407           0 :         MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     408           0 :         return false;
     409             :       }
     410           0 :       return true;
     411             :     }
     412             :     // Even if we don't have this index, we don't forward the
     413             :     // get on to our expando object.
     414             :   } else {
     415             :     { // Scope for expando
     416           0 :       JS::Rooted<JSObject*> expando(cx, DOMProxyHandler::GetExpandoObject(proxy));
     417           0 :       if (expando) {
     418             :         bool hasProp;
     419           0 :         if (!JS_HasPropertyById(cx, expando, id, &hasProp)) {
     420           0 :           return false;
     421             :         }
     422             : 
     423           0 :         if (hasProp) {
     424             :           // Forward the get to the expando object, but our receiver is whatever our
     425             :           // receiver is.
     426           0 :           return JS_ForwardGetPropertyTo(cx, expando, id, receiver, vp);
     427             :         }
     428             :       }
     429             :     }
     430             :   }
     431             : 
     432             :   bool foundOnPrototype;
     433           0 :   if (!GetPropertyOnPrototype(cx, proxy, receiver, id, &foundOnPrototype, vp)) {
     434           0 :     return false;
     435             :   }
     436             : 
     437           0 :   if (foundOnPrototype) {
     438           0 :     return true;
     439             :   }
     440             : 
     441           0 :   vp.setUndefined();
     442           0 :   return true;
     443             : }
     444             : 
     445             : const char*
     446           0 : DOMProxyHandler::className(JSContext* cx, JS::Handle<JSObject*> proxy) const
     447             : {
     448           0 :   return "CSSRuleList";
     449             : }
     450             : 
     451             : bool
     452           0 : DOMProxyHandler::finalizeInBackground(const JS::Value& priv) const
     453             : {
     454           0 :   return false;
     455             : }
     456             : 
     457             : void
     458           0 : DOMProxyHandler::finalize(JSFreeOp* fop, JSObject* proxy) const
     459             : {
     460           0 :   mozilla::dom::CSSRuleList* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::CSSRuleList>(proxy);
     461           0 :   if (self) {
     462           0 :     ClearWrapper(self, self, proxy);
     463           0 :     AddForDeferredFinalization<mozilla::dom::CSSRuleList>(self);
     464             :   }
     465           0 : }
     466             : 
     467             : const DOMProxyHandler*
     468           0 : DOMProxyHandler::getInstance()
     469             : {
     470             :   static const DOMProxyHandler instance;
     471           0 :   return &instance;
     472             : }
     473             : 
     474             : bool
     475           0 : DOMProxyHandler::delete_(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::ObjectOpResult& opresult) const
     476             : {
     477           0 :   MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
     478             :             "Should not have a XrayWrapper here");
     479             : 
     480           0 :   uint32_t index = GetArrayIndexFromId(cx, id);
     481           0 :   if (IsArrayIndex(index)) {
     482             :     bool deleteSucceeded;
     483           0 :     bool found = false;
     484           0 :     mozilla::dom::CSSRuleList* self = UnwrapProxy(proxy);
     485           0 :     auto result(StrongOrRawPtr<mozilla::css::Rule>(self->IndexedGetter(index, found)));
     486           0 :     MOZ_ASSERT(!JS_IsExceptionPending(cx));
     487             :     (void)result;
     488           0 :     deleteSucceeded = !found;
     489           0 :     return deleteSucceeded ? opresult.succeed() : opresult.failCantDelete();
     490             :   }
     491             : 
     492           0 :   return dom::DOMProxyHandler::delete_(cx, proxy, id, opresult);
     493             : }
     494             : 
     495             : bool
     496           0 : DOMProxyHandler::getElements(JSContext* cx, JS::Handle<JSObject*> proxy, uint32_t begin, uint32_t end, js::ElementAdder* adder) const
     497             : {
     498           0 :   JS::Rooted<JS::Value> temp(cx);
     499           0 :   MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
     500             :              "Should not have a XrayWrapper here");
     501             : 
     502           0 :   mozilla::dom::CSSRuleList* self = UnwrapProxy(proxy);
     503           0 :   uint32_t length = self->Length();
     504             :   // Compute the end of the indices we'll get ourselves
     505           0 :   uint32_t ourEnd = std::max(begin, std::min(end, length));
     506             : 
     507           0 :   for (uint32_t index = begin; index < ourEnd; ++index) {
     508           0 :     bool found = false;
     509           0 :     auto result(StrongOrRawPtr<mozilla::css::Rule>(self->IndexedGetter(index, found)));
     510           0 :     MOZ_ASSERT(!JS_IsExceptionPending(cx));
     511             : 
     512           0 :     MOZ_ASSERT(found);
     513           0 :     if (!result) {
     514           0 :       temp.setNull();
     515           0 :       if (!adder->append(cx, temp)) return false;
     516           0 :       continue;
     517             :     }
     518           0 :     if (!GetOrCreateDOMReflector(cx, result, &temp)) {
     519           0 :       MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     520           0 :       return false;
     521             :     }
     522           0 :     if (!adder->append(cx, temp)) return false;
     523           0 :     continue;
     524             :   }
     525             : 
     526           0 :   if (end > ourEnd) {
     527           0 :     JS::Rooted<JSObject*> proto(cx);
     528           0 :     if (!js::GetObjectProto(cx, proxy, &proto)) {
     529           0 :       return false;
     530             :     }
     531           0 :     return js::GetElementsWithAdder(cx, proto, proxy, ourEnd, end, adder);
     532             :   }
     533             : 
     534           0 :   return true;
     535             : }
     536             : 
     537             : static const js::ClassExtension sClassExtension = PROXY_MAKE_EXT(
     538             :     _objectMoved
     539             : );
     540             : 
     541             : static const DOMJSClass sClass = {
     542             :   PROXY_CLASS_WITH_EXT("CSSRuleList",
     543             :                        JSCLASS_IS_DOMJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(1),
     544             :                        &sClassExtension),
     545             :   { prototypes::id::CSSRuleList, 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 },
     546             :   IsBaseOf<nsISupports, mozilla::dom::CSSRuleList >::value,
     547             :   sNativePropertyHooks,
     548             :   FindAssociatedGlobalForNative<mozilla::dom::CSSRuleList>::Get,
     549             :   GetProtoObjectHandle,
     550             :   GetCCParticipant<mozilla::dom::CSSRuleList>::Get()
     551             : };
     552             : 
     553             : bool
     554           0 : Wrap(JSContext* aCx, mozilla::dom::CSSRuleList* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
     555             : {
     556             :   MOZ_ASSERT(static_cast<mozilla::dom::CSSRuleList*>(aObject) ==
     557             :              reinterpret_cast<mozilla::dom::CSSRuleList*>(aObject),
     558             :              "Multiple inheritance for mozilla::dom::CSSRuleList is broken.");
     559           0 :   MOZ_ASSERT(ToSupportsIsCorrect(aObject));
     560           0 :   MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
     561           0 :   MOZ_ASSERT(!aCache->GetWrapper(),
     562             :              "You should probably not be using Wrap() directly; use "
     563             :              "GetOrCreateDOMReflector instead");
     564             : 
     565           0 :   MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
     566             :              "nsISupports must be on our primary inheritance chain");
     567             : 
     568           0 :   JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
     569           0 :   if (!global) {
     570           0 :     return false;
     571             :   }
     572           0 :   MOZ_ASSERT(JS_IsGlobalObject(global));
     573           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(global));
     574             : 
     575             :   // That might have ended up wrapping us already, due to the wonders
     576             :   // of XBL.  Check for that, and bail out as needed.
     577           0 :   aReflector.set(aCache->GetWrapper());
     578           0 :   if (aReflector) {
     579             : #ifdef DEBUG
     580           0 :     binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
     581             : #endif // DEBUG
     582           0 :     return true;
     583             :   }
     584             : 
     585           0 :   JSAutoCompartment ac(aCx, global);
     586           0 :   JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
     587           0 :   if (!canonicalProto) {
     588           0 :     return false;
     589             :   }
     590           0 :   JS::Rooted<JSObject*> proto(aCx);
     591           0 :   if (aGivenProto) {
     592           0 :     proto = aGivenProto;
     593             :     // Unfortunately, while aGivenProto was in the compartment of aCx
     594             :     // coming in, we changed compartments to that of "parent" so may need
     595             :     // to wrap the proto here.
     596           0 :     if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
     597           0 :       if (!JS_WrapObject(aCx, &proto)) {
     598           0 :         return false;
     599             :       }
     600             :     }
     601             :   } else {
     602           0 :     proto = canonicalProto;
     603             :   }
     604             : 
     605           0 :   BindingJSObjectCreator<mozilla::dom::CSSRuleList> creator(aCx);
     606           0 :   JS::Rooted<JS::Value> expandoValue(aCx, JS::UndefinedValue());
     607           0 :   creator.CreateProxyObject(aCx, &sClass.mBase, DOMProxyHandler::getInstance(),
     608           0 :                             proto, aObject, expandoValue, aReflector);
     609           0 :   if (!aReflector) {
     610           0 :     return false;
     611             :   }
     612             : 
     613             : 
     614           0 :   aCache->SetWrapper(aReflector);
     615           0 :   creator.InitializationSucceeded();
     616             : 
     617           0 :   MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
     618             :              aCache->GetWrapperPreserveColor() == aReflector);
     619             :   // If proto != canonicalProto, we have to preserve our wrapper;
     620             :   // otherwise we won't be able to properly recreate it later, since
     621             :   // we won't know what proto to use.  Note that we don't check
     622             :   // aGivenProto here, since it's entirely possible (and even
     623             :   // somewhat common) to have a non-null aGivenProto which is the
     624             :   // same as canonicalProto.
     625           0 :   if (proto != canonicalProto) {
     626           0 :     PreserveWrapper(aObject);
     627             :   }
     628             : 
     629           0 :   return true;
     630             : }
     631             : 
     632             : static bool
     633           0 : ResolveOwnProperty(JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::MutableHandle<JS::PropertyDescriptor> desc)
     634             : {
     635           0 :   return js::GetProxyHandler(obj)->getOwnPropertyDescriptor(cx, wrapper, id, desc);
     636             : }
     637             : 
     638             : static bool
     639           0 : EnumerateOwnProperties(JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> obj, JS::AutoIdVector& props)
     640             : {
     641           0 :   return js::GetProxyHandler(obj)->ownPropertyKeys(cx, wrapper, props);
     642             : }
     643             : 
     644             : const NativePropertyHooks sNativePropertyHooks[] = { {
     645             :   ResolveOwnProperty,
     646             :   EnumerateOwnProperties,
     647             :   nullptr,
     648             :   { sNativeProperties.Upcast(), nullptr },
     649             :   prototypes::id::CSSRuleList,
     650             :   constructors::id::CSSRuleList,
     651             :   nullptr,
     652             :   &DefaultXrayExpandoObjectClass
     653             : } };
     654             : 
     655             : void
     656           0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
     657             : {
     658           0 :   JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
     659           0 :   if (!parentProto) {
     660           0 :     return;
     661             :   }
     662             : 
     663           0 :   JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
     664           0 :   if (!constructorProto) {
     665           0 :     return;
     666             :   }
     667             : 
     668             :   static bool sIdsInited = false;
     669           0 :   if (!sIdsInited && NS_IsMainThread()) {
     670           0 :     if (!InitIds(aCx, sNativeProperties.Upcast())) {
     671           0 :       return;
     672             :     }
     673           0 :     sIdsInited = true;
     674             :   }
     675             : 
     676           0 :   JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::CSSRuleList);
     677           0 :   JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::CSSRuleList);
     678           0 :   dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
     679             :                               &sPrototypeClass.mBase, protoCache,
     680             :                               constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
     681             :                               interfaceCache,
     682             :                               sNativeProperties.Upcast(),
     683             :                               nullptr,
     684             :                               "CSSRuleList", aDefineOnGlobal,
     685             :                               nullptr,
     686           0 :                               false);
     687             : }
     688             : 
     689             : JS::Handle<JSObject*>
     690           0 : GetProtoObjectHandle(JSContext* aCx)
     691             : {
     692             :   /* Get the interface prototype object for this class.  This will create the
     693             :      object as needed. */
     694           0 :   bool aDefineOnGlobal = true;
     695             : 
     696             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
     697           0 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
     698           0 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
     699           0 :     return nullptr;
     700             :   }
     701             : 
     702             :   /* Check to see whether the interface objects are already installed */
     703           0 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
     704           0 :   if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::CSSRuleList)) {
     705           0 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
     706           0 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
     707             :   }
     708             : 
     709             :   /*
     710             :    * The object might _still_ be null, but that's OK.
     711             :    *
     712             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
     713             :    * traced by TraceProtoAndIfaceCache() and its contents are never
     714             :    * changed after they have been set.
     715             :    *
     716             :    * Calling address() avoids the read read barrier that does gray
     717             :    * unmarking, but it's not possible for the object to be gray here.
     718             :    */
     719             : 
     720           0 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::CSSRuleList);
     721           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
     722           0 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
     723             : }
     724             : 
     725             : JS::Handle<JSObject*>
     726           0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
     727             : {
     728             :   /* Get the interface object for this class.  This will create the object as
     729             :      needed. */
     730             : 
     731             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
     732           0 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
     733           0 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
     734           0 :     return nullptr;
     735             :   }
     736             : 
     737             :   /* Check to see whether the interface objects are already installed */
     738           0 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
     739           0 :   if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::CSSRuleList)) {
     740           0 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
     741           0 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
     742             :   }
     743             : 
     744             :   /*
     745             :    * The object might _still_ be null, but that's OK.
     746             :    *
     747             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
     748             :    * traced by TraceProtoAndIfaceCache() and its contents are never
     749             :    * changed after they have been set.
     750             :    *
     751             :    * Calling address() avoids the read read barrier that does gray
     752             :    * unmarking, but it's not possible for the object to be gray here.
     753             :    */
     754             : 
     755           0 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::CSSRuleList);
     756           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
     757           0 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
     758             : }
     759             : 
     760             : JSObject*
     761           0 : GetConstructorObject(JSContext* aCx)
     762             : {
     763           0 :   return GetConstructorObjectHandle(aCx);
     764             : }
     765             : 
     766             : } // namespace CSSRuleListBinding
     767             : 
     768             : 
     769             : 
     770             : } // namespace dom
     771             : } // namespace mozilla

Generated by: LCOV version 1.13