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

Generated by: LCOV version 1.13