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

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

Generated by: LCOV version 1.13