Bug 1312705 - Update ServiceWorkerMessageEvent to the latest version of the spec, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 25 Oct 2016 18:22:46 +0200
changeset 362256 12bd9aa9f2c7ee3999acc58fa41783d863cc8308
parent 362255 25e1e4d63f116039124613519b0b516e154f236d
child 362257 f1deb434e0c789b436d64c46bc64fc5208c7df3f
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-beta@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1312705
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1312705 - Update ServiceWorkerMessageEvent to the latest version of the spec, r=smaug
dom/webidl/ServiceWorkerMessageEvent.webidl
dom/workers/ServiceWorkerClient.cpp
dom/workers/ServiceWorkerMessageEvent.cpp
dom/workers/ServiceWorkerMessageEvent.h
--- a/dom/webidl/ServiceWorkerMessageEvent.webidl
+++ b/dom/webidl/ServiceWorkerMessageEvent.webidl
@@ -31,19 +31,19 @@ interface ServiceWorkerMessageEvent : Ev
   /**
    * The service worker or port which originated this event.
    * FIXME: Use SameOject after IDL spec is updated
    * https://bugzilla.mozilla.org/show_bug.cgi?id=1196097
    */
   [Constant] readonly attribute (ServiceWorker or MessagePort)? source;
 
   [Constant, Cached, Frozen]
-  readonly attribute sequence<MessagePort>? ports;
+  readonly attribute sequence<MessagePort> ports;
 };
 
 dictionary ServiceWorkerMessageEventInit : EventInit
 {
-  any data;
-  DOMString origin;
-  DOMString lastEventId;
-  (ServiceWorker or MessagePort)? source;
-  sequence<MessagePort>? ports;
+  any data = null;
+  DOMString origin = "";
+  DOMString lastEventId = "";
+  (ServiceWorker or MessagePort)? source = null;
+  sequence<MessagePort> ports = [];
 };
--- a/dom/workers/ServiceWorkerClient.cpp
+++ b/dom/workers/ServiceWorkerClient.cpp
@@ -153,27 +153,21 @@ private:
       MOZ_ASSERT(!isSystemPrincipal);
     }
 
     init.mData = messageData;
     nsAutoCString origin;
     if (principal && !isNullPrincipal && !isSystemPrincipal) {
       principal->GetOrigin(origin);
     }
-    init.mOrigin.Construct(NS_ConvertUTF8toUTF16(origin));
-    init.mLastEventId.Construct(EmptyString());
-    init.mPorts.Construct();
-    init.mPorts.Value().SetNull();
+    init.mOrigin = NS_ConvertUTF8toUTF16(origin);
 
     RefPtr<ServiceWorker> serviceWorker = aTargetContainer->GetController();
-    init.mSource.Construct();
     if (serviceWorker) {
-      init.mSource.Value().SetValue().SetAsServiceWorker() = serviceWorker;
-    } else {
-      init.mSource.Value().SetNull();
+      init.mSource.SetValue().SetAsServiceWorker() = serviceWorker;
     }
 
     RefPtr<ServiceWorkerMessageEvent> event =
       ServiceWorkerMessageEvent::Constructor(aTargetContainer,
                                              NS_LITERAL_STRING("message"), init, rv);
 
     nsTArray<RefPtr<MessagePort>> ports = TakeTransferredPorts();
     event->SetPorts(Move(ports));
--- a/dom/workers/ServiceWorkerMessageEvent.cpp
+++ b/dom/workers/ServiceWorkerMessageEvent.cpp
@@ -41,17 +41,16 @@ NS_INTERFACE_MAP_END_INHERITING(Event)
 NS_IMPL_ADDREF_INHERITED(ServiceWorkerMessageEvent, Event)
 NS_IMPL_RELEASE_INHERITED(ServiceWorkerMessageEvent, Event)
 
 ServiceWorkerMessageEvent::ServiceWorkerMessageEvent(EventTarget* aOwner,
                                                      nsPresContext* aPresContext,
                                                      WidgetEvent* aEvent)
   : Event(aOwner, aPresContext, aEvent)
   , mData(JS::UndefinedValue())
-  , mPortsSet(false)
 {
   mozilla::HoldJSObjects(this);
 }
 
 ServiceWorkerMessageEvent::~ServiceWorkerMessageEvent()
 {
   mData.setUndefined();
   DropJSObjects(this);
@@ -105,32 +104,26 @@ ServiceWorkerMessageEvent::SetSource(moz
 
 void
 ServiceWorkerMessageEvent::SetSource(workers::ServiceWorker* aServiceWorker)
 {
   mServiceWorker = aServiceWorker;
 }
 
 void
-ServiceWorkerMessageEvent::GetPorts(Nullable<nsTArray<RefPtr<MessagePort>>>& aPorts)
+ServiceWorkerMessageEvent::GetPorts(nsTArray<RefPtr<MessagePort>>& aPorts)
 {
-  if (!mPortsSet) {
-    aPorts.SetNull();
-    return;
-  }
-
-  aPorts.SetValue(mPorts);
+  aPorts = mPorts;
 }
 
 void
 ServiceWorkerMessageEvent::SetPorts(nsTArray<RefPtr<MessagePort>>&& aPorts)
 {
-  MOZ_ASSERT(mPorts.IsEmpty() && !mPortsSet);
+  MOZ_ASSERT(mPorts.IsEmpty());
   mPorts = Move(aPorts);
-  mPortsSet = true;
 }
 
 /* static */ already_AddRefed<ServiceWorkerMessageEvent>
 ServiceWorkerMessageEvent::Constructor(const GlobalObject& aGlobal,
                                        const nsAString& aType,
                                        const ServiceWorkerMessageEventInit& aParam,
                                        ErrorResult& aRv)
 {
@@ -148,38 +141,26 @@ ServiceWorkerMessageEvent::Constructor(E
     new ServiceWorkerMessageEvent(aEventTarget, nullptr, nullptr);
 
   event->InitEvent(aType, aParam.mBubbles, aParam.mCancelable);
 
   bool trusted = event->Init(aEventTarget);
   event->SetTrusted(trusted);
 
   event->mData = aParam.mData;
+  event->mOrigin = aParam.mOrigin;
+  event->mLastEventId = aParam.mLastEventId;
 
-  if (aParam.mOrigin.WasPassed()) {
-    event->mOrigin = aParam.mOrigin.Value();
-  }
-
-  if (aParam.mLastEventId.WasPassed()) {
-    event->mLastEventId = aParam.mLastEventId.Value();
+  if (!aParam.mSource.IsNull()) {
+    if (aParam.mSource.Value().IsServiceWorker()) {
+      event->mServiceWorker = aParam.mSource.Value().GetAsServiceWorker();
+    } else if (aParam.mSource.Value().IsMessagePort()) {
+      event->mMessagePort = aParam.mSource.Value().GetAsMessagePort();
+    }
   }
 
-  if (aParam.mSource.WasPassed() && !aParam.mSource.Value().IsNull()) {
-
-    if (aParam.mSource.Value().Value().IsServiceWorker()) {
-      event->mServiceWorker = aParam.mSource.Value().Value().GetAsServiceWorker();
-    } else {
-      event->mMessagePort = aParam.mSource.Value().Value().GetAsMessagePort();
-    }
-
-    MOZ_ASSERT(event->mServiceWorker || event->mMessagePort);
-  }
-
-  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();
 }
 
 } // namespace dom
 } // namespace mozilla
--- a/dom/workers/ServiceWorkerMessageEvent.h
+++ b/dom/workers/ServiceWorkerMessageEvent.h
@@ -41,17 +41,17 @@ public:
                ErrorResult& aRv) const;
 
   void GetOrigin(nsAString& aOrigin) const;
 
   void GetLastEventId(nsAString& aLastEventId) const;
 
   void GetSource(Nullable<OwningServiceWorkerOrMessagePort>& aValue) const;
 
-  void GetPorts(Nullable<nsTArray<RefPtr<MessagePort>>>& aPorts);
+  void GetPorts(nsTArray<RefPtr<MessagePort>>& aPorts);
 
   void SetSource(mozilla::dom::MessagePort* aPort);
 
   void SetSource(workers::ServiceWorker* aServiceWorker);
 
   void SetPorts(nsTArray<RefPtr<MessagePort>>&& aPorts);
 
   static already_AddRefed<ServiceWorkerMessageEvent>
@@ -70,18 +70,16 @@ protected:
   ~ServiceWorkerMessageEvent();
 
 private:
   JS::Heap<JS::Value> mData;
   nsString mOrigin;
   nsString mLastEventId;
   RefPtr<workers::ServiceWorker> mServiceWorker;
   RefPtr<MessagePort> mMessagePort;
-
   nsTArray<RefPtr<MessagePort>> mPorts;
-  bool mPortsSet;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif /* mozilla_dom_workers_serviceworkermessageevent_h__ */