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

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

Generated by: LCOV version 1.13