Bug 1450644 - WorkerRef should make APIs able to work until the worker is completely terminated - part 2 - BroadcastChannel, r=asuth
☠☠ backed out by 73615fe67ab6 ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 17 Apr 2018 20:51:02 +0200
changeset 467710 629e499c0f754bc3cce971bd1a90310ce04114ab
parent 467709 ed93e3547096537e7cd76cdae83e83573c30dcb3
child 467711 246fb3ee14cd82024354f82cac6c97f48139c3d1
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1450644
milestone61.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 1450644 - WorkerRef should make APIs able to work until the worker is completely terminated - part 2 - BroadcastChannel, r=asuth
dom/broadcastchannel/BroadcastChannel.cpp
dom/broadcastchannel/BroadcastChannel.h
testing/web-platform/tests/webmessaging/broadcastchannel/workers.html
--- a/dom/broadcastchannel/BroadcastChannel.cpp
+++ b/dom/broadcastchannel/BroadcastChannel.cpp
@@ -306,25 +306,25 @@ BroadcastChannel::Constructor(const Glob
     MOZ_ASSERT(workerPrivate);
 
     RefPtr<StrongWorkerRef> workerRef =
       StrongWorkerRef::Create(workerPrivate, "BroadcastChannel",
                               [bc] () { bc->Shutdown(); });
     // We are already shutting down the worker. Let's return a non-active
     // object.
     if (NS_WARN_IF(!workerRef)) {
-      bc->mState = StateClosed;
-      return bc.forget();
+      aRv.Throw(NS_ERROR_FAILURE);
+      return nullptr;
     }
 
     RefPtr<ThreadSafeWorkerRef> tsr = new ThreadSafeWorkerRef(workerRef);
 
     RefPtr<InitializeRunnable> runnable =
       new InitializeRunnable(tsr, origin, principalInfo, aRv);
-    runnable->Dispatch(Closing, aRv);
+    runnable->Dispatch(Canceling, aRv);
     if (aRv.Failed()) {
       return nullptr;
     }
 
     bc->mWorkerRef = Move(workerRef);
   }
 
   // Register this component to PBackground.
--- a/dom/broadcastchannel/BroadcastChannel.h
+++ b/dom/broadcastchannel/BroadcastChannel.h
@@ -63,21 +63,16 @@ public:
   void Shutdown();
 
 private:
   BroadcastChannel(nsPIDOMWindowInner* aWindow,
                    const nsAString& aChannel);
 
   ~BroadcastChannel();
 
-  void PostMessageData(BroadcastChannelMessage* aData);
-
-  void PostMessageInternal(JSContext* aCx, JS::Handle<JS::Value> aMessage,
-                           ErrorResult& aRv);
-
   void RemoveDocFromBFCache();
 
   void DisconnectFromOwner() override;
 
   RefPtr<BroadcastChannelChild> mActor;
 
   RefPtr<WorkerRef> mWorkerRef;
 
--- a/testing/web-platform/tests/webmessaging/broadcastchannel/workers.html
+++ b/testing/web-platform/tests/webmessaging/broadcastchannel/workers.html
@@ -116,9 +116,26 @@ async_test(t => {
 
   var w = new Worker(URL.createObjectURL(workerBlob));
   w.onmessage = function(e) {
     assert_true(e.data, "BroadcastChannel created on worker shutdown.");
     t.done();
   }
 }, 'BroadcastChannel created after a worker self.close()');
 
+async_test(t => {
+  function workerCode() {
+    close();
+    var bc = new BroadcastChannel('worker-test-after-close');
+    bc.postMessage(true);
+  }
+
+  var bc = new BroadcastChannel('worker-test-after-close');
+  bc.onmessage = function(e) {
+    assert_true(e.data, "BroadcastChannel created on worker shutdown.");
+    t.done();
+  }
+
+  var workerBlob = new Blob([workerCode.toString() + ";workerCode();"], {type:"application/javascript"});
+  new Worker(URL.createObjectURL(workerBlob));
+}, 'BroadcastChannel used after a worker self.close()');
+
 </script>