Backed out changeset efa6394f2a4a (bug 1453925) for mochitest failures on test_broadcastchannel_worker_alive.html. a=backout
authorCosmin Sabou <csabou@mozilla.com>
Sun, 15 Apr 2018 02:45:33 +0300
changeset 413383 a79d460bf2a33fd79c6646236f9c4df78e66e7b7
parent 413382 a0c455e036df741556d695cf46baeacc581c0c58
child 413387 d333f10ea6e13fbeb9d1294f07885b69a5487b79
child 413444 f291b07fa1f869fd3f9af9f5fe940d47b842edcf
push id33846
push usercsabou@mozilla.com
push dateSat, 14 Apr 2018 23:46:03 +0000
treeherdermozilla-central@a79d460bf2a3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbackout
bugs1453925
milestone61.0a1
backs outefa6394f2a4a47735c03f5c9b1953665c17b555e
first release with
nightly linux32
a79d460bf2a3 / 61.0a1 / 20180415000402 / files
nightly linux64
a79d460bf2a3 / 61.0a1 / 20180415000402 / files
nightly mac
a79d460bf2a3 / 61.0a1 / 20180415000402 / files
nightly win32
a79d460bf2a3 / 61.0a1 / 20180415000402 / files
nightly win64
a79d460bf2a3 / 61.0a1 / 20180415000402 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out changeset efa6394f2a4a (bug 1453925) for mochitest failures on test_broadcastchannel_worker_alive.html. a=backout
dom/broadcastchannel/BroadcastChannel.cpp
dom/broadcastchannel/tests/test_event_listener_leaks.html
--- a/dom/broadcastchannel/BroadcastChannel.cpp
+++ b/dom/broadcastchannel/BroadcastChannel.cpp
@@ -120,16 +120,58 @@ public:
 
 private:
   RefPtr<ThreadSafeWorkerRef> mWorkerRef;
   nsACString& mOrigin;
   PrincipalInfo& mPrincipalInfo;
   ErrorResult& mRv;
 };
 
+class BCPostMessageRunnable final : public nsIRunnable,
+                                    public nsICancelableRunnable
+{
+public:
+  NS_DECL_ISUPPORTS
+
+  BCPostMessageRunnable(BroadcastChannelChild* aActor,
+                        BroadcastChannelMessage* aData)
+    : mActor(aActor)
+    , mData(aData)
+  {
+    MOZ_ASSERT(mActor);
+  }
+
+  NS_IMETHOD Run() override
+  {
+    MOZ_ASSERT(mActor);
+    if (mActor->IsActorDestroyed()) {
+      return NS_OK;
+    }
+
+    ClonedMessageData message;
+    mData->BuildClonedMessageDataForBackgroundChild(mActor->Manager(), message);
+    mActor->SendPostMessage(message);
+    return NS_OK;
+  }
+
+  nsresult Cancel() override
+  {
+    mActor = nullptr;
+    return NS_OK;
+  }
+
+private:
+  ~BCPostMessageRunnable() {}
+
+  RefPtr<BroadcastChannelChild> mActor;
+  RefPtr<BroadcastChannelMessage> mData;
+};
+
+NS_IMPL_ISUPPORTS(BCPostMessageRunnable, nsICancelableRunnable, nsIRunnable)
+
 class CloseRunnable final : public nsIRunnable,
                             public nsICancelableRunnable
 {
 public:
   NS_DECL_ISUPPORTS
 
   explicit CloseRunnable(BroadcastChannel* aBC)
     : mBC(aBC)
@@ -351,28 +393,45 @@ void
 BroadcastChannel::PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
                               ErrorResult& aRv)
 {
   if (mState != StateActive) {
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return;
   }
 
+  PostMessageInternal(aCx, aMessage, aRv);
+}
+
+void
+BroadcastChannel::PostMessageInternal(JSContext* aCx,
+                                      JS::Handle<JS::Value> aMessage,
+                                      ErrorResult& aRv)
+{
   RefPtr<BroadcastChannelMessage> data = new BroadcastChannelMessage();
 
   data->Write(aCx, aMessage, aRv);
   if (NS_WARN_IF(aRv.Failed())) {
     return;
   }
 
+  PostMessageData(data);
+}
+
+void
+BroadcastChannel::PostMessageData(BroadcastChannelMessage* aData)
+{
   RemoveDocFromBFCache();
 
-  ClonedMessageData message;
-  data->BuildClonedMessageDataForBackgroundChild(mActor->Manager(), message);
-  mActor->SendPostMessage(message);
+  RefPtr<BCPostMessageRunnable> runnable =
+    new BCPostMessageRunnable(mActor, aData);
+
+  if (NS_FAILED(NS_DispatchToCurrentThread(runnable))) {
+    NS_WARNING("Failed to dispatch to the current thread!");
+  }
 }
 
 void
 BroadcastChannel::Close()
 {
   if (mState != StateActive) {
     return;
   }
--- a/dom/broadcastchannel/tests/test_event_listener_leaks.html
+++ b/dom/broadcastchannel/tests/test_event_listener_leaks.html
@@ -18,20 +18,20 @@
 // exercise the leak condition.
 let count = 0;
 async function useBroadcastChannel(contentWindow) {
   contentWindow.messageCount = 0;
 
   count += 1;
   const name = `test_event_listener_leaks-${count}`;
 
-  let bc = new contentWindow.BroadcastChannel(name);
   let outer = new BroadcastChannel(name);
   outer.postMessage('foo');
 
+  let bc = new contentWindow.BroadcastChannel(name);
   await new Promise(resolve => {
     bc.onmessage = e => {
       contentWindow.messageCount += 1;
       resolve();
     };
   });
 
   is(contentWindow.messageCount, 1, "message should be received");