Bug 1310967 - Update MessageEvent to the latest spec, r=smaug
☠☠ backed out by 86858f4eb396 ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 18 Oct 2016 18:19:59 +0200
changeset 318500 133feae493304107a70519eb061da16c4eaf3334
parent 318451 bc91be30f2aa9c8b2ebde507da902808c8647181
child 318501 dac69b2b8d26fff4e56703c494889e64b464b088
push id20725
push userphilringnalda@gmail.com
push dateThu, 20 Oct 2016 01:36:01 +0000
treeherderfx-team@998ad5a74da8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1310967
milestone52.0a1
Bug 1310967 - Update MessageEvent to the latest spec, r=smaug
dom/base/EventSource.cpp
dom/base/PostMessageEvent.cpp
dom/base/WebSocket.cpp
dom/base/nsDOMDataChannel.cpp
dom/broadcastchannel/BroadcastChannelChild.cpp
dom/events/MessageEvent.cpp
dom/events/MessageEvent.h
dom/messagechannel/MessagePort.cpp
dom/presentation/PresentationConnection.cpp
dom/webidl/MessageEvent.webidl
dom/workers/WorkerPrivate.cpp
--- a/dom/base/EventSource.cpp
+++ b/dom/base/EventSource.cpp
@@ -1076,17 +1076,18 @@ EventSource::DispatchAllMessageEvents()
     }
 
     // create an event that uses the MessageEvent interface,
     // which does not bubble, is not cancelable, and has no default action
 
     RefPtr<MessageEvent> event = new MessageEvent(this, nullptr, nullptr);
 
     event->InitMessageEvent(nullptr, message->mEventName, false, false, jsData,
-                            mOrigin, message->mLastEventID, nullptr, nullptr);
+                            mOrigin, message->mLastEventID, nullptr,
+                            Sequence<OwningNonNull<MessagePort>>());
     event->SetTrusted(true);
 
     rv = DispatchDOMEvent(nullptr, static_cast<Event*>(event), nullptr,
                           nullptr);
     if (NS_FAILED(rv)) {
       NS_WARNING("Failed to dispatch the message event!!!");
       return;
     }
--- a/dom/base/PostMessageEvent.cpp
+++ b/dom/base/PostMessageEvent.cpp
@@ -142,17 +142,18 @@ PostMessageEvent::Run()
 
 
   Nullable<WindowProxyOrMessagePort> source;
   source.SetValue().SetAsWindowProxy() = mSource ? mSource->AsOuter() : nullptr;
 
   event->InitMessageEvent(nullptr, NS_LITERAL_STRING("message"),
                           false /*non-bubbling */, false /*cancelable */,
                           messageData, mCallerOrigin,
-                          EmptyString(), source, nullptr);
+                          EmptyString(), source,
+                          Sequence<OwningNonNull<MessagePort>>());
 
   nsTArray<RefPtr<MessagePort>> ports = TakeTransferredPorts();
   event->SetPorts(Move(ports));
 
   // We can't simply call dispatchEvent on the window because doing so ends
   // up flipping the trusted bit on the event, and we don't want that to
   // happen because then untrusted content can call postMessage on a chrome
   // window if it can get a reference to it.
--- a/dom/base/WebSocket.cpp
+++ b/dom/base/WebSocket.cpp
@@ -2004,17 +2004,17 @@ WebSocket::CreateAndDispatchMessageEvent
 
   // create an event that uses the MessageEvent interface,
   // which does not bubble, is not cancelable, and has no default action
 
   RefPtr<MessageEvent> event = new MessageEvent(this, nullptr, nullptr);
 
   event->InitMessageEvent(nullptr, NS_LITERAL_STRING("message"), false, false,
                           jsData, mImpl->mUTF16Origin, EmptyString(), nullptr,
-                          nullptr);
+                          Sequence<OwningNonNull<MessagePort>>());
   event->SetTrusted(true);
 
   return DispatchDOMEvent(nullptr, static_cast<Event*>(event), nullptr,
                           nullptr);
 }
 
 nsresult
 WebSocket::CreateAndDispatchCloseEvent(bool aWasClean,
--- a/dom/base/nsDOMDataChannel.cpp
+++ b/dom/base/nsDOMDataChannel.cpp
@@ -400,17 +400,18 @@ nsDOMDataChannel::DoOnMessageAvailable(c
     NS_ENSURE_TRUE(jsString, NS_ERROR_FAILURE);
 
     jsData.setString(jsString);
   }
 
   RefPtr<MessageEvent> event = new MessageEvent(this, nullptr, nullptr);
 
   event->InitMessageEvent(nullptr, NS_LITERAL_STRING("message"), false, false,
-                          jsData, mOrigin, EmptyString(), nullptr, nullptr);
+                          jsData, mOrigin, EmptyString(), nullptr,
+                          Sequence<OwningNonNull<MessagePort>>());
   event->SetTrusted(true);
 
   LOG(("%p(%p): %s - Dispatching\n",this,(void*)mDataChannel,__FUNCTION__));
   rv = DispatchDOMEvent(nullptr, static_cast<Event*>(event), nullptr, nullptr);
   if (NS_FAILED(rv)) {
     NS_WARNING("Failed to dispatch the message event!!!");
   }
   return rv;
--- a/dom/broadcastchannel/BroadcastChannelChild.cpp
+++ b/dom/broadcastchannel/BroadcastChannelChild.cpp
@@ -101,17 +101,17 @@ BroadcastChannelChild::RecvNotify(const 
       rv.SuppressException();
       return true;
     }
   }
 
   RootedDictionary<MessageEventInit> init(cx);
   init.mBubbles = false;
   init.mCancelable = false;
-  init.mOrigin.Construct(mOrigin);
+  init.mOrigin = mOrigin;
   init.mData = value;
 
   ErrorResult rv;
   RefPtr<MessageEvent> event =
     MessageEvent::Constructor(mBC, NS_LITERAL_STRING("message"), init, rv);
   if (NS_WARN_IF(rv.Failed())) {
     rv.SuppressException();
     return true;
--- a/dom/events/MessageEvent.cpp
+++ b/dom/events/MessageEvent.cpp
@@ -41,17 +41,16 @@ NS_INTERFACE_MAP_END_INHERITING(Event)
 NS_IMPL_ADDREF_INHERITED(MessageEvent, Event)
 NS_IMPL_RELEASE_INHERITED(MessageEvent, Event)
 
 MessageEvent::MessageEvent(EventTarget* aOwner,
                            nsPresContext* aPresContext,
                            WidgetEvent* aEvent)
   : Event(aOwner, aPresContext, aEvent)
   , mData(JS::UndefinedValue())
-  , mPortsSet(false)
 {
 }
 
 MessageEvent::~MessageEvent()
 {
   mData.setUndefined();
   DropJSObjects(this);
 }
@@ -116,50 +115,42 @@ MessageEvent::Constructor(EventTarget* a
   event->InitEvent(aType, aParam.mBubbles, aParam.mCancelable);
   bool trusted = event->Init(aEventTarget);
   event->SetTrusted(trusted);
 
   event->mData = aParam.mData;
 
   mozilla::HoldJSObjects(event.get());
 
-  if (aParam.mOrigin.WasPassed()) {
-    event->mOrigin = aParam.mOrigin.Value();
-  }
-
-  if (aParam.mLastEventId.WasPassed()) {
-    event->mLastEventId = aParam.mLastEventId.Value();
-  }
+  event->mOrigin = aParam.mOrigin;
+  event->mLastEventId = aParam.mLastEventId;
 
   if (!aParam.mSource.IsNull()) {
     if (aParam.mSource.Value().IsWindow()) {
       event->mWindowSource = aParam.mSource.Value().GetAsWindow()->AsInner();
     } else {
       event->mPortSource = aParam.mSource.Value().GetAsMessagePort();
     }
 
     MOZ_ASSERT(event->mWindowSource || event->mPortSource);
   }
 
-  if (aParam.mPorts.WasPassed() && !aParam.mPorts.Value().IsNull()) {
-    event->mPorts.AppendElements(aParam.mPorts.Value().Value());
-    event->mPortsSet = true;
-  }
+  event->mPorts.AppendElements(aParam.mPorts);
 
   return event.forget();
 }
 
 void
 MessageEvent::InitMessageEvent(JSContext* aCx, const nsAString& aType,
                                bool aCanBubble, bool aCancelable,
                                JS::Handle<JS::Value> aData,
                                const nsAString& aOrigin,
                                const nsAString& aLastEventId,
                                const Nullable<WindowProxyOrMessagePort>& aSource,
-                               const Nullable<Sequence<OwningNonNull<MessagePort>>>& aPorts)
+                               const Sequence<OwningNonNull<MessagePort>>& aPorts)
 {
   Event::InitEvent(aType, aCanBubble, aCancelable);
   mData = aData;
   mozilla::HoldJSObjects(this);
   mOrigin = aOrigin;
   mLastEventId = aLastEventId;
 
   mWindowSource = nullptr;
@@ -170,43 +161,31 @@ MessageEvent::InitMessageEvent(JSContext
       auto* windowProxy = aSource.Value().GetAsWindowProxy();
       mWindowSource = windowProxy ? windowProxy->GetCurrentInnerWindow() : nullptr;
     } else {
       mPortSource = &aSource.Value().GetAsMessagePort();
     }
   }
 
   mPorts.Clear();
-  mPortsSet = false;
-
-  if (!aPorts.IsNull()) {
-    mPorts.AppendElements(aPorts.Value());
-    mPortsSet = true;
-  }
-
+  mPorts.AppendElements(aPorts);
   MessageEventBinding::ClearCachedPortsValue(this);
 }
 
 void
-MessageEvent::GetPorts(Nullable<nsTArray<RefPtr<MessagePort>>>& aPorts)
+MessageEvent::GetPorts(nsTArray<RefPtr<MessagePort>>& aPorts)
 {
-  if (!mPortsSet) {
-    aPorts.SetNull();
-    return;
-  }
-
-  aPorts.SetValue(mPorts);
+  aPorts = mPorts;
 }
 
 void
 MessageEvent::SetPorts(nsTArray<RefPtr<MessagePort>>&& aPorts)
 {
-  MOZ_ASSERT(mPorts.IsEmpty() && !mPortsSet);
+  MOZ_ASSERT(mPorts.IsEmpty());
   mPorts = Move(aPorts);
-  mPortsSet = true;
 }
 
 void
 MessageEvent::SetSource(mozilla::dom::MessagePort* aPort)
 {
   mPortSource = aPort;
 }
 
--- a/dom/events/MessageEvent.h
+++ b/dom/events/MessageEvent.h
@@ -42,17 +42,17 @@ public:
   virtual JSObject* WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
   void GetData(JSContext* aCx, JS::MutableHandle<JS::Value> aData,
                ErrorResult& aRv);
   void GetOrigin(nsAString&) const;
   void GetLastEventId(nsAString&) const;
   void GetSource(Nullable<OwningWindowProxyOrMessagePort>& aValue) const;
 
-  void GetPorts(Nullable<nsTArray<RefPtr<MessagePort>>>& aPorts);
+  void GetPorts(nsTArray<RefPtr<MessagePort>>& aPorts);
 
   void SetPorts(nsTArray<RefPtr<MessagePort>>&& aPorts);
 
   // Non WebIDL methods
   void SetSource(mozilla::dom::MessagePort* aPort);
 
   void SetSource(nsPIDOMWindowInner* aWindow)
   {
@@ -70,28 +70,27 @@ public:
               const nsAString& aType,
               const MessageEventInit& aEventInit,
               ErrorResult& aRv);
 
   void InitMessageEvent(JSContext* aCx, const nsAString& aType, bool aCanBubble,
                         bool aCancelable, JS::Handle<JS::Value> aData,
                         const nsAString& aOrigin, const nsAString& aLastEventId,
                         const Nullable<WindowProxyOrMessagePort>& aSource,
-                        const Nullable<Sequence<OwningNonNull<MessagePort>>>& aPorts);
+                        const Sequence<OwningNonNull<MessagePort>>& aPorts);
 
 protected:
   ~MessageEvent();
 
 private:
   JS::Heap<JS::Value> mData;
   nsString mOrigin;
   nsString mLastEventId;
   RefPtr<nsPIDOMWindowInner> mWindowSource;
   RefPtr<MessagePort> mPortSource;
 
   nsTArray<RefPtr<MessagePort>> mPorts;
-  bool mPortsSet;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_MessageEvent_h_
--- a/dom/messagechannel/MessagePort.cpp
+++ b/dom/messagechannel/MessagePort.cpp
@@ -132,17 +132,18 @@ private:
     nsCOMPtr<mozilla::dom::EventTarget> eventTarget =
       do_QueryInterface(mPort->GetOwner());
     RefPtr<MessageEvent> event =
       new MessageEvent(eventTarget, nullptr, nullptr);
 
     event->InitMessageEvent(nullptr, NS_LITERAL_STRING("message"),
                             false /* non-bubbling */,
                             false /* cancelable */, value, EmptyString(),
-                            EmptyString(), nullptr, nullptr);
+                            EmptyString(), nullptr,
+                            Sequence<OwningNonNull<MessagePort>>());
     event->SetTrusted(true);
     event->SetSource(mPort);
 
     nsTArray<RefPtr<MessagePort>> ports = mData->TakeTransferredPorts();
     event->SetPorts(Move(ports));
 
     bool dummy;
     mPort->DispatchEvent(static_cast<dom::Event*>(event.get()), &dummy);
--- a/dom/presentation/PresentationConnection.cpp
+++ b/dom/presentation/PresentationConnection.cpp
@@ -575,17 +575,18 @@ PresentationConnection::DispatchMessageE
     return rv;
   }
 
   RefPtr<MessageEvent> messageEvent = new MessageEvent(this, nullptr, nullptr);
 
   messageEvent->InitMessageEvent(nullptr,
                                  NS_LITERAL_STRING("message"),
                                  false, false, aData, origin,
-                                 EmptyString(), nullptr, nullptr);
+                                 EmptyString(), nullptr,
+                                 Sequence<OwningNonNull<MessagePort>>());
   messageEvent->SetTrusted(true);
 
   RefPtr<AsyncEventDispatcher> asyncDispatcher =
     new AsyncEventDispatcher(this, static_cast<Event*>(messageEvent));
   return asyncDispatcher->PostDOMEvent();
 }
 
 nsresult
--- a/dom/webidl/MessageEvent.webidl
+++ b/dom/webidl/MessageEvent.webidl
@@ -36,23 +36,23 @@ interface MessageEvent : Event {
   readonly attribute (WindowProxy or MessagePort)? source;
 
   /**
    * Initializes this event with the given data, in a manner analogous to
    * the similarly-named method on the nsIDOMEvent interface, also setting the
    * data, origin, source, and lastEventId attributes of this appropriately.
    */
   [Pure, Cached, Frozen]
-  readonly attribute sequence<MessagePort>? ports;
+  readonly attribute sequence<MessagePort> ports;
 
   void initMessageEvent(DOMString type, boolean bubbles, boolean cancelable,
                         any data, DOMString origin, DOMString lastEventId,
                         (WindowProxy or MessagePort)? source,
-                        sequence<MessagePort>? ports);
+                        sequence<MessagePort> ports);
 };
 
 dictionary MessageEventInit : EventInit {
-  any data;
-  DOMString origin;
-  DOMString lastEventId;
+  any data = null;
+  DOMString origin = "";
+  DOMString lastEventId = "";
   (Window or MessagePort)? source = null;
-  sequence<MessagePort>? ports;
+  sequence<MessagePort> ports = [];
 };
--- a/dom/workers/WorkerPrivate.cpp
+++ b/dom/workers/WorkerPrivate.cpp
@@ -717,17 +717,17 @@ public:
       event->InitMessageEvent(nullptr,
                               NS_LITERAL_STRING("message"),
                               false /* non-bubbling */,
                               false /* cancelable */,
                               messageData,
                               EmptyString(),
                               EmptyString(),
                               nullptr,
-                              nullptr);
+                              Sequence<OwningNonNull<MessagePort>>());
       event->SetPorts(Move(ports));
       domEvent = do_QueryObject(event);
     }
 
     domEvent->SetTrusted(true);
 
     nsEventStatus dummy = nsEventStatus_eIgnore;
     aTarget->DispatchDOMEvent(nullptr, domEvent, nullptr, &dummy);
@@ -809,17 +809,17 @@ private:
     event->InitMessageEvent(nullptr,
                             NS_LITERAL_STRING("message"),
                             false, // canBubble
                             true, // cancelable
                             data,
                             EmptyString(),
                             EmptyString(),
                             nullptr,
-                            nullptr);
+                            Sequence<OwningNonNull<MessagePort>>());
     event->SetTrusted(true);
 
     nsCOMPtr<nsIDOMEvent> domEvent = do_QueryObject(event);
     nsEventStatus status = nsEventStatus_eIgnore;
     globalScope->DispatchDOMEvent(nullptr, domEvent, nullptr, &status);
     return true;
   }
 };