Bug 1301519 Don't crash if GetCurrentThreadWorkerPrivate() is called during worker shutdown. r=baku
authorBen Kelly <ben@wanderview.com>
Mon, 12 Sep 2016 06:09:32 -0700
changeset 354810 00f3449636bab53be69a7421a109c99754bb827f
parent 354809 e5400de3999089ffbd5a88752f775317b6f7deb0
child 354811 b8b6ed05d041bd151d5df9e9f867fb26baffc0d3
push id6570
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:26:13 +0000
treeherdermozilla-beta@f455459b2ae5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1301519
milestone51.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 1301519 Don't crash if GetCurrentThreadWorkerPrivate() is called during worker shutdown. r=baku
dom/workers/RuntimeService.cpp
--- a/dom/workers/RuntimeService.cpp
+++ b/dom/workers/RuntimeService.cpp
@@ -1432,17 +1432,19 @@ WorkerCrossThreadDispatcher::PostTask(Wo
 
 WorkerPrivate*
 GetWorkerPrivateFromContext(JSContext* aCx)
 {
   MOZ_ASSERT(!NS_IsMainThread());
   MOZ_ASSERT(aCx);
 
   void* cxPrivate = JS_GetContextPrivate(aCx);
-  MOZ_ASSERT(cxPrivate);
+  if (!cxPrivate) {
+    return nullptr;
+  }
 
   return
     static_cast<WorkerThreadContextPrivate*>(cxPrivate)->GetWorkerPrivate();
 }
 
 WorkerPrivate*
 GetCurrentThreadWorkerPrivate()
 {
@@ -1452,17 +1454,23 @@ GetCurrentThreadWorkerPrivate()
   if (!ccrt) {
     return nullptr;
   }
 
   JSContext* cx = ccrt->Context();
   MOZ_ASSERT(cx);
 
   void* cxPrivate = JS_GetContextPrivate(cx);
-  MOZ_ASSERT(cxPrivate);
+  if (!cxPrivate) {
+    // This can happen if the nsCycleCollector_shutdown() in ~WorkerJSRuntime()
+    // triggers any calls to GetCurrentThreadWorkerPrivate().  At this stage
+    // CycleCollectedJSRuntime::Get() will still return a runtime, but
+    // the context private has already been cleared.
+    return nullptr;
+  }
 
   return
     static_cast<WorkerThreadContextPrivate*>(cxPrivate)->GetWorkerPrivate();
 }
 
 bool
 IsCurrentThreadRunningChromeWorker()
 {