Bug 1450644 - WorkerRef should make APIs able to work until the worker is completely terminated - part 2 - BroadcastChannel, r=asuth
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 17 Apr 2018 20:51:02 +0200
changeset 467754 f2341e59a4b58d36766806dab967a24526a35368
parent 467753 c8c11bd922185c9fb46735ee0a00de083d723285
child 467755 0d3ab01ff51bc77b7f616beefd355e70c0d7de41
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>