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

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

Generated by: LCOV version 1.13