LCOV - code coverage report
Current view: top level - obj-x86_64-pc-linux-gnu/dom/bindings - MessageEventBinding.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 34 635 5.4 %
Date: 2017-07-14 16:53:18 Functions: 4 43 9.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* THIS FILE IS AUTOGENERATED FROM MessageEvent.webidl BY Codegen.py - DO NOT EDIT */
       2             : 
       3             : #include "AtomList.h"
       4             : #include "EventBinding.h"
       5             : #include "MessageEventBinding.h"
       6             : #include "WrapperFactory.h"
       7             : #include "XrayWrapper.h"
       8             : #include "mozilla/OwningNonNull.h"
       9             : #include "mozilla/dom/BindingUtils.h"
      10             : #include "mozilla/dom/DOMJSClass.h"
      11             : #include "mozilla/dom/MessageEvent.h"
      12             : #include "mozilla/dom/MessagePort.h"
      13             : #include "mozilla/dom/NonRefcountedDOMObject.h"
      14             : #include "mozilla/dom/Nullable.h"
      15             : #include "mozilla/dom/PrimitiveConversions.h"
      16             : #include "mozilla/dom/ScriptSettings.h"
      17             : #include "mozilla/dom/UnionConversions.h"
      18             : #include "mozilla/dom/XrayExpandoClass.h"
      19             : #include "mozilla/dom/workers/bindings/ServiceWorker.h"
      20             : #include "nsPIDOMWindow.h"
      21             : 
      22             : namespace mozilla {
      23             : namespace dom {
      24             : 
      25             : void
      26           0 : ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningWindowProxyOrMessagePortOrServiceWorker& aUnion, const char* aName, uint32_t aFlags)
      27             : {
      28           0 :   if (aUnion.IsWindowProxy()) {
      29           0 :     ImplCycleCollectionTraverse(aCallback, aUnion.GetAsWindowProxy(), "mWindowProxy", aFlags);
      30           0 :   } else if (aUnion.IsMessagePort()) {
      31           0 :     ImplCycleCollectionTraverse(aCallback, aUnion.GetAsMessagePort(), "mMessagePort", aFlags);
      32           0 :   } else if (aUnion.IsServiceWorker()) {
      33           0 :     ImplCycleCollectionTraverse(aCallback, aUnion.GetAsServiceWorker(), "mServiceWorker", aFlags);
      34             :   }
      35           0 : }
      36             : 
      37             : 
      38             : void
      39           0 : ImplCycleCollectionUnlink(OwningWindowProxyOrMessagePortOrServiceWorker& aUnion)
      40             : {
      41           0 :   aUnion.Uninit();
      42           0 : }
      43             : 
      44             : 
      45             : bool
      46           0 : WindowProxyOrMessagePortOrServiceWorker::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
      47             : {
      48           0 :   switch (mType) {
      49             :     case eUninitialized: {
      50           0 :       return false;
      51             :       break;
      52             :     }
      53             :     case eWindowProxy: {
      54           0 :       if (!WrapObject(cx, mValue.mWindowProxy.Value(), rval)) {
      55           0 :         return false;
      56             :       }
      57           0 :       return true;
      58             :       break;
      59             :     }
      60             :     case eMessagePort: {
      61           0 :       if (!GetOrCreateDOMReflector(cx, mValue.mMessagePort.Value(), rval)) {
      62           0 :         MOZ_ASSERT(true || JS_IsExceptionPending(cx));
      63           0 :         return false;
      64             :       }
      65           0 :       return true;
      66             :       break;
      67             :     }
      68             :     case eServiceWorker: {
      69           0 :       if (!GetOrCreateDOMReflector(cx, mValue.mServiceWorker.Value(), rval)) {
      70           0 :         MOZ_ASSERT(true || JS_IsExceptionPending(cx));
      71           0 :         return false;
      72             :       }
      73           0 :       return true;
      74             :       break;
      75             :     }
      76             :     default: {
      77           0 :       return false;
      78             :       break;
      79             :     }
      80             :   }
      81             : 
      82             :   return false;
      83             : }
      84             : 
      85             : 
      86             : RefPtr<nsPIDOMWindowOuter>&
      87           0 : OwningWindowProxyOrMessagePortOrServiceWorker::RawSetAsWindowProxy()
      88             : {
      89           0 :   if (mType == eWindowProxy) {
      90           0 :     return mValue.mWindowProxy.Value();
      91             :   }
      92           0 :   MOZ_ASSERT(mType == eUninitialized);
      93           0 :   mType = eWindowProxy;
      94           0 :   return mValue.mWindowProxy.SetValue();
      95             : }
      96             : 
      97             : RefPtr<nsPIDOMWindowOuter>&
      98           0 : OwningWindowProxyOrMessagePortOrServiceWorker::SetAsWindowProxy()
      99             : {
     100           0 :   if (mType == eWindowProxy) {
     101           0 :     return mValue.mWindowProxy.Value();
     102             :   }
     103           0 :   Uninit();
     104           0 :   mType = eWindowProxy;
     105           0 :   return mValue.mWindowProxy.SetValue();
     106             : }
     107             : 
     108             : bool
     109           0 : OwningWindowProxyOrMessagePortOrServiceWorker::TrySetToWindowProxy(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
     110             : {
     111           0 :   tryNext = false;
     112             :   { // scope for memberSlot
     113           0 :     RefPtr<nsPIDOMWindowOuter>& memberSlot = RawSetAsWindowProxy();
     114           0 :     static_assert(IsRefcounted<nsPIDOMWindowOuter>::value, "We can only store refcounted classes.");RefPtr<nsPIDOMWindowOuter> mWindowProxyHolder;
     115           0 :     JS::Rooted<JSObject*> source(cx, &value.toObject());
     116           0 :     if (NS_FAILED(UnwrapArg<nsPIDOMWindowOuter>(cx, source, getter_AddRefs(mWindowProxyHolder)))) {
     117           0 :       DestroyWindowProxy();
     118           0 :       tryNext = true;
     119           0 :       return true;
     120             :     }
     121           0 :     MOZ_ASSERT(mWindowProxyHolder);
     122           0 :     memberSlot = mWindowProxyHolder;
     123             :   }
     124           0 :   return true;
     125             : }
     126             : 
     127             : void
     128           0 : OwningWindowProxyOrMessagePortOrServiceWorker::DestroyWindowProxy()
     129             : {
     130           0 :   MOZ_ASSERT(IsWindowProxy(), "Wrong type!");
     131           0 :   mValue.mWindowProxy.Destroy();
     132           0 :   mType = eUninitialized;
     133           0 : }
     134             : 
     135             : 
     136             : 
     137             : 
     138             : OwningNonNull<mozilla::dom::MessagePort>&
     139           0 : OwningWindowProxyOrMessagePortOrServiceWorker::RawSetAsMessagePort()
     140             : {
     141           0 :   if (mType == eMessagePort) {
     142           0 :     return mValue.mMessagePort.Value();
     143             :   }
     144           0 :   MOZ_ASSERT(mType == eUninitialized);
     145           0 :   mType = eMessagePort;
     146           0 :   return mValue.mMessagePort.SetValue();
     147             : }
     148             : 
     149             : OwningNonNull<mozilla::dom::MessagePort>&
     150           0 : OwningWindowProxyOrMessagePortOrServiceWorker::SetAsMessagePort()
     151             : {
     152           0 :   if (mType == eMessagePort) {
     153           0 :     return mValue.mMessagePort.Value();
     154             :   }
     155           0 :   Uninit();
     156           0 :   mType = eMessagePort;
     157           0 :   return mValue.mMessagePort.SetValue();
     158             : }
     159             : 
     160             : bool
     161           0 : OwningWindowProxyOrMessagePortOrServiceWorker::TrySetToMessagePort(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
     162             : {
     163           0 :   tryNext = false;
     164             :   { // scope for memberSlot
     165           0 :     OwningNonNull<mozilla::dom::MessagePort>& memberSlot = RawSetAsMessagePort();
     166             :     static_assert(IsRefcounted<mozilla::dom::MessagePort>::value, "We can only store refcounted classes.");{
     167           0 :       nsresult rv = UnwrapObject<prototypes::id::MessagePort, mozilla::dom::MessagePort>(value, memberSlot);
     168           0 :       if (NS_FAILED(rv)) {
     169           0 :         DestroyMessagePort();
     170           0 :         tryNext = true;
     171           0 :         return true;
     172             :       }
     173             :     }
     174             :   }
     175           0 :   return true;
     176             : }
     177             : 
     178             : void
     179           0 : OwningWindowProxyOrMessagePortOrServiceWorker::DestroyMessagePort()
     180             : {
     181           0 :   MOZ_ASSERT(IsMessagePort(), "Wrong type!");
     182           0 :   mValue.mMessagePort.Destroy();
     183           0 :   mType = eUninitialized;
     184           0 : }
     185             : 
     186             : 
     187             : 
     188             : 
     189             : OwningNonNull<mozilla::dom::workers::ServiceWorker>&
     190           0 : OwningWindowProxyOrMessagePortOrServiceWorker::RawSetAsServiceWorker()
     191             : {
     192           0 :   if (mType == eServiceWorker) {
     193           0 :     return mValue.mServiceWorker.Value();
     194             :   }
     195           0 :   MOZ_ASSERT(mType == eUninitialized);
     196           0 :   mType = eServiceWorker;
     197           0 :   return mValue.mServiceWorker.SetValue();
     198             : }
     199             : 
     200             : OwningNonNull<mozilla::dom::workers::ServiceWorker>&
     201           0 : OwningWindowProxyOrMessagePortOrServiceWorker::SetAsServiceWorker()
     202             : {
     203           0 :   if (mType == eServiceWorker) {
     204           0 :     return mValue.mServiceWorker.Value();
     205             :   }
     206           0 :   Uninit();
     207           0 :   mType = eServiceWorker;
     208           0 :   return mValue.mServiceWorker.SetValue();
     209             : }
     210             : 
     211             : bool
     212           0 : OwningWindowProxyOrMessagePortOrServiceWorker::TrySetToServiceWorker(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
     213             : {
     214           0 :   tryNext = false;
     215             :   { // scope for memberSlot
     216           0 :     OwningNonNull<mozilla::dom::workers::ServiceWorker>& memberSlot = RawSetAsServiceWorker();
     217             :     static_assert(IsRefcounted<mozilla::dom::workers::ServiceWorker>::value, "We can only store refcounted classes.");{
     218           0 :       nsresult rv = UnwrapObject<prototypes::id::ServiceWorker, mozilla::dom::workers::ServiceWorker>(value, memberSlot);
     219           0 :       if (NS_FAILED(rv)) {
     220           0 :         DestroyServiceWorker();
     221           0 :         tryNext = true;
     222           0 :         return true;
     223             :       }
     224             :     }
     225             :   }
     226           0 :   return true;
     227             : }
     228             : 
     229             : void
     230           0 : OwningWindowProxyOrMessagePortOrServiceWorker::DestroyServiceWorker()
     231             : {
     232           0 :   MOZ_ASSERT(IsServiceWorker(), "Wrong type!");
     233           0 :   mValue.mServiceWorker.Destroy();
     234           0 :   mType = eUninitialized;
     235           0 : }
     236             : 
     237             : 
     238             : 
     239             : 
     240             : void
     241           0 : OwningWindowProxyOrMessagePortOrServiceWorker::Uninit()
     242             : {
     243           0 :   switch (mType) {
     244             :     case eUninitialized: {
     245           0 :       break;
     246             :     }
     247             :     case eWindowProxy: {
     248           0 :       DestroyWindowProxy();
     249           0 :       break;
     250             :     }
     251             :     case eMessagePort: {
     252           0 :       DestroyMessagePort();
     253           0 :       break;
     254             :     }
     255             :     case eServiceWorker: {
     256           0 :       DestroyServiceWorker();
     257           0 :       break;
     258             :     }
     259             :   }
     260           0 : }
     261             : 
     262             : bool
     263           0 : OwningWindowProxyOrMessagePortOrServiceWorker::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
     264             : {
     265           0 :   switch (mType) {
     266             :     case eUninitialized: {
     267           0 :       return false;
     268             :       break;
     269             :     }
     270             :     case eWindowProxy: {
     271           0 :       if (!WrapObject(cx, mValue.mWindowProxy.Value(), rval)) {
     272           0 :         return false;
     273             :       }
     274           0 :       return true;
     275             :       break;
     276             :     }
     277             :     case eMessagePort: {
     278           0 :       if (!GetOrCreateDOMReflector(cx, mValue.mMessagePort.Value(), rval)) {
     279           0 :         MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     280           0 :         return false;
     281             :       }
     282           0 :       return true;
     283             :       break;
     284             :     }
     285             :     case eServiceWorker: {
     286           0 :       if (!GetOrCreateDOMReflector(cx, mValue.mServiceWorker.Value(), rval)) {
     287           0 :         MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     288           0 :         return false;
     289             :       }
     290           0 :       return true;
     291             :       break;
     292             :     }
     293             :     default: {
     294           0 :       return false;
     295             :       break;
     296             :     }
     297             :   }
     298             : 
     299             :   return false;
     300             : }
     301             : 
     302             : void
     303           0 : OwningWindowProxyOrMessagePortOrServiceWorker::TraceUnion(JSTracer* trc)
     304             : {
     305           0 : }
     306             : 
     307             : OwningWindowProxyOrMessagePortOrServiceWorker&
     308           0 : OwningWindowProxyOrMessagePortOrServiceWorker::operator=(const OwningWindowProxyOrMessagePortOrServiceWorker& aOther)
     309             : {
     310           0 :   switch (aOther.mType) {
     311             :     case eUninitialized: {
     312           0 :       MOZ_ASSERT(mType == eUninitialized,
     313             :                  "We need to destroy ourselves?");
     314           0 :       break;
     315             :     }
     316             :     case eWindowProxy: {
     317           0 :       SetAsWindowProxy() = aOther.GetAsWindowProxy();
     318           0 :       break;
     319             :     }
     320             :     case eMessagePort: {
     321           0 :       SetAsMessagePort() = aOther.GetAsMessagePort();
     322           0 :       break;
     323             :     }
     324             :     case eServiceWorker: {
     325           0 :       SetAsServiceWorker() = aOther.GetAsServiceWorker();
     326           0 :       break;
     327             :     }
     328             :   }
     329           0 :   return *this;
     330             : }
     331             : 
     332             : 
     333             : 
     334           0 : MessageEventInit::MessageEventInit()
     335           0 :   : EventInit(FastDictionaryInitializer()),
     336           0 :     mData(JS::UndefinedValue())
     337             : {
     338             :   // Safe to pass a null context if we pass a null value
     339           0 :   Init(nullptr, JS::NullHandleValue);
     340           0 : }
     341             : 
     342             : 
     343             : bool
     344           0 : MessageEventInit::InitIds(JSContext* cx, MessageEventInitAtoms* atomsCache)
     345             : {
     346           0 :   MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
     347             : 
     348             :   // Initialize these in reverse order so that any failure leaves the first one
     349             :   // uninitialized.
     350           0 :   if (!atomsCache->source_id.init(cx, "source") ||
     351           0 :       !atomsCache->ports_id.init(cx, "ports") ||
     352           0 :       !atomsCache->origin_id.init(cx, "origin") ||
     353           0 :       !atomsCache->lastEventId_id.init(cx, "lastEventId") ||
     354           0 :       !atomsCache->data_id.init(cx, "data")) {
     355           0 :     return false;
     356             :   }
     357           0 :   return true;
     358             : }
     359             : 
     360             : bool
     361           0 : MessageEventInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
     362             : {
     363             :   // Passing a null JSContext is OK only if we're initing from null,
     364             :   // Since in that case we will not have to do any property gets
     365             :   // Also evaluate isNullOrUndefined in order to avoid false-positive
     366             :   // checkers by static analysis tools
     367           0 :   MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
     368           0 :   MessageEventInitAtoms* atomsCache = nullptr;
     369           0 :   if (cx) {
     370           0 :     atomsCache = GetAtomCache<MessageEventInitAtoms>(cx);
     371           0 :     if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
     372           0 :       return false;
     373             :     }
     374             :   }
     375             : 
     376             :   // Per spec, we init the parent's members first
     377           0 :   if (!EventInit::Init(cx, val)) {
     378           0 :     return false;
     379             :   }
     380             : 
     381           0 :   bool isNull = val.isNullOrUndefined();
     382             :   // We only need these if !isNull, in which case we have |cx|.
     383           0 :   Maybe<JS::Rooted<JSObject *> > object;
     384           0 :   Maybe<JS::Rooted<JS::Value> > temp;
     385           0 :   if (!isNull) {
     386           0 :     MOZ_ASSERT(cx);
     387           0 :     object.emplace(cx, &val.toObject());
     388           0 :     temp.emplace(cx);
     389             :   }
     390           0 :   if (!isNull) {
     391           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->data_id, temp.ptr())) {
     392           0 :       return false;
     393             :     }
     394             :   }
     395           0 :   if (!isNull && !temp->isUndefined()) {
     396             : #ifdef __clang__
     397             : #pragma clang diagnostic push
     398             : #pragma clang diagnostic ignored "-Wunreachable-code"
     399             : #pragma clang diagnostic ignored "-Wunreachable-code-return"
     400             : #endif // __clang__
     401           0 :     if ((passedToJSImpl) && !CallerSubsumes(temp.ref())) {
     402           0 :       ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "'data' member of MessageEventInit");
     403           0 :       return false;
     404             :     }
     405             : #ifdef __clang__
     406             : #pragma clang diagnostic pop
     407             : #endif // __clang__
     408           0 :     mData = temp.ref();
     409             :   } else {
     410           0 :     mData = JS::NullValue();
     411             :   }
     412           0 :   mIsAnyMemberPresent = true;
     413             : 
     414           0 :   if (!isNull) {
     415           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->lastEventId_id, temp.ptr())) {
     416           0 :       return false;
     417             :     }
     418             :   }
     419           0 :   if (!isNull && !temp->isUndefined()) {
     420           0 :     if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mLastEventId)) {
     421           0 :       return false;
     422             :     }
     423             :   } else {
     424             :     static const char16_t data[] = { 0 };
     425           0 :     mLastEventId.Rebind(data, ArrayLength(data) - 1);
     426             :   }
     427           0 :   mIsAnyMemberPresent = true;
     428             : 
     429           0 :   if (!isNull) {
     430           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->origin_id, temp.ptr())) {
     431           0 :       return false;
     432             :     }
     433             :   }
     434           0 :   if (!isNull && !temp->isUndefined()) {
     435           0 :     if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mOrigin)) {
     436           0 :       return false;
     437             :     }
     438             :   } else {
     439             :     static const char16_t data[] = { 0 };
     440           0 :     mOrigin.Rebind(data, ArrayLength(data) - 1);
     441             :   }
     442           0 :   mIsAnyMemberPresent = true;
     443             : 
     444           0 :   if (!isNull) {
     445           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->ports_id, temp.ptr())) {
     446           0 :       return false;
     447             :     }
     448             :   }
     449           0 :   if (!isNull && !temp->isUndefined()) {
     450           0 :     if (temp.ref().isObject()) {
     451           0 :       JS::ForOfIterator iter(cx);
     452           0 :       if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
     453           0 :         return false;
     454             :       }
     455           0 :       if (!iter.valueIsIterable()) {
     456           0 :         ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'ports' member of MessageEventInit");
     457           0 :         return false;
     458             :       }
     459           0 :       Sequence<OwningNonNull<mozilla::dom::MessagePort>> &arr = mPorts;
     460           0 :       JS::Rooted<JS::Value> temp(cx);
     461             :       while (true) {
     462             :         bool done;
     463           0 :         if (!iter.next(&temp, &done)) {
     464           0 :           return false;
     465             :         }
     466           0 :         if (done) {
     467           0 :           break;
     468             :         }
     469           0 :         OwningNonNull<mozilla::dom::MessagePort>* slotPtr = arr.AppendElement(mozilla::fallible);
     470           0 :         if (!slotPtr) {
     471           0 :           JS_ReportOutOfMemory(cx);
     472           0 :           return false;
     473             :         }
     474           0 :         OwningNonNull<mozilla::dom::MessagePort>& slot = *slotPtr;
     475           0 :         if (temp.isObject()) {
     476             :           static_assert(IsRefcounted<mozilla::dom::MessagePort>::value, "We can only store refcounted classes.");{
     477           0 :             nsresult rv = UnwrapObject<prototypes::id::MessagePort, mozilla::dom::MessagePort>(&temp, slot);
     478           0 :             if (NS_FAILED(rv)) {
     479           0 :               ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Element of 'ports' member of MessageEventInit", "MessagePort");
     480           0 :               return false;
     481             :             }
     482             :           }
     483             :         } else {
     484           0 :           ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of 'ports' member of MessageEventInit");
     485           0 :           return false;
     486             :         }
     487           0 :       }
     488             :     } else {
     489           0 :       ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'ports' member of MessageEventInit");
     490           0 :       return false;
     491             :     }
     492             :   } else {
     493             :     /* Array is already empty; nothing to do */
     494             :   }
     495           0 :   mIsAnyMemberPresent = true;
     496             : 
     497           0 :   if (!isNull) {
     498           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->source_id, temp.ptr())) {
     499           0 :       return false;
     500             :     }
     501             :   }
     502           0 :   if (!(!isNull && !temp->isUndefined()) || temp.ref().isNullOrUndefined()) {
     503           0 :     mSource.SetNull();
     504             :   } else {
     505             :     {
     506           0 :       bool done = false, failed = false, tryNext;
     507           0 :       if (temp.ref().isObject()) {
     508           0 :         done = (failed = !mSource.SetValue().TrySetToWindowProxy(cx, temp.ref(), tryNext, passedToJSImpl)) || !tryNext ||
     509           0 :                (failed = !mSource.SetValue().TrySetToMessagePort(cx, temp.ref(), tryNext, passedToJSImpl)) || !tryNext ||
     510           0 :                (failed = !mSource.SetValue().TrySetToServiceWorker(cx, temp.ref(), tryNext, passedToJSImpl)) || !tryNext;
     511             : 
     512             :       }
     513           0 :       if (failed) {
     514           0 :         return false;
     515             :       }
     516           0 :       if (!done) {
     517           0 :         ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "'source' member of MessageEventInit", "WindowProxy, MessagePort, ServiceWorker");
     518           0 :         return false;
     519             :       }
     520             :     }
     521             :   }
     522           0 :   mIsAnyMemberPresent = true;
     523           0 :   return true;
     524             : }
     525             : 
     526             : bool
     527           0 : MessageEventInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
     528             : {
     529           0 :   MessageEventInitAtoms* atomsCache = GetAtomCache<MessageEventInitAtoms>(cx);
     530           0 :   if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
     531           0 :     return false;
     532             :   }
     533             : 
     534             :   // Per spec, we define the parent's members first
     535           0 :   if (!EventInit::ToObjectInternal(cx, rval)) {
     536           0 :     return false;
     537             :   }
     538           0 :   JS::Rooted<JSObject*> obj(cx, &rval.toObject());
     539             : 
     540             :   do {
     541             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     542           0 :     JS::Rooted<JS::Value> temp(cx);
     543           0 :     JS::Value const & currentValue = mData;
     544           0 :     JS::ExposeValueToActiveJS(currentValue);
     545           0 :     temp.set(currentValue);
     546           0 :     if (!MaybeWrapValue(cx, &temp)) {
     547           0 :       return false;
     548             :     }
     549           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->data_id, temp, JSPROP_ENUMERATE)) {
     550           0 :       return false;
     551             :     }
     552           0 :     break;
     553             :   } while(0);
     554             : 
     555             :   do {
     556             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     557           0 :     JS::Rooted<JS::Value> temp(cx);
     558           0 :     nsString const & currentValue = mLastEventId;
     559           0 :     if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
     560           0 :       return false;
     561             :     }
     562           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->lastEventId_id, temp, JSPROP_ENUMERATE)) {
     563           0 :       return false;
     564             :     }
     565           0 :     break;
     566             :   } while(0);
     567             : 
     568             :   do {
     569             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     570           0 :     JS::Rooted<JS::Value> temp(cx);
     571           0 :     nsString const & currentValue = mOrigin;
     572           0 :     if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
     573           0 :       return false;
     574             :     }
     575           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->origin_id, temp, JSPROP_ENUMERATE)) {
     576           0 :       return false;
     577             :     }
     578           0 :     break;
     579             :   } while(0);
     580             : 
     581             :   do {
     582             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     583           0 :     JS::Rooted<JS::Value> temp(cx);
     584           0 :     Sequence<OwningNonNull<mozilla::dom::MessagePort>> const & currentValue = mPorts;
     585             : 
     586           0 :     uint32_t length = currentValue.Length();
     587           0 :     JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
     588           0 :     if (!returnArray) {
     589           0 :       return false;
     590             :     }
     591             :     // Scope for 'tmp'
     592             :     {
     593           0 :       JS::Rooted<JS::Value> tmp(cx);
     594           0 :       for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
     595             :         // Control block to let us common up the JS_DefineElement calls when there
     596             :         // are different ways to succeed at wrapping the object.
     597             :         do {
     598           0 :           if (!GetOrCreateDOMReflector(cx, currentValue[sequenceIdx0], &tmp)) {
     599           0 :             MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     600           0 :             return false;
     601             :           }
     602           0 :           break;
     603             :         } while (0);
     604           0 :         if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
     605             :                               JSPROP_ENUMERATE)) {
     606           0 :           return false;
     607             :         }
     608             :       }
     609             :     }
     610           0 :     temp.setObject(*returnArray);
     611           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->ports_id, temp, JSPROP_ENUMERATE)) {
     612           0 :       return false;
     613             :     }
     614           0 :     break;
     615             :   } while(0);
     616             : 
     617             :   do {
     618             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     619           0 :     JS::Rooted<JS::Value> temp(cx);
     620           0 :     Nullable<OwningWindowProxyOrMessagePortOrServiceWorker > const & currentValue = mSource;
     621           0 :     if (currentValue.IsNull()) {
     622           0 :       temp.setNull();
     623           0 :       if (!JS_DefinePropertyById(cx, obj, atomsCache->source_id, temp, JSPROP_ENUMERATE)) {
     624           0 :         return false;
     625             :       }
     626           0 :       break;
     627             :     }
     628           0 :     if (!currentValue.Value().ToJSVal(cx, obj, &temp)) {
     629           0 :       return false;
     630             :     }
     631           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->source_id, temp, JSPROP_ENUMERATE)) {
     632           0 :       return false;
     633             :     }
     634           0 :     break;
     635             :   } while(0);
     636             : 
     637           0 :   return true;
     638             : }
     639             : 
     640             : void
     641           0 : MessageEventInit::TraceDictionary(JSTracer* trc)
     642             : {
     643           0 :   EventInit::TraceDictionary(trc);
     644           0 :   JS::UnsafeTraceRoot(trc, &mData, "MessageEventInit.mData");
     645           0 : }
     646             : 
     647             : namespace binding_detail {
     648             : } // namespace binding_detail
     649             : 
     650             : 
     651             : namespace MessageEventBinding {
     652             : 
     653             : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventBinding::NativeType>::value,
     654             :               "Can't inherit from an interface with a different ownership model.");
     655             : 
     656             : static bool
     657           0 : get_data(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MessageEvent* self, JSJitGetterCallArgs args)
     658             : {
     659           0 :   binding_detail::FastErrorResult rv;
     660           0 :   JS::Rooted<JS::Value> result(cx);
     661           0 :   self->GetData(cx, &result, rv);
     662           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     663           0 :     return false;
     664             :   }
     665           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     666           0 :   JS::ExposeValueToActiveJS(result);
     667           0 :   args.rval().set(result);
     668           0 :   if (!MaybeWrapValue(cx, args.rval())) {
     669           0 :     return false;
     670             :   }
     671           0 :   return true;
     672             : }
     673             : 
     674             : static const JSJitInfo data_getterinfo = {
     675             :   { (JSJitGetterOp)get_data },
     676             :   { prototypes::id::MessageEvent },
     677             :   { PrototypeTraits<prototypes::id::MessageEvent>::Depth },
     678             :   JSJitInfo::Getter,
     679             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     680             :   JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
     681             :   false,  /* isInfallible. False in setters. */
     682             :   false,  /* isMovable.  Not relevant for setters. */
     683             :   false, /* isEliminatable.  Not relevant for setters. */
     684             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     685             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     686             :   false,  /* isTypedMethod.  Only relevant for methods. */
     687             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     688             : };
     689             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     690             : static_assert(0 < 2, "There is no slot for us");
     691             : 
     692             : static bool
     693           0 : get_origin(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MessageEvent* self, JSJitGetterCallArgs args)
     694             : {
     695           0 :   DOMString result;
     696           0 :   self->GetOrigin(result);
     697           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     698           0 :   if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
     699           0 :     return false;
     700             :   }
     701           0 :   return true;
     702             : }
     703             : 
     704             : static const JSJitInfo origin_getterinfo = {
     705             :   { (JSJitGetterOp)get_origin },
     706             :   { prototypes::id::MessageEvent },
     707             :   { PrototypeTraits<prototypes::id::MessageEvent>::Depth },
     708             :   JSJitInfo::Getter,
     709             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     710             :   JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
     711             :   false,  /* isInfallible. False in setters. */
     712             :   false,  /* isMovable.  Not relevant for setters. */
     713             :   false, /* isEliminatable.  Not relevant for setters. */
     714             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     715             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     716             :   false,  /* isTypedMethod.  Only relevant for methods. */
     717             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     718             : };
     719             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     720             : static_assert(0 < 2, "There is no slot for us");
     721             : 
     722             : static bool
     723           0 : get_lastEventId(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MessageEvent* self, JSJitGetterCallArgs args)
     724             : {
     725           0 :   DOMString result;
     726           0 :   self->GetLastEventId(result);
     727           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     728           0 :   if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
     729           0 :     return false;
     730             :   }
     731           0 :   return true;
     732             : }
     733             : 
     734             : static const JSJitInfo lastEventId_getterinfo = {
     735             :   { (JSJitGetterOp)get_lastEventId },
     736             :   { prototypes::id::MessageEvent },
     737             :   { PrototypeTraits<prototypes::id::MessageEvent>::Depth },
     738             :   JSJitInfo::Getter,
     739             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     740             :   JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
     741             :   false,  /* isInfallible. False in setters. */
     742             :   false,  /* isMovable.  Not relevant for setters. */
     743             :   false, /* isEliminatable.  Not relevant for setters. */
     744             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     745             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     746             :   false,  /* isTypedMethod.  Only relevant for methods. */
     747             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     748             : };
     749             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     750             : static_assert(0 < 2, "There is no slot for us");
     751             : 
     752             : static bool
     753           0 : get_source(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MessageEvent* self, JSJitGetterCallArgs args)
     754             : {
     755           0 :   Nullable<OwningWindowProxyOrMessagePortOrServiceWorker> result;
     756           0 :   self->GetSource(result);
     757           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     758           0 :   if (result.IsNull()) {
     759           0 :     args.rval().setNull();
     760           0 :     return true;
     761             :   }
     762           0 :   if (!result.Value().ToJSVal(cx, obj, args.rval())) {
     763           0 :     return false;
     764             :   }
     765           0 :   return true;
     766             : }
     767             : 
     768             : static const JSJitInfo source_getterinfo = {
     769             :   { (JSJitGetterOp)get_source },
     770             :   { prototypes::id::MessageEvent },
     771             :   { PrototypeTraits<prototypes::id::MessageEvent>::Depth },
     772             :   JSJitInfo::Getter,
     773             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     774             :   JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
     775             :   false,  /* isInfallible. False in setters. */
     776             :   false,  /* isMovable.  Not relevant for setters. */
     777             :   false, /* isEliminatable.  Not relevant for setters. */
     778             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     779             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     780             :   false,  /* isTypedMethod.  Only relevant for methods. */
     781             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     782             : };
     783             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     784             : static_assert(0 < 2, "There is no slot for us");
     785             : 
     786             : static bool
     787           0 : get_ports(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MessageEvent* self, JSJitGetterCallArgs args)
     788             : {
     789             :   // Have to either root across the getter call or reget after.
     790             :   bool isXray;
     791           0 :   JS::Rooted<JSObject*> slotStorage(cx, GetCachedSlotStorageObject(cx, obj, &isXray));
     792           0 :   if (!slotStorage) {
     793           0 :     return false;
     794             :   }
     795           0 :   const size_t slotIndex = isXray ? (xpc::JSSLOT_EXPANDO_COUNT + 0) : (DOM_INSTANCE_RESERVED_SLOTS + 0);
     796           0 :   MOZ_ASSERT(JSCLASS_RESERVED_SLOTS(js::GetObjectClass(slotStorage)) > slotIndex);
     797             :   {
     798             :     // Scope for cachedVal
     799           0 :     JS::Value cachedVal = js::GetReservedSlot(slotStorage, slotIndex);
     800           0 :     if (!cachedVal.isUndefined()) {
     801           0 :       args.rval().set(cachedVal);
     802             :       // The cached value is in the compartment of slotStorage,
     803             :       // so wrap into the caller compartment as needed.
     804           0 :       return MaybeWrapNonDOMObjectValue(cx, args.rval());
     805             :     }
     806             :   }
     807             : 
     808           0 :   nsTArray<StrongPtrForMember<mozilla::dom::MessagePort>::Type> result;
     809           0 :   self->GetPorts(result);
     810           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     811             :   {
     812           0 :     JS::Rooted<JSObject*> conversionScope(cx, isXray ? obj : slotStorage);
     813           0 :     JSAutoCompartment ac(cx, conversionScope);
     814             :     do { // block we break out of when done wrapping
     815             : 
     816           0 :       uint32_t length = result.Length();
     817           0 :       JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
     818           0 :       if (!returnArray) {
     819           0 :         return false;
     820             :       }
     821             :       // Scope for 'tmp'
     822             :       {
     823           0 :         JS::Rooted<JS::Value> tmp(cx);
     824           0 :         for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
     825             :           // Control block to let us common up the JS_DefineElement calls when there
     826             :           // are different ways to succeed at wrapping the object.
     827             :           do {
     828           0 :             if (!GetOrCreateDOMReflector(cx, result[sequenceIdx0], &tmp)) {
     829           0 :               MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     830           0 :               return false;
     831             :             }
     832           0 :             break;
     833             :           } while (0);
     834           0 :           if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
     835             :                                 JSPROP_ENUMERATE)) {
     836           0 :             return false;
     837             :           }
     838             :         }
     839             :       }
     840           0 :       args.rval().setObject(*returnArray);
     841           0 :       break;
     842             :     } while (0);
     843           0 :     JS::Rooted<JSObject*> rvalObj(cx, &args.rval().toObject());
     844           0 :     if (!JS_FreezeObject(cx, rvalObj)) {
     845           0 :       return false;
     846             :     }
     847             :   }
     848             :   { // And now store things in the compartment of our slotStorage.
     849           0 :     JSAutoCompartment ac(cx, slotStorage);
     850             :     // Make a copy so that we don't do unnecessary wrapping on args.rval().
     851           0 :     JS::Rooted<JS::Value> storedVal(cx, args.rval());
     852           0 :     if (!MaybeWrapNonDOMObjectValue(cx, &storedVal)) {
     853           0 :       return false;
     854             :     }
     855           0 :     js::SetReservedSlot(slotStorage, slotIndex, storedVal);
     856           0 :     if (!isXray) {
     857             :       // In the Xray case we don't need to do this, because getting the
     858             :       // expando object already preserved our wrapper.
     859           0 :       PreserveWrapper(self);
     860             :     }
     861             :   }
     862             :   // And now make sure args.rval() is in the caller compartment
     863           0 :   return MaybeWrapNonDOMObjectValue(cx, args.rval());
     864             : }
     865             : 
     866             : static const JSJitInfo ports_getterinfo = {
     867             :   { (JSJitGetterOp)get_ports },
     868             :   { prototypes::id::MessageEvent },
     869             :   { PrototypeTraits<prototypes::id::MessageEvent>::Depth },
     870             :   JSJitInfo::Getter,
     871             :   JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
     872             :   JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
     873             :   false,  /* isInfallible. False in setters. */
     874             :   true,  /* isMovable.  Not relevant for setters. */
     875             :   true, /* isEliminatable.  Not relevant for setters. */
     876             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     877             :   true, /* isLazilyCachedInSlot.  Only relevant for getters. */
     878             :   false,  /* isTypedMethod.  Only relevant for methods. */
     879             :   (DOM_INSTANCE_RESERVED_SLOTS + 0)   /* Reserved slot index, if we're stored in a slot, else 0. */
     880             : };
     881             : static_assert((DOM_INSTANCE_RESERVED_SLOTS + 0) <= JSJitInfo::maxSlotIndex, "We won't fit");
     882             : static_assert((DOM_INSTANCE_RESERVED_SLOTS + 0) < 2, "There is no slot for us");
     883             : 
     884             : static bool
     885           0 : initMessageEvent(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MessageEvent* self, const JSJitMethodCallArgs& args)
     886             : {
     887           0 :   if (MOZ_UNLIKELY(args.length() < 1)) {
     888           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "MessageEvent.initMessageEvent");
     889             :   }
     890           0 :   binding_detail::FakeString arg0;
     891           0 :   if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
     892           0 :     return false;
     893             :   }
     894             :   bool arg1;
     895           0 :   if (args.hasDefined(1)) {
     896           0 :     if (!ValueToPrimitive<bool, eDefault>(cx, args[1], &arg1)) {
     897           0 :       return false;
     898             :     }
     899             :   } else {
     900           0 :     arg1 = false;
     901             :   }
     902             :   bool arg2;
     903           0 :   if (args.hasDefined(2)) {
     904           0 :     if (!ValueToPrimitive<bool, eDefault>(cx, args[2], &arg2)) {
     905           0 :       return false;
     906             :     }
     907             :   } else {
     908           0 :     arg2 = false;
     909             :   }
     910           0 :   JS::Rooted<JS::Value> arg3(cx);
     911           0 :   if (args.hasDefined(3)) {
     912           0 :     arg3 = args[3];
     913             :   } else {
     914           0 :     arg3 = JS::NullValue();
     915             :   }
     916           0 :   binding_detail::FakeString arg4;
     917           0 :   if (args.hasDefined(4)) {
     918           0 :     if (!ConvertJSValueToString(cx, args[4], eStringify, eStringify, arg4)) {
     919           0 :       return false;
     920             :     }
     921             :   } else {
     922             :     static const char16_t data[] = { 0 };
     923           0 :     arg4.Rebind(data, ArrayLength(data) - 1);
     924             :   }
     925           0 :   binding_detail::FakeString arg5;
     926           0 :   if (args.hasDefined(5)) {
     927           0 :     if (!ConvertJSValueToString(cx, args[5], eStringify, eStringify, arg5)) {
     928           0 :       return false;
     929             :     }
     930             :   } else {
     931             :     static const char16_t data[] = { 0 };
     932           0 :     arg5.Rebind(data, ArrayLength(data) - 1);
     933             :   }
     934           0 :   Nullable<WindowProxyOrMessagePortOrServiceWorker > arg6;
     935           0 :   Maybe<WindowProxyOrMessagePortOrServiceWorkerArgument> arg6_holder;
     936           0 :   if (!(args.hasDefined(6)) || args[6].isNullOrUndefined()) {
     937           0 :     arg6.SetNull();
     938             :   } else {
     939           0 :     arg6_holder.emplace(arg6.SetValue());
     940             :     {
     941           0 :       bool done = false, failed = false, tryNext;
     942           0 :       if (args[6].isObject()) {
     943           0 :         done = (failed = !arg6_holder.ref().TrySetToWindowProxy(cx, args[6], tryNext, false)) || !tryNext ||
     944           0 :                (failed = !arg6_holder.ref().TrySetToMessagePort(cx, args[6], tryNext, false)) || !tryNext ||
     945           0 :                (failed = !arg6_holder.ref().TrySetToServiceWorker(cx, args[6], tryNext, false)) || !tryNext;
     946             : 
     947             :       }
     948           0 :       if (failed) {
     949           0 :         return false;
     950             :       }
     951           0 :       if (!done) {
     952           0 :         ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Argument 7 of MessageEvent.initMessageEvent", "WindowProxy, MessagePort, ServiceWorker");
     953           0 :         return false;
     954             :       }
     955             :     }
     956             :   }
     957           0 :   binding_detail::AutoSequence<OwningNonNull<mozilla::dom::MessagePort>> arg7;
     958           0 :   if (args.hasDefined(7)) {
     959           0 :     if (args[7].isObject()) {
     960           0 :       JS::ForOfIterator iter(cx);
     961           0 :       if (!iter.init(args[7], JS::ForOfIterator::AllowNonIterable)) {
     962           0 :         return false;
     963             :       }
     964           0 :       if (!iter.valueIsIterable()) {
     965           0 :         ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 8 of MessageEvent.initMessageEvent");
     966           0 :         return false;
     967             :       }
     968           0 :       binding_detail::AutoSequence<OwningNonNull<mozilla::dom::MessagePort>> &arr = arg7;
     969           0 :       JS::Rooted<JS::Value> temp(cx);
     970             :       while (true) {
     971             :         bool done;
     972           0 :         if (!iter.next(&temp, &done)) {
     973           0 :           return false;
     974             :         }
     975           0 :         if (done) {
     976           0 :           break;
     977             :         }
     978           0 :         OwningNonNull<mozilla::dom::MessagePort>* slotPtr = arr.AppendElement(mozilla::fallible);
     979           0 :         if (!slotPtr) {
     980           0 :           JS_ReportOutOfMemory(cx);
     981           0 :           return false;
     982             :         }
     983           0 :         OwningNonNull<mozilla::dom::MessagePort>& slot = *slotPtr;
     984           0 :         if (temp.isObject()) {
     985             :           static_assert(IsRefcounted<mozilla::dom::MessagePort>::value, "We can only store refcounted classes.");{
     986           0 :             nsresult rv = UnwrapObject<prototypes::id::MessagePort, mozilla::dom::MessagePort>(&temp, slot);
     987           0 :             if (NS_FAILED(rv)) {
     988           0 :               ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Element of argument 8 of MessageEvent.initMessageEvent", "MessagePort");
     989           0 :               return false;
     990             :             }
     991             :           }
     992             :         } else {
     993           0 :           ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of argument 8 of MessageEvent.initMessageEvent");
     994           0 :           return false;
     995             :         }
     996           0 :       }
     997             :     } else {
     998           0 :       ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 8 of MessageEvent.initMessageEvent");
     999           0 :       return false;
    1000             :     }
    1001             :   } else {
    1002             :     /* Array is already empty; nothing to do */
    1003             :   }
    1004           0 :   self->InitMessageEvent(cx, NonNullHelper(Constify(arg0)), arg1, arg2, arg3, NonNullHelper(Constify(arg4)), NonNullHelper(Constify(arg5)), Constify(arg6), Constify(arg7));
    1005           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
    1006           0 :   args.rval().setUndefined();
    1007           0 :   return true;
    1008             : }
    1009             : 
    1010             : static const JSJitInfo initMessageEvent_methodinfo = {
    1011             :   { (JSJitGetterOp)initMessageEvent },
    1012             :   { prototypes::id::MessageEvent },
    1013             :   { PrototypeTraits<prototypes::id::MessageEvent>::Depth },
    1014             :   JSJitInfo::Method,
    1015             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
    1016             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
    1017             :   false,  /* isInfallible. False in setters. */
    1018             :   false,  /* isMovable.  Not relevant for setters. */
    1019             :   false, /* isEliminatable.  Not relevant for setters. */
    1020             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
    1021             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
    1022             :   false,  /* isTypedMethod.  Only relevant for methods. */
    1023             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
    1024             : };
    1025             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
    1026             : static_assert(0 < 2, "There is no slot for us");
    1027             : 
    1028             : static bool
    1029           0 : get_isTrusted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MessageEvent* self, JSJitGetterCallArgs args)
    1030             : {
    1031           0 :   bool result(self->IsTrusted());
    1032           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
    1033           0 :   args.rval().setBoolean(result);
    1034           0 :   return true;
    1035             : }
    1036             : 
    1037             : static const JSJitInfo isTrusted_getterinfo = {
    1038             :   { (JSJitGetterOp)get_isTrusted },
    1039             :   { prototypes::id::MessageEvent },
    1040             :   { PrototypeTraits<prototypes::id::MessageEvent>::Depth },
    1041             :   JSJitInfo::Getter,
    1042             :   JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
    1043             :   JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
    1044             :   true,  /* isInfallible. False in setters. */
    1045             :   true,  /* isMovable.  Not relevant for setters. */
    1046             :   true, /* isEliminatable.  Not relevant for setters. */
    1047             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
    1048             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
    1049             :   false,  /* isTypedMethod.  Only relevant for methods. */
    1050             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
    1051             : };
    1052             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
    1053             : static_assert(0 < 2, "There is no slot for us");
    1054             : 
    1055             : static bool
    1056           1 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
    1057             : {
    1058           1 :   mozilla::dom::MessageEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MessageEvent>(obj);
    1059             :   // We don't want to preserve if we don't have a wrapper, and we
    1060             :   // obviously can't preserve if we're not initialized.
    1061           1 :   if (self && self->GetWrapperPreserveColor()) {
    1062           0 :     PreserveWrapper(self);
    1063             :   }
    1064           1 :   return true;
    1065             : }
    1066             : 
    1067             : static void
    1068           0 : _finalize(js::FreeOp* fop, JSObject* obj)
    1069             : {
    1070           0 :   mozilla::dom::MessageEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MessageEvent>(obj);
    1071           0 :   if (self) {
    1072           0 :     ClearWrapper(self, self, obj);
    1073           0 :     AddForDeferredFinalization<mozilla::dom::MessageEvent>(self);
    1074             :   }
    1075           0 : }
    1076             : 
    1077             : static void
    1078           0 : _objectMoved(JSObject* obj, const JSObject* old)
    1079             : {
    1080           0 :   mozilla::dom::MessageEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MessageEvent>(obj);
    1081           0 :   if (self) {
    1082           0 :     UpdateWrapper(self, self, obj, old);
    1083             :   }
    1084           0 : }
    1085             : 
    1086             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
    1087             : #if defined(__clang__)
    1088             : #pragma clang diagnostic push
    1089             : #pragma clang diagnostic ignored "-Wmissing-braces"
    1090             : #endif
    1091             : static const JSFunctionSpec sMethods_specs[] = {
    1092             :   JS_FNSPEC("initMessageEvent", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&initMessageEvent_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
    1093             :   JS_FS_END
    1094             : };
    1095             : #if defined(__clang__)
    1096             : #pragma clang diagnostic pop
    1097             : #endif
    1098             : 
    1099             : 
    1100             : // Can't be const because the pref-enabled boolean needs to be writable
    1101             : static Prefable<const JSFunctionSpec> sMethods[] = {
    1102             :   { nullptr, &sMethods_specs[0] },
    1103             :   { nullptr, nullptr }
    1104             : };
    1105             : 
    1106             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
    1107             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
    1108             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
    1109             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
    1110             : 
    1111             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
    1112             : #if defined(__clang__)
    1113             : #pragma clang diagnostic push
    1114             : #pragma clang diagnostic ignored "-Wmissing-braces"
    1115             : #endif
    1116             : static const JSPropertySpec sAttributes_specs[] = {
    1117             :   { "data", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &data_getterinfo, nullptr, nullptr },
    1118             :   { "origin", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &origin_getterinfo, nullptr, nullptr },
    1119             :   { "lastEventId", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &lastEventId_getterinfo, nullptr, nullptr },
    1120             :   { "source", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &source_getterinfo, nullptr, nullptr },
    1121             :   { "ports", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &ports_getterinfo, nullptr, nullptr },
    1122             :   { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
    1123             : };
    1124             : #if defined(__clang__)
    1125             : #pragma clang diagnostic pop
    1126             : #endif
    1127             : 
    1128             : 
    1129             : // Can't be const because the pref-enabled boolean needs to be writable
    1130             : static Prefable<const JSPropertySpec> sAttributes[] = {
    1131             :   { nullptr, &sAttributes_specs[0] },
    1132             :   { nullptr, nullptr }
    1133             : };
    1134             : 
    1135             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
    1136             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
    1137             : static_assert(5 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
    1138             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
    1139             : 
    1140             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
    1141             : #if defined(__clang__)
    1142             : #pragma clang diagnostic push
    1143             : #pragma clang diagnostic ignored "-Wmissing-braces"
    1144             : #endif
    1145             : static const JSPropertySpec sUnforgeableAttributes_specs[] = {
    1146             :   { "isTrusted", JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericBindingGetter, &isTrusted_getterinfo, nullptr, nullptr },
    1147             :   { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
    1148             : };
    1149             : #if defined(__clang__)
    1150             : #pragma clang diagnostic pop
    1151             : #endif
    1152             : 
    1153             : 
    1154             : // Can't be const because the pref-enabled boolean needs to be writable
    1155             : static Prefable<const JSPropertySpec> sUnforgeableAttributes[] = {
    1156             :   { nullptr, &sUnforgeableAttributes_specs[0] },
    1157             :   { nullptr, nullptr }
    1158             : };
    1159             : 
    1160             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
    1161             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
    1162             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
    1163             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
    1164             : 
    1165             : 
    1166             : static uint16_t sNativeProperties_sortedPropertyIndices[7];
    1167             : static PropertyInfo sNativeProperties_propertyInfos[7];
    1168             : 
    1169             : static const NativePropertiesN<3> sNativeProperties = {
    1170             :   false, 0,
    1171             :   false, 0,
    1172             :   true,  0 /* sMethods */,
    1173             :   true,  1 /* sAttributes */,
    1174             :   false, 0,
    1175             :   true,  2 /* sUnforgeableAttributes */,
    1176             :   false, 0,
    1177             :   -1,
    1178             :   7,
    1179             :   sNativeProperties_sortedPropertyIndices,
    1180             :   {
    1181             :     { sMethods, &sNativeProperties_propertyInfos[0] },
    1182             :     { sAttributes, &sNativeProperties_propertyInfos[1] },
    1183             :     { sUnforgeableAttributes, &sNativeProperties_propertyInfos[6] }
    1184             :   }
    1185             : };
    1186             : static_assert(7 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
    1187             :     "We have a property info count that is oversized");
    1188             : 
    1189             : static bool
    1190           0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
    1191             : {
    1192           0 :   JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
    1193           0 :   JS::Rooted<JSObject*> obj(cx, &args.callee());
    1194           0 :   if (!args.isConstructing()) {
    1195             :     // XXXbz wish I could get the name from the callee instead of
    1196             :     // Adding more relocations
    1197           0 :     return ThrowConstructorWithoutNew(cx, "MessageEvent");
    1198             :   }
    1199             : 
    1200           0 :   GlobalObject global(cx, obj);
    1201           0 :   if (global.Failed()) {
    1202           0 :     return false;
    1203             :   }
    1204             : 
    1205           0 :   JS::Rooted<JSObject*> desiredProto(cx);
    1206           0 :   if (!GetDesiredProto(cx, args, &desiredProto)) {
    1207           0 :     return false;
    1208             :   }
    1209             : 
    1210           0 :   if (MOZ_UNLIKELY(args.length() < 1)) {
    1211           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "MessageEvent");
    1212             :   }
    1213           0 :   bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
    1214           0 :   binding_detail::FakeString arg0;
    1215           0 :   if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
    1216           0 :     return false;
    1217             :   }
    1218           0 :   RootedDictionary<binding_detail::FastMessageEventInit> arg1(cx);
    1219           0 :   if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue,  "Argument 2 of MessageEvent.constructor", false)) {
    1220           0 :     return false;
    1221             :   }
    1222           0 :   Maybe<JSAutoCompartment> ac;
    1223           0 :   if (objIsXray) {
    1224           0 :     obj = js::CheckedUnwrap(obj);
    1225           0 :     if (!obj) {
    1226           0 :       return false;
    1227             :     }
    1228           0 :     ac.emplace(cx, obj);
    1229           0 :     if (!JS_WrapObject(cx, &desiredProto)) {
    1230           0 :       return false;
    1231             :     }
    1232           0 :     if (!JS_WrapValue(cx, JS::MutableHandle<JS::Value>::fromMarkedLocation(&arg1.mData))) {
    1233           0 :       return false;
    1234             :     }
    1235             :   }
    1236           0 :   binding_detail::FastErrorResult rv;
    1237           0 :   auto result(StrongOrRawPtr<mozilla::dom::MessageEvent>(mozilla::dom::MessageEvent::Constructor(global, NonNullHelper(Constify(arg0)), Constify(arg1), rv)));
    1238           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
    1239           0 :     return false;
    1240             :   }
    1241           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
    1242             :   static_assert(!IsPointer<decltype(result)>::value,
    1243             :                 "NewObject implies that we need to keep the object alive with a strong reference.");
    1244           0 :   if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
    1245           0 :     MOZ_ASSERT(true || JS_IsExceptionPending(cx));
    1246           0 :     return false;
    1247             :   }
    1248           0 :   return true;
    1249             : }
    1250             : 
    1251             : static const js::ClassOps sInterfaceObjectClassOps = {
    1252             :     nullptr,               /* addProperty */
    1253             :     nullptr,               /* delProperty */
    1254             :     nullptr,               /* getProperty */
    1255             :     nullptr,               /* setProperty */
    1256             :     nullptr,               /* enumerate */
    1257             :     nullptr,               /* newEnumerate */
    1258             :     nullptr,               /* resolve */
    1259             :     nullptr,               /* mayResolve */
    1260             :     nullptr,               /* finalize */
    1261             :     _constructor, /* call */
    1262             :     nullptr,               /* hasInstance */
    1263             :     _constructor, /* construct */
    1264             :     nullptr,               /* trace */
    1265             : };
    1266             : 
    1267             : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
    1268             :   {
    1269             :     "Function",
    1270             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
    1271             :     &sInterfaceObjectClassOps,
    1272             :     JS_NULL_CLASS_SPEC,
    1273             :     JS_NULL_CLASS_EXT,
    1274             :     &sInterfaceObjectClassObjectOps
    1275             :   },
    1276             :   eInterface,
    1277             :   true,
    1278             :   prototypes::id::MessageEvent,
    1279             :   PrototypeTraits<prototypes::id::MessageEvent>::Depth,
    1280             :   sNativePropertyHooks,
    1281             :   "function MessageEvent() {\n    [native code]\n}",
    1282             :   EventBinding::GetConstructorObject
    1283             : };
    1284             : 
    1285             : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
    1286             :   {
    1287             :     "MessageEventPrototype",
    1288             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */),
    1289             :     JS_NULL_CLASS_OPS,
    1290             :     JS_NULL_CLASS_SPEC,
    1291             :     JS_NULL_CLASS_EXT,
    1292             :     JS_NULL_OBJECT_OPS
    1293             :   },
    1294             :   eInterfacePrototype,
    1295             :   false,
    1296             :   prototypes::id::MessageEvent,
    1297             :   PrototypeTraits<prototypes::id::MessageEvent>::Depth,
    1298             :   sNativePropertyHooks,
    1299             :   "[object MessageEventPrototype]",
    1300             :   EventBinding::GetProtoObject
    1301             : };
    1302             : 
    1303             : JSObject*
    1304           0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
    1305             : {
    1306           0 :   return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
    1307             : }
    1308             : 
    1309             : static const js::ClassOps sClassOps = {
    1310             :   _addProperty, /* addProperty */
    1311             :   nullptr,               /* delProperty */
    1312             :   nullptr,               /* getProperty */
    1313             :   nullptr,               /* setProperty */
    1314             :   nullptr,               /* enumerate */
    1315             :   nullptr, /* newEnumerate */
    1316             :   nullptr, /* resolve */
    1317             :   nullptr, /* mayResolve */
    1318             :   _finalize, /* finalize */
    1319             :   nullptr, /* call */
    1320             :   nullptr,               /* hasInstance */
    1321             :   nullptr,               /* construct */
    1322             :   nullptr, /* trace */
    1323             : };
    1324             : 
    1325             : static const js::ClassExtension sClassExtension = {
    1326             :   nullptr, /* weakmapKeyDelegateOp */
    1327             :   _objectMoved /* objectMovedOp */
    1328             : };
    1329             : 
    1330             : static const DOMJSClass sClass = {
    1331             :   { "MessageEvent",
    1332             :     JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(2) | JSCLASS_SKIP_NURSERY_FINALIZE,
    1333             :     &sClassOps,
    1334             :     JS_NULL_CLASS_SPEC,
    1335             :     &sClassExtension,
    1336             :     JS_NULL_OBJECT_OPS
    1337             :   },
    1338             :   { prototypes::id::Event, prototypes::id::MessageEvent, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
    1339             :   IsBaseOf<nsISupports, mozilla::dom::MessageEvent >::value,
    1340             :   sNativePropertyHooks,
    1341             :   FindAssociatedGlobalForNative<mozilla::dom::MessageEvent>::Get,
    1342             :   GetProtoObjectHandle,
    1343             :   GetCCParticipant<mozilla::dom::MessageEvent>::Get()
    1344             : };
    1345             : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
    1346             :               "Must have the right minimal number of reserved slots.");
    1347             : static_assert(2 >= 2,
    1348             :               "Must have enough reserved slots.");
    1349             : 
    1350             : const JSClass*
    1351           0 : GetJSClass()
    1352             : {
    1353           0 :   return sClass.ToJSClass();
    1354             : }
    1355             : 
    1356             : bool
    1357           0 : Wrap(JSContext* aCx, mozilla::dom::MessageEvent* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
    1358             : {
    1359             :   MOZ_ASSERT(static_cast<mozilla::dom::MessageEvent*>(aObject) ==
    1360             :              reinterpret_cast<mozilla::dom::MessageEvent*>(aObject),
    1361             :              "Multiple inheritance for mozilla::dom::MessageEvent is broken.");
    1362             :   MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) ==
    1363             :              reinterpret_cast<mozilla::dom::Event*>(aObject),
    1364             :              "Multiple inheritance for mozilla::dom::Event is broken.");
    1365           0 :   MOZ_ASSERT(ToSupportsIsCorrect(aObject));
    1366           0 :   MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
    1367           0 :   MOZ_ASSERT(!aCache->GetWrapper(),
    1368             :              "You should probably not be using Wrap() directly; use "
    1369             :              "GetOrCreateDOMReflector instead");
    1370             : 
    1371           0 :   MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
    1372             :              "nsISupports must be on our primary inheritance chain");
    1373             : 
    1374           0 :   JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
    1375           0 :   if (!global) {
    1376           0 :     return false;
    1377             :   }
    1378           0 :   MOZ_ASSERT(JS_IsGlobalObject(global));
    1379           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(global));
    1380             : 
    1381             :   // That might have ended up wrapping us already, due to the wonders
    1382             :   // of XBL.  Check for that, and bail out as needed.
    1383           0 :   aReflector.set(aCache->GetWrapper());
    1384           0 :   if (aReflector) {
    1385             : #ifdef DEBUG
    1386           0 :     binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
    1387             : #endif // DEBUG
    1388           0 :     return true;
    1389             :   }
    1390             : 
    1391           0 :   JSAutoCompartment ac(aCx, global);
    1392           0 :   JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
    1393           0 :   if (!canonicalProto) {
    1394           0 :     return false;
    1395             :   }
    1396           0 :   JS::Rooted<JSObject*> proto(aCx);
    1397           0 :   if (aGivenProto) {
    1398           0 :     proto = aGivenProto;
    1399             :     // Unfortunately, while aGivenProto was in the compartment of aCx
    1400             :     // coming in, we changed compartments to that of "parent" so may need
    1401             :     // to wrap the proto here.
    1402           0 :     if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
    1403           0 :       if (!JS_WrapObject(aCx, &proto)) {
    1404           0 :         return false;
    1405             :       }
    1406             :     }
    1407             :   } else {
    1408           0 :     proto = canonicalProto;
    1409             :   }
    1410             : 
    1411           0 :   BindingJSObjectCreator<mozilla::dom::MessageEvent> creator(aCx);
    1412           0 :   creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
    1413           0 :   if (!aReflector) {
    1414           0 :     return false;
    1415             :   }
    1416             : 
    1417           0 :   aCache->SetWrapper(aReflector);
    1418             : 
    1419             :   // Important: do unforgeable property setup after we have handed
    1420             :   // over ownership of the C++ object to obj as needed, so that if
    1421             :   // we fail and it ends up GCed it won't have problems in the
    1422             :   // finalizer trying to drop its ownership of the C++ object.
    1423             :   JS::Rooted<JSObject*> unforgeableHolder(aCx,
    1424           0 :     &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject());
    1425           0 :   if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) {
    1426           0 :     aCache->ReleaseWrapper(aObject);
    1427           0 :     aCache->ClearWrapper();
    1428           0 :     return false;
    1429             :   }
    1430           0 :   creator.InitializationSucceeded();
    1431             : 
    1432           0 :   MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
    1433             :              aCache->GetWrapperPreserveColor() == aReflector);
    1434             :   // If proto != canonicalProto, we have to preserve our wrapper;
    1435             :   // otherwise we won't be able to properly recreate it later, since
    1436             :   // we won't know what proto to use.  Note that we don't check
    1437             :   // aGivenProto here, since it's entirely possible (and even
    1438             :   // somewhat common) to have a non-null aGivenProto which is the
    1439             :   // same as canonicalProto.
    1440           0 :   if (proto != canonicalProto) {
    1441           0 :     PreserveWrapper(aObject);
    1442             :   }
    1443             : 
    1444           0 :   return true;
    1445             : }
    1446             : 
    1447             : // This may allocate too many slots, because we only really need
    1448             : // slots for our non-interface-typed members that we cache.  But
    1449             : // allocating slots only for those would make the slot index
    1450             : // computations much more complicated, so let's do this the simple
    1451             : // way for now.
    1452             : DEFINE_XRAY_EXPANDO_CLASS(static, sXrayExpandoObjectClass, 1);
    1453             : 
    1454             : const NativePropertyHooks sNativePropertyHooks[] = { {
    1455             :   nullptr,
    1456             :   nullptr,
    1457             :   nullptr,
    1458             :   { sNativeProperties.Upcast(), nullptr },
    1459             :   prototypes::id::MessageEvent,
    1460             :   constructors::id::MessageEvent,
    1461             :   EventBinding::sNativePropertyHooks,
    1462             :   &sXrayExpandoObjectClass
    1463             : } };
    1464             : 
    1465             : void
    1466           0 : ClearCachedPortsValue(mozilla::dom::MessageEvent* aObject)
    1467             : {
    1468             :   JSObject* obj;
    1469           0 :   obj = aObject->GetWrapper();
    1470           0 :   if (!obj) {
    1471           0 :     return;
    1472             :   }
    1473           0 :   js::SetReservedSlot(obj, (DOM_INSTANCE_RESERVED_SLOTS + 0), JS::UndefinedValue());
    1474           0 :   xpc::ClearXrayExpandoSlots(obj, (xpc::JSSLOT_EXPANDO_COUNT + 0));
    1475             : }
    1476             : 
    1477             : void
    1478           1 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
    1479             : {
    1480           1 :   JS::Handle<JSObject*> parentProto(EventBinding::GetProtoObjectHandle(aCx));
    1481           1 :   if (!parentProto) {
    1482           0 :     return;
    1483             :   }
    1484             : 
    1485           1 :   JS::Handle<JSObject*> constructorProto(EventBinding::GetConstructorObjectHandle(aCx));
    1486           1 :   if (!constructorProto) {
    1487           0 :     return;
    1488             :   }
    1489             : 
    1490             :   static bool sIdsInited = false;
    1491           1 :   if (!sIdsInited && NS_IsMainThread()) {
    1492           0 :     if (!InitIds(aCx, sNativeProperties.Upcast())) {
    1493           0 :       return;
    1494             :     }
    1495           0 :     sIdsInited = true;
    1496             :   }
    1497             : 
    1498           1 :   JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::MessageEvent);
    1499           1 :   JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::MessageEvent);
    1500           1 :   dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
    1501             :                               &sPrototypeClass.mBase, protoCache,
    1502             :                               constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr,
    1503             :                               interfaceCache,
    1504             :                               sNativeProperties.Upcast(),
    1505             :                               nullptr,
    1506             :                               "MessageEvent", aDefineOnGlobal,
    1507             :                               nullptr,
    1508           1 :                               false);
    1509             : 
    1510           2 :   JS::Rooted<JSObject*> unforgeableHolder(aCx);
    1511             :   {
    1512           2 :     JS::Rooted<JSObject*> holderProto(aCx, *protoCache);
    1513           1 :     unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto);
    1514           1 :     if (!unforgeableHolder) {
    1515           0 :       *protoCache = nullptr;
    1516           0 :       if (interfaceCache) {
    1517           0 :         *interfaceCache = nullptr;
    1518             :       }
    1519           0 :       return;
    1520             :     }
    1521             :   }
    1522             : 
    1523           1 :   if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) {
    1524           0 :     *protoCache = nullptr;
    1525           0 :     if (interfaceCache) {
    1526           0 :       *interfaceCache = nullptr;
    1527             :     }
    1528           0 :     return;
    1529             :   }
    1530             : 
    1531           1 :   if (*protoCache) {
    1532           1 :     js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE,
    1533           2 :                         JS::ObjectValue(*unforgeableHolder));
    1534             :   }
    1535             : }
    1536             : 
    1537             : JS::Handle<JSObject*>
    1538           0 : GetProtoObjectHandle(JSContext* aCx)
    1539             : {
    1540             :   /* Get the interface prototype object for this class.  This will create the
    1541             :      object as needed. */
    1542           0 :   bool aDefineOnGlobal = true;
    1543             : 
    1544             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
    1545           0 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
    1546           0 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
    1547           0 :     return nullptr;
    1548             :   }
    1549             : 
    1550             :   /* Check to see whether the interface objects are already installed */
    1551           0 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
    1552           0 :   if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::MessageEvent)) {
    1553           0 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
    1554           0 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
    1555             :   }
    1556             : 
    1557             :   /*
    1558             :    * The object might _still_ be null, but that's OK.
    1559             :    *
    1560             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
    1561             :    * traced by TraceProtoAndIfaceCache() and its contents are never
    1562             :    * changed after they have been set.
    1563             :    *
    1564             :    * Calling address() avoids the read read barrier that does gray
    1565             :    * unmarking, but it's not possible for the object to be gray here.
    1566             :    */
    1567             : 
    1568           0 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::MessageEvent);
    1569           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
    1570           0 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
    1571             : }
    1572             : 
    1573             : JS::Handle<JSObject*>
    1574           1 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
    1575             : {
    1576             :   /* Get the interface object for this class.  This will create the object as
    1577             :      needed. */
    1578             : 
    1579             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
    1580           1 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
    1581           1 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
    1582           0 :     return nullptr;
    1583             :   }
    1584             : 
    1585             :   /* Check to see whether the interface objects are already installed */
    1586           1 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
    1587           1 :   if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::MessageEvent)) {
    1588           2 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
    1589           1 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
    1590             :   }
    1591             : 
    1592             :   /*
    1593             :    * The object might _still_ be null, but that's OK.
    1594             :    *
    1595             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
    1596             :    * traced by TraceProtoAndIfaceCache() and its contents are never
    1597             :    * changed after they have been set.
    1598             :    *
    1599             :    * Calling address() avoids the read read barrier that does gray
    1600             :    * unmarking, but it's not possible for the object to be gray here.
    1601             :    */
    1602             : 
    1603           1 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::MessageEvent);
    1604           1 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
    1605           1 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
    1606             : }
    1607             : 
    1608             : JSObject*
    1609           1 : GetConstructorObject(JSContext* aCx)
    1610             : {
    1611           1 :   return GetConstructorObjectHandle(aCx);
    1612             : }
    1613             : 
    1614             : } // namespace MessageEventBinding
    1615             : 
    1616             : 
    1617             : 
    1618             : } // namespace dom
    1619             : } // namespace mozilla

Generated by: LCOV version 1.13