Bug 1565956 run worker-specific MessagePort close on initialize on only worker threads r=baku
authorKarl Tomlinson <karlt+@karlt.net>
Sun, 17 Nov 2019 21:09:52 +0000
changeset 502356 75a422b353a50e0367459ae4c7909151deda575e
parent 502355 9f72416c9e8a507772a72ac8d6f3d5f48f05e5b5
child 502357 370d932f9681bbf85b1c1417b27936a839248be9
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1565956
milestone72.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 1565956 run worker-specific MessagePort close on initialize on only worker threads r=baku MessagePorts will be initialized also on worklet threads. Differential Revision: https://phabricator.services.mozilla.com/D53131
dom/messagechannel/MessagePort.cpp
dom/workers/RuntimeService.cpp
--- a/dom/messagechannel/MessagePort.cpp
+++ b/dom/messagechannel/MessagePort.cpp
@@ -260,22 +260,19 @@ void MessagePort::Initialize(const nsID&
     }
   } else {
     MOZ_ASSERT(mState == eStateUnshippedEntangled);
   }
 
   // The port has to keep itself alive until it's entangled.
   UpdateMustKeepAlive();
 
-  if (!NS_IsMainThread()) {
+  if (WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate()) {
     RefPtr<MessagePort> self = this;
 
-    WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
-    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.
       mState = eStateDisentangled;
       UpdateMustKeepAlive();
--- a/dom/workers/RuntimeService.cpp
+++ b/dom/workers/RuntimeService.cpp
@@ -2464,25 +2464,27 @@ WorkerPrivate* GetWorkerPrivateFromConte
   // context private is cleared early in ~CycleCollectedJSContext() and so
   // GetFor() returns null above if called after ccjscx is no longer a
   // WorkerJSContext.
   MOZ_ASSERT(workerjscx);
   return workerjscx->GetWorkerPrivate();
 }
 
 WorkerPrivate* GetCurrentThreadWorkerPrivate() {
-  MOZ_ASSERT(!NS_IsMainThread());
+  if (NS_IsMainThread()) {
+    return nullptr;
+  }
 
   CycleCollectedJSContext* ccjscx = CycleCollectedJSContext::Get();
   if (!ccjscx) {
     return nullptr;
   }
 
   WorkerJSContext* workerjscx = ccjscx->GetAsWorkerJSContext();
-  // Although GetCurrentThreadWorkerPrivate() is called only for worker
+  // Even when GetCurrentThreadWorkerPrivate() is called on worker
   // threads, the ccjscx will no longer be a WorkerJSContext if called from
   // stable state events during ~CycleCollectedJSContext().
   if (!workerjscx) {
     return nullptr;
   }
 
   return workerjscx->GetWorkerPrivate();
 }