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

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

Generated by: LCOV version 1.13