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

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

Generated by: LCOV version 1.13