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

          Line data    Source code
       1             : /* THIS FILE IS AUTOGENERATED FROM PerformanceObserver.webidl BY Codegen.py - DO NOT EDIT */
       2             : 
       3             : #include "AtomList.h"
       4             : #include "Performance.h"
       5             : #include "PerformanceObserverBinding.h"
       6             : #include "WrapperFactory.h"
       7             : #include "mozilla/OwningNonNull.h"
       8             : #include "mozilla/dom/BindingUtils.h"
       9             : #include "mozilla/dom/DOMJSClass.h"
      10             : #include "mozilla/dom/NonRefcountedDOMObject.h"
      11             : #include "mozilla/dom/PerformanceObserver.h"
      12             : #include "mozilla/dom/PerformanceObserverEntryList.h"
      13             : #include "mozilla/dom/ScriptSettings.h"
      14             : #include "mozilla/dom/SimpleGlobalObject.h"
      15             : #include "mozilla/dom/XrayExpandoClass.h"
      16             : 
      17             : namespace mozilla {
      18             : namespace dom {
      19             : 
      20             : 
      21           0 : PerformanceObserverInit::PerformanceObserverInit()
      22             : {
      23             :   // Safe to pass a null context if we pass a null value
      24           0 :   Init(nullptr, JS::NullHandleValue);
      25           0 : }
      26             : 
      27             : 
      28             : 
      29             : bool
      30           0 : PerformanceObserverInit::InitIds(JSContext* cx, PerformanceObserverInitAtoms* atomsCache)
      31             : {
      32           0 :   MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
      33             : 
      34             :   // Initialize these in reverse order so that any failure leaves the first one
      35             :   // uninitialized.
      36           0 :   if (!atomsCache->entryTypes_id.init(cx, "entryTypes")) {
      37           0 :     return false;
      38             :   }
      39           0 :   return true;
      40             : }
      41             : 
      42             : bool
      43           0 : PerformanceObserverInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
      44             : {
      45             :   // Passing a null JSContext is OK only if we're initing from null,
      46             :   // Since in that case we will not have to do any property gets
      47             :   // Also evaluate isNullOrUndefined in order to avoid false-positive
      48             :   // checkers by static analysis tools
      49           0 :   MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
      50           0 :   PerformanceObserverInitAtoms* atomsCache = nullptr;
      51           0 :   if (cx) {
      52           0 :     atomsCache = GetAtomCache<PerformanceObserverInitAtoms>(cx);
      53           0 :     if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
      54           0 :       return false;
      55             :     }
      56             :   }
      57             : 
      58           0 :   if (!IsConvertibleToDictionary(val)) {
      59           0 :     return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
      60             :   }
      61             : 
      62           0 :   bool isNull = val.isNullOrUndefined();
      63             :   // We only need these if !isNull, in which case we have |cx|.
      64           0 :   Maybe<JS::Rooted<JSObject *> > object;
      65           0 :   Maybe<JS::Rooted<JS::Value> > temp;
      66           0 :   if (!isNull) {
      67           0 :     MOZ_ASSERT(cx);
      68           0 :     object.emplace(cx, &val.toObject());
      69           0 :     temp.emplace(cx);
      70             :   }
      71           0 :   if (!isNull) {
      72           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->entryTypes_id, temp.ptr())) {
      73           0 :       return false;
      74             :     }
      75             :   }
      76           0 :   if (!isNull && !temp->isUndefined()) {
      77           0 :     if (temp.ref().isObject()) {
      78           0 :       JS::ForOfIterator iter(cx);
      79           0 :       if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
      80           0 :         return false;
      81             :       }
      82           0 :       if (!iter.valueIsIterable()) {
      83           0 :         ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'entryTypes' member of PerformanceObserverInit");
      84           0 :         return false;
      85             :       }
      86           0 :       Sequence<nsString> &arr = mEntryTypes;
      87           0 :       JS::Rooted<JS::Value> temp(cx);
      88             :       while (true) {
      89             :         bool done;
      90           0 :         if (!iter.next(&temp, &done)) {
      91           0 :           return false;
      92             :         }
      93           0 :         if (done) {
      94           0 :           break;
      95             :         }
      96           0 :         nsString* slotPtr = arr.AppendElement(mozilla::fallible);
      97           0 :         if (!slotPtr) {
      98           0 :           JS_ReportOutOfMemory(cx);
      99           0 :           return false;
     100             :         }
     101           0 :         nsString& slot = *slotPtr;
     102           0 :         if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
     103           0 :           return false;
     104             :         }
     105           0 :       }
     106             :     } else {
     107           0 :       ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'entryTypes' member of PerformanceObserverInit");
     108           0 :       return false;
     109             :     }
     110           0 :     mIsAnyMemberPresent = true;
     111           0 :   } else if (cx) {
     112             :     // Don't error out if we have no cx.  In that
     113             :     // situation the caller is default-constructing us and we'll
     114             :     // just assume they know what they're doing.
     115           0 :     return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER,
     116           0 :                              "'entryTypes' member of PerformanceObserverInit");
     117             :   }
     118           0 :   return true;
     119             : }
     120             : 
     121             : bool
     122           0 : PerformanceObserverInit::Init(const nsAString& aJSON)
     123             : {
     124           0 :   AutoJSAPI jsapi;
     125           0 :   JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
     126           0 :   if (!cleanGlobal) {
     127           0 :     return false;
     128             :   }
     129           0 :   if (!jsapi.Init(cleanGlobal)) {
     130           0 :     return false;
     131             :   }
     132           0 :   JSContext* cx = jsapi.cx();
     133           0 :   JS::Rooted<JS::Value> json(cx);
     134           0 :   bool ok = ParseJSON(cx, aJSON, &json);
     135           0 :   NS_ENSURE_TRUE(ok, false);
     136           0 :   return Init(cx, json);
     137             : }
     138             : 
     139             : bool
     140           0 : PerformanceObserverInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
     141             : {
     142           0 :   PerformanceObserverInitAtoms* atomsCache = GetAtomCache<PerformanceObserverInitAtoms>(cx);
     143           0 :   if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
     144           0 :     return false;
     145             :   }
     146             : 
     147           0 :   JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
     148           0 :   if (!obj) {
     149           0 :     return false;
     150             :   }
     151           0 :   rval.set(JS::ObjectValue(*obj));
     152             : 
     153             :   do {
     154             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     155           0 :     JS::Rooted<JS::Value> temp(cx);
     156           0 :     Sequence<nsString> const & currentValue = mEntryTypes;
     157             : 
     158           0 :     uint32_t length = currentValue.Length();
     159           0 :     JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
     160           0 :     if (!returnArray) {
     161           0 :       return false;
     162             :     }
     163             :     // Scope for 'tmp'
     164             :     {
     165           0 :       JS::Rooted<JS::Value> tmp(cx);
     166           0 :       for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
     167             :         // Control block to let us common up the JS_DefineElement calls when there
     168             :         // are different ways to succeed at wrapping the object.
     169             :         do {
     170           0 :           if (!xpc::NonVoidStringToJsval(cx, currentValue[sequenceIdx0], &tmp)) {
     171           0 :             return false;
     172             :           }
     173           0 :           break;
     174             :         } while (0);
     175           0 :         if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
     176             :                               JSPROP_ENUMERATE)) {
     177           0 :           return false;
     178             :         }
     179             :       }
     180             :     }
     181           0 :     temp.setObject(*returnArray);
     182           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->entryTypes_id, temp, JSPROP_ENUMERATE)) {
     183           0 :       return false;
     184             :     }
     185           0 :     break;
     186             :   } while(0);
     187             : 
     188           0 :   return true;
     189             : }
     190             : 
     191             : bool
     192           0 : PerformanceObserverInit::ToJSON(nsAString& aJSON) const
     193             : {
     194           0 :   AutoJSAPI jsapi;
     195           0 :   jsapi.Init();
     196           0 :   JSContext *cx = jsapi.cx();
     197             :   // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
     198             :   // because we'll only be creating objects, in ways that have no
     199             :   // side-effects, followed by a call to JS::ToJSONMaybeSafely,
     200             :   // which likewise guarantees no side-effects for the sorts of
     201             :   // things we will pass it.
     202           0 :   JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
     203           0 :   JS::Rooted<JS::Value> val(cx);
     204           0 :   if (!ToObjectInternal(cx, &val)) {
     205           0 :     return false;
     206             :   }
     207           0 :   JS::Rooted<JSObject*> obj(cx, &val.toObject());
     208           0 :   return StringifyToJSON(cx, obj, aJSON);
     209             : }
     210             : 
     211             : void
     212           0 : PerformanceObserverInit::TraceDictionary(JSTracer* trc)
     213             : {
     214           0 : }
     215             : 
     216             : PerformanceObserverInit&
     217           0 : PerformanceObserverInit::operator=(const PerformanceObserverInit& aOther)
     218             : {
     219           0 :   mEntryTypes = aOther.mEntryTypes;
     220           0 :   return *this;
     221             : }
     222             : 
     223             : namespace binding_detail {
     224             : } // namespace binding_detail
     225             : 
     226             : 
     227             : void
     228           0 : PerformanceObserverCallback::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, PerformanceObserverEntryList& entries, PerformanceObserver& observer, ErrorResult& aRv)
     229             : {
     230           0 :   JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
     231           0 :   JS::AutoValueVector argv(cx);
     232           0 :   if (!argv.resize(2)) {
     233           0 :     aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
     234           0 :     return;
     235             :   }
     236           0 :   unsigned argc = 2;
     237             : 
     238             :   do {
     239           0 :     if (!GetOrCreateDOMReflector(cx, observer, argv[1])) {
     240           0 :       MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     241           0 :       aRv.Throw(NS_ERROR_UNEXPECTED);
     242           0 :       return;
     243             :     }
     244           0 :     break;
     245             :   } while (0);
     246             : 
     247             :   do {
     248           0 :     if (!GetOrCreateDOMReflector(cx, entries, argv[0])) {
     249           0 :       MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     250           0 :       aRv.Throw(NS_ERROR_UNEXPECTED);
     251           0 :       return;
     252             :     }
     253           0 :     break;
     254             :   } while (0);
     255             : 
     256           0 :   JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback));
     257           0 :   if (!JS::Call(cx, aThisVal, callable,
     258           0 :                 JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
     259           0 :     aRv.NoteJSContextException(cx);
     260           0 :     return;
     261             :   }
     262             : }
     263             : 
     264             : 
     265             : 
     266             : namespace binding_detail {
     267             : } // namespace binding_detail
     268             : 
     269             : 
     270             : namespace PerformanceObserverBinding {
     271             : 
     272             : static bool
     273           0 : observe(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PerformanceObserver* self, const JSJitMethodCallArgs& args)
     274             : {
     275           0 :   if (MOZ_UNLIKELY(args.length() < 1)) {
     276           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "PerformanceObserver.observe");
     277             :   }
     278           0 :   binding_detail::FastPerformanceObserverInit arg0;
     279           0 :   if (!arg0.Init(cx, args[0],  "Argument 1 of PerformanceObserver.observe", false)) {
     280           0 :     return false;
     281             :   }
     282           0 :   binding_detail::FastErrorResult rv;
     283           0 :   self->Observe(Constify(arg0), rv);
     284           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     285           0 :     return false;
     286             :   }
     287           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     288           0 :   args.rval().setUndefined();
     289           0 :   return true;
     290             : }
     291             : 
     292             : static const JSJitInfo observe_methodinfo = {
     293             :   { (JSJitGetterOp)observe },
     294             :   { prototypes::id::PerformanceObserver },
     295             :   { PrototypeTraits<prototypes::id::PerformanceObserver>::Depth },
     296             :   JSJitInfo::Method,
     297             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     298             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
     299             :   false,  /* isInfallible. False in setters. */
     300             :   false,  /* isMovable.  Not relevant for setters. */
     301             :   false, /* isEliminatable.  Not relevant for setters. */
     302             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     303             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     304             :   false,  /* isTypedMethod.  Only relevant for methods. */
     305             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     306             : };
     307             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     308             : static_assert(0 < 1, "There is no slot for us");
     309             : 
     310             : static bool
     311           0 : disconnect(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PerformanceObserver* self, const JSJitMethodCallArgs& args)
     312             : {
     313           0 :   self->Disconnect();
     314           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     315           0 :   args.rval().setUndefined();
     316           0 :   return true;
     317             : }
     318             : 
     319             : static const JSJitInfo disconnect_methodinfo = {
     320             :   { (JSJitGetterOp)disconnect },
     321             :   { prototypes::id::PerformanceObserver },
     322             :   { PrototypeTraits<prototypes::id::PerformanceObserver>::Depth },
     323             :   JSJitInfo::Method,
     324             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     325             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
     326             :   true,  /* isInfallible. False in setters. */
     327             :   false,  /* isMovable.  Not relevant for setters. */
     328             :   false, /* isEliminatable.  Not relevant for setters. */
     329             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     330             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     331             :   false,  /* isTypedMethod.  Only relevant for methods. */
     332             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     333             : };
     334             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     335             : static_assert(0 < 1, "There is no slot for us");
     336             : 
     337             : static bool
     338           0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
     339             : {
     340           0 :   mozilla::dom::PerformanceObserver* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PerformanceObserver>(obj);
     341             :   // We don't want to preserve if we don't have a wrapper, and we
     342             :   // obviously can't preserve if we're not initialized.
     343           0 :   if (self && self->GetWrapperPreserveColor()) {
     344           0 :     PreserveWrapper(self);
     345             :   }
     346           0 :   return true;
     347             : }
     348             : 
     349             : static void
     350           0 : _finalize(js::FreeOp* fop, JSObject* obj)
     351             : {
     352           0 :   mozilla::dom::PerformanceObserver* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PerformanceObserver>(obj);
     353           0 :   if (self) {
     354           0 :     ClearWrapper(self, self, obj);
     355           0 :     AddForDeferredFinalization<mozilla::dom::PerformanceObserver>(self);
     356             :   }
     357           0 : }
     358             : 
     359             : static void
     360           0 : _objectMoved(JSObject* obj, const JSObject* old)
     361             : {
     362           0 :   mozilla::dom::PerformanceObserver* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PerformanceObserver>(obj);
     363           0 :   if (self) {
     364           0 :     UpdateWrapper(self, self, obj, old);
     365             :   }
     366           0 : }
     367             : 
     368             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
     369             : #if defined(__clang__)
     370             : #pragma clang diagnostic push
     371             : #pragma clang diagnostic ignored "-Wmissing-braces"
     372             : #endif
     373             : static const JSFunctionSpec sMethods_specs[] = {
     374             :   JS_FNSPEC("observe", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&observe_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
     375             :   JS_FNSPEC("disconnect", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&disconnect_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
     376             :   JS_FS_END
     377             : };
     378             : #if defined(__clang__)
     379             : #pragma clang diagnostic pop
     380             : #endif
     381             : 
     382             : 
     383             : // Can't be const because the pref-enabled boolean needs to be writable
     384             : static Prefable<const JSFunctionSpec> sMethods[] = {
     385             :   { nullptr, &sMethods_specs[0] },
     386             :   { nullptr, nullptr }
     387             : };
     388             : 
     389             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
     390             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
     391             : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
     392             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
     393             : 
     394             : 
     395             : static uint16_t sNativeProperties_sortedPropertyIndices[2];
     396             : static PropertyInfo sNativeProperties_propertyInfos[2];
     397             : 
     398             : static const NativePropertiesN<1> sNativeProperties = {
     399             :   false, 0,
     400             :   false, 0,
     401             :   true,  0 /* sMethods */,
     402             :   false, 0,
     403             :   false, 0,
     404             :   false, 0,
     405             :   false, 0,
     406             :   -1,
     407             :   2,
     408             :   sNativeProperties_sortedPropertyIndices,
     409             :   {
     410             :     { sMethods, &sNativeProperties_propertyInfos[0] }
     411             :   }
     412             : };
     413             : static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
     414             :     "We have a property info count that is oversized");
     415             : 
     416             : static bool
     417           0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
     418             : {
     419           0 :   JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
     420           0 :   JS::Rooted<JSObject*> obj(cx, &args.callee());
     421           0 :   if (!args.isConstructing()) {
     422             :     // XXXbz wish I could get the name from the callee instead of
     423             :     // Adding more relocations
     424           0 :     return ThrowConstructorWithoutNew(cx, "PerformanceObserver");
     425             :   }
     426             : 
     427           0 :   GlobalObject global(cx, obj);
     428           0 :   if (global.Failed()) {
     429           0 :     return false;
     430             :   }
     431             : 
     432           0 :   JS::Rooted<JSObject*> desiredProto(cx);
     433           0 :   if (!GetDesiredProto(cx, args, &desiredProto)) {
     434           0 :     return false;
     435             :   }
     436             : 
     437           0 :   if (MOZ_UNLIKELY(args.length() < 1)) {
     438           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "PerformanceObserver");
     439             :   }
     440           0 :   bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
     441           0 :   RootedCallback<OwningNonNull<binding_detail::FastPerformanceObserverCallback>> arg0(cx);
     442           0 :   if (args[0].isObject()) {
     443           0 :     if (JS::IsCallable(&args[0].toObject())) {
     444             :     { // scope for tempRoot
     445           0 :       JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
     446           0 :       arg0 = new binding_detail::FastPerformanceObserverCallback(tempRoot);
     447             :     }
     448             :     } else {
     449           0 :       ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 1 of PerformanceObserver.constructor");
     450           0 :       return false;
     451             :     }
     452             :   } else {
     453           0 :     ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of PerformanceObserver.constructor");
     454           0 :     return false;
     455             :   }
     456           0 :   Maybe<JSAutoCompartment> ac;
     457           0 :   if (objIsXray) {
     458           0 :     obj = js::CheckedUnwrap(obj);
     459           0 :     if (!obj) {
     460           0 :       return false;
     461             :     }
     462           0 :     ac.emplace(cx, obj);
     463           0 :     if (!JS_WrapObject(cx, &desiredProto)) {
     464           0 :       return false;
     465             :     }
     466             :   }
     467           0 :   binding_detail::FastErrorResult rv;
     468           0 :   auto result(StrongOrRawPtr<mozilla::dom::PerformanceObserver>(mozilla::dom::PerformanceObserver::Constructor(global, NonNullHelper(arg0), rv)));
     469           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     470           0 :     return false;
     471             :   }
     472           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     473             :   static_assert(!IsPointer<decltype(result)>::value,
     474             :                 "NewObject implies that we need to keep the object alive with a strong reference.");
     475           0 :   if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
     476           0 :     MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     477           0 :     return false;
     478             :   }
     479           0 :   return true;
     480             : }
     481             : 
     482             : static const js::ClassOps sInterfaceObjectClassOps = {
     483             :     nullptr,               /* addProperty */
     484             :     nullptr,               /* delProperty */
     485             :     nullptr,               /* getProperty */
     486             :     nullptr,               /* setProperty */
     487             :     nullptr,               /* enumerate */
     488             :     nullptr,               /* newEnumerate */
     489             :     nullptr,               /* resolve */
     490             :     nullptr,               /* mayResolve */
     491             :     nullptr,               /* finalize */
     492             :     _constructor, /* call */
     493             :     nullptr,               /* hasInstance */
     494             :     _constructor, /* construct */
     495             :     nullptr,               /* trace */
     496             : };
     497             : 
     498             : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
     499             :   {
     500             :     "Function",
     501             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
     502             :     &sInterfaceObjectClassOps,
     503             :     JS_NULL_CLASS_SPEC,
     504             :     JS_NULL_CLASS_EXT,
     505             :     &sInterfaceObjectClassObjectOps
     506             :   },
     507             :   eInterface,
     508             :   true,
     509             :   prototypes::id::PerformanceObserver,
     510             :   PrototypeTraits<prototypes::id::PerformanceObserver>::Depth,
     511             :   sNativePropertyHooks,
     512             :   "function PerformanceObserver() {\n    [native code]\n}",
     513             :   JS::GetRealmFunctionPrototype
     514             : };
     515             : 
     516             : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
     517             :   {
     518             :     "PerformanceObserverPrototype",
     519             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
     520             :     JS_NULL_CLASS_OPS,
     521             :     JS_NULL_CLASS_SPEC,
     522             :     JS_NULL_CLASS_EXT,
     523             :     JS_NULL_OBJECT_OPS
     524             :   },
     525             :   eInterfacePrototype,
     526             :   false,
     527             :   prototypes::id::PerformanceObserver,
     528             :   PrototypeTraits<prototypes::id::PerformanceObserver>::Depth,
     529             :   sNativePropertyHooks,
     530             :   "[object PerformanceObserverPrototype]",
     531             :   JS::GetRealmObjectPrototype
     532             : };
     533             : 
     534             : bool
     535           1 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
     536             : {
     537           1 :   return Performance::IsObserverEnabled(aCx, aObj);
     538             : }
     539             : 
     540             : JSObject*
     541           0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
     542             : {
     543           0 :   return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
     544             : }
     545             : 
     546             : static const js::ClassOps sClassOps = {
     547             :   _addProperty, /* addProperty */
     548             :   nullptr,               /* delProperty */
     549             :   nullptr,               /* getProperty */
     550             :   nullptr,               /* setProperty */
     551             :   nullptr,               /* enumerate */
     552             :   nullptr, /* newEnumerate */
     553             :   nullptr, /* resolve */
     554             :   nullptr, /* mayResolve */
     555             :   _finalize, /* finalize */
     556             :   nullptr, /* call */
     557             :   nullptr,               /* hasInstance */
     558             :   nullptr,               /* construct */
     559             :   nullptr, /* trace */
     560             : };
     561             : 
     562             : static const js::ClassExtension sClassExtension = {
     563             :   nullptr, /* weakmapKeyDelegateOp */
     564             :   _objectMoved /* objectMovedOp */
     565             : };
     566             : 
     567             : static const DOMJSClass sClass = {
     568             :   { "PerformanceObserver",
     569             :     JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
     570             :     &sClassOps,
     571             :     JS_NULL_CLASS_SPEC,
     572             :     &sClassExtension,
     573             :     JS_NULL_OBJECT_OPS
     574             :   },
     575             :   { prototypes::id::PerformanceObserver, 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 },
     576             :   IsBaseOf<nsISupports, mozilla::dom::PerformanceObserver >::value,
     577             :   sNativePropertyHooks,
     578             :   FindAssociatedGlobalForNative<mozilla::dom::PerformanceObserver>::Get,
     579             :   GetProtoObjectHandle,
     580             :   GetCCParticipant<mozilla::dom::PerformanceObserver>::Get()
     581             : };
     582             : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
     583             :               "Must have the right minimal number of reserved slots.");
     584             : static_assert(1 >= 1,
     585             :               "Must have enough reserved slots.");
     586             : 
     587             : const JSClass*
     588           0 : GetJSClass()
     589             : {
     590           0 :   return sClass.ToJSClass();
     591             : }
     592             : 
     593             : bool
     594           0 : Wrap(JSContext* aCx, mozilla::dom::PerformanceObserver* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
     595             : {
     596             :   MOZ_ASSERT(static_cast<mozilla::dom::PerformanceObserver*>(aObject) ==
     597             :              reinterpret_cast<mozilla::dom::PerformanceObserver*>(aObject),
     598             :              "Multiple inheritance for mozilla::dom::PerformanceObserver is broken.");
     599           0 :   MOZ_ASSERT(ToSupportsIsCorrect(aObject));
     600           0 :   MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
     601           0 :   MOZ_ASSERT(!aCache->GetWrapper(),
     602             :              "You should probably not be using Wrap() directly; use "
     603             :              "GetOrCreateDOMReflector instead");
     604             : 
     605           0 :   MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
     606             :              "nsISupports must be on our primary inheritance chain");
     607             : 
     608           0 :   JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
     609           0 :   if (!global) {
     610           0 :     return false;
     611             :   }
     612           0 :   MOZ_ASSERT(JS_IsGlobalObject(global));
     613           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(global));
     614             : 
     615             :   // That might have ended up wrapping us already, due to the wonders
     616             :   // of XBL.  Check for that, and bail out as needed.
     617           0 :   aReflector.set(aCache->GetWrapper());
     618           0 :   if (aReflector) {
     619             : #ifdef DEBUG
     620           0 :     binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
     621             : #endif // DEBUG
     622           0 :     return true;
     623             :   }
     624             : 
     625           0 :   JSAutoCompartment ac(aCx, global);
     626           0 :   JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
     627           0 :   if (!canonicalProto) {
     628           0 :     return false;
     629             :   }
     630           0 :   JS::Rooted<JSObject*> proto(aCx);
     631           0 :   if (aGivenProto) {
     632           0 :     proto = aGivenProto;
     633             :     // Unfortunately, while aGivenProto was in the compartment of aCx
     634             :     // coming in, we changed compartments to that of "parent" so may need
     635             :     // to wrap the proto here.
     636           0 :     if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
     637           0 :       if (!JS_WrapObject(aCx, &proto)) {
     638           0 :         return false;
     639             :       }
     640             :     }
     641             :   } else {
     642           0 :     proto = canonicalProto;
     643             :   }
     644             : 
     645           0 :   BindingJSObjectCreator<mozilla::dom::PerformanceObserver> creator(aCx);
     646           0 :   creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
     647           0 :   if (!aReflector) {
     648           0 :     return false;
     649             :   }
     650             : 
     651           0 :   aCache->SetWrapper(aReflector);
     652           0 :   creator.InitializationSucceeded();
     653             : 
     654           0 :   MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
     655             :              aCache->GetWrapperPreserveColor() == aReflector);
     656             :   // If proto != canonicalProto, we have to preserve our wrapper;
     657             :   // otherwise we won't be able to properly recreate it later, since
     658             :   // we won't know what proto to use.  Note that we don't check
     659             :   // aGivenProto here, since it's entirely possible (and even
     660             :   // somewhat common) to have a non-null aGivenProto which is the
     661             :   // same as canonicalProto.
     662           0 :   if (proto != canonicalProto) {
     663           0 :     PreserveWrapper(aObject);
     664             :   }
     665             : 
     666           0 :   return true;
     667             : }
     668             : 
     669             : const NativePropertyHooks sNativePropertyHooks[] = { {
     670             :   nullptr,
     671             :   nullptr,
     672             :   nullptr,
     673             :   { sNativeProperties.Upcast(), nullptr },
     674             :   prototypes::id::PerformanceObserver,
     675             :   constructors::id::PerformanceObserver,
     676             :   nullptr,
     677             :   &DefaultXrayExpandoObjectClass
     678             : } };
     679             : 
     680             : void
     681           1 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
     682             : {
     683           2 :   JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
     684           1 :   if (!parentProto) {
     685           0 :     return;
     686             :   }
     687             : 
     688           2 :   JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
     689           1 :   if (!constructorProto) {
     690           0 :     return;
     691             :   }
     692             : 
     693             :   static bool sIdsInited = false;
     694           1 :   if (!sIdsInited && NS_IsMainThread()) {
     695           0 :     if (!InitIds(aCx, sNativeProperties.Upcast())) {
     696           0 :       return;
     697             :     }
     698           0 :     sIdsInited = true;
     699             :   }
     700             : 
     701           1 :   JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::PerformanceObserver);
     702           1 :   JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::PerformanceObserver);
     703           2 :   dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
     704             :                               &sPrototypeClass.mBase, protoCache,
     705             :                               constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr,
     706             :                               interfaceCache,
     707             :                               sNativeProperties.Upcast(),
     708             :                               nullptr,
     709             :                               "PerformanceObserver", aDefineOnGlobal,
     710             :                               nullptr,
     711           1 :                               false);
     712             : }
     713             : 
     714             : JS::Handle<JSObject*>
     715           0 : GetProtoObjectHandle(JSContext* aCx)
     716             : {
     717             :   /* Get the interface prototype object for this class.  This will create the
     718             :      object as needed. */
     719           0 :   bool aDefineOnGlobal = true;
     720             : 
     721             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
     722           0 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
     723           0 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
     724           0 :     return nullptr;
     725             :   }
     726             : 
     727             :   /* Check to see whether the interface objects are already installed */
     728           0 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
     729           0 :   if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::PerformanceObserver)) {
     730           0 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
     731           0 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
     732             :   }
     733             : 
     734             :   /*
     735             :    * The object might _still_ be null, but that's OK.
     736             :    *
     737             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
     738             :    * traced by TraceProtoAndIfaceCache() and its contents are never
     739             :    * changed after they have been set.
     740             :    *
     741             :    * Calling address() avoids the read read barrier that does gray
     742             :    * unmarking, but it's not possible for the object to be gray here.
     743             :    */
     744             : 
     745           0 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::PerformanceObserver);
     746           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
     747           0 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
     748             : }
     749             : 
     750             : JS::Handle<JSObject*>
     751           1 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
     752             : {
     753             :   /* Get the interface object for this class.  This will create the object as
     754             :      needed. */
     755             : 
     756             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
     757           1 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
     758           1 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
     759           0 :     return nullptr;
     760             :   }
     761             : 
     762             :   /* Check to see whether the interface objects are already installed */
     763           1 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
     764           1 :   if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::PerformanceObserver)) {
     765           2 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
     766           1 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
     767             :   }
     768             : 
     769             :   /*
     770             :    * The object might _still_ be null, but that's OK.
     771             :    *
     772             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
     773             :    * traced by TraceProtoAndIfaceCache() and its contents are never
     774             :    * changed after they have been set.
     775             :    *
     776             :    * Calling address() avoids the read read barrier that does gray
     777             :    * unmarking, but it's not possible for the object to be gray here.
     778             :    */
     779             : 
     780           1 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::PerformanceObserver);
     781           1 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
     782           1 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
     783             : }
     784             : 
     785             : JSObject*
     786           1 : GetConstructorObject(JSContext* aCx)
     787             : {
     788           1 :   return GetConstructorObjectHandle(aCx);
     789             : }
     790             : 
     791             : } // namespace PerformanceObserverBinding
     792             : 
     793             : 
     794             : 
     795             : } // namespace dom
     796             : } // namespace mozilla

Generated by: LCOV version 1.13