Bug 1450644 - WorkerRef should make APIs able to work until the worker is completely terminated - part 1 - MessagePort, r=asuth
☠☠ backed out by 73615fe67ab6 ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 17 Apr 2018 20:51:02 +0200
changeset 414176 ed93e3547096537e7cd76cdae83e83573c30dcb3
parent 414175 b657b7a34615a3febf6bc83ff85623ae4476233f
child 414177 629e499c0f754bc3cce971bd1a90310ce04114ab
push id33861
push userccoroiu@mozilla.com
push dateWed, 18 Apr 2018 10:50:38 +0000
treeherdermozilla-central@4af4ae0aee55 [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 1 - MessagePort, r=asuth
dom/messagechannel/MessagePort.cpp
dom/workers/WorkerRef.cpp
--- a/dom/messagechannel/MessagePort.cpp
+++ b/dom/messagechannel/MessagePort.cpp
@@ -292,18 +292,18 @@ MessagePort::Initialize(const nsID& aUUI
     MOZ_ASSERT(workerPrivate);
 
     // When the callback is executed, we cannot process messages anymore because
     // we cannot dispatch new runnables. Let's force a Close().
     RefPtr<StrongWorkerRef> strongWorkerRef =
       StrongWorkerRef::Create(workerPrivate, "MessagePort",
                               [self]() { self->CloseForced(); });
     if (NS_WARN_IF(!strongWorkerRef)) {
-      // The worker is shutting down. Let's return an already closed port.
-      mState = eStateDisentangledForClose;
+      // The worker is shutting down.
+      aRv.Throw(NS_ERROR_FAILURE);
       return;
     }
 
     MOZ_ASSERT(!mWorkerRef);
     mWorkerRef = Move(strongWorkerRef);
   } else if (GetOwner()) {
     MOZ_ASSERT(NS_IsMainThread());
     mInnerID = GetOwner()->WindowID();
--- a/dom/workers/WorkerRef.cpp
+++ b/dom/workers/WorkerRef.cpp
@@ -65,16 +65,20 @@ public:
     , mWorkerRef(aWorkerRef)
   {}
 
   bool
   Notify(WorkerStatus aStatus) override
   {
     MOZ_ASSERT(mWorkerRef);
 
+    if (aStatus < Canceling) {
+      return true;
+    }
+
     // Let's keep this object alive for the whole Notify() execution.
     RefPtr<WorkerRef> workerRef;
     workerRef = mWorkerRef;
 
     workerRef->Notify();
     return true;
   }
 
@@ -123,17 +127,17 @@ WeakWorkerRef::Create(WorkerPrivate* aWo
   MOZ_ASSERT(aWorkerPrivate);
   aWorkerPrivate->AssertIsOnWorkerThread();
 
   RefPtr<WeakWorkerRef> ref = new WeakWorkerRef(aWorkerPrivate);
 
   // This holder doesn't keep the worker alive.
   UniquePtr<Holder> holder(new Holder("WeakWorkerRef::Holder", ref,
                                       WorkerHolder::AllowIdleShutdownStart));
-  if (NS_WARN_IF(!holder->HoldWorker(aWorkerPrivate, Closing))) {
+  if (NS_WARN_IF(!holder->HoldWorker(aWorkerPrivate, Canceling))) {
     return nullptr;
   }
 
   ref->mHolder = Move(holder);
   ref->mCallback = aCallback;
 
   return ref.forget();
 }
@@ -177,17 +181,17 @@ StrongWorkerRef::Create(WorkerPrivate* a
   MOZ_ASSERT(aWorkerPrivate);
   MOZ_ASSERT(aName);
 
   RefPtr<StrongWorkerRef> ref = new StrongWorkerRef(aWorkerPrivate);
 
   // The worker is kept alive by this holder.
   UniquePtr<Holder> holder(new Holder(aName, ref,
                                       WorkerHolder::PreventIdleShutdownStart));
-  if (NS_WARN_IF(!holder->HoldWorker(aWorkerPrivate, Closing))) {
+  if (NS_WARN_IF(!holder->HoldWorker(aWorkerPrivate, Canceling))) {
     return nullptr;
   }
 
   ref->mHolder = Move(holder);
   ref->mCallback = aCallback;
 
   return ref.forget();
 }