Bug 1316616 part 1. Replace some redundant code in GetCurrentThreadWorkerPrivate() with a call to a function that we already have. r=bkelly
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 18 Nov 2016 16:13:06 -0500
changeset 323516 e70b0fb180a3444285502a5ecff5c2634c6f0cab
parent 323515 c1a0df0334a19e3ebd8f94772a2f48bfc920bb5e
child 323517 d9c4800ffba6692543bcda18e12b1cc197a70d63
push id21
push usermaklebus@msu.edu
push dateThu, 01 Dec 2016 06:22:08 +0000
reviewersbkelly
bugs1316616
milestone53.0a1
Bug 1316616 part 1. Replace some redundant code in GetCurrentThreadWorkerPrivate() with a call to a function that we already have. r=bkelly
dom/workers/RuntimeService.cpp
--- a/dom/workers/RuntimeService.cpp
+++ b/dom/workers/RuntimeService.cpp
@@ -1449,27 +1449,21 @@ GetCurrentThreadWorkerPrivate()
   CycleCollectedJSContext* ccjscx = CycleCollectedJSContext::Get();
   if (!ccjscx) {
     return nullptr;
   }
 
   JSContext* cx = ccjscx->Context();
   MOZ_ASSERT(cx);
 
-  void* cxPrivate = JS_GetContextPrivate(cx);
-  if (!cxPrivate) {
-    // This can happen if the nsCycleCollector_shutdown() in ~WorkerJSContext()
-    // triggers any calls to GetCurrentThreadWorkerPrivate().  At this stage
-    // CycleCollectedJSContext::Get() will still return a context, but
-    // the context private has already been cleared.
-    return nullptr;
-  }
-
-  return
-    static_cast<WorkerThreadContextPrivate*>(cxPrivate)->GetWorkerPrivate();
+  // Note that we can return nullptr if the nsCycleCollector_shutdown() in
+  // ~WorkerJSContext() triggers any calls to GetCurrentThreadWorkerPrivate().
+  // At this stage CycleCollectedJSContext::Get() will still return a context,
+  // but the context private has already been cleared.
+  return GetWorkerPrivateFromContext(cx);
 }
 
 bool
 IsCurrentThreadRunningChromeWorker()
 {
   return GetCurrentThreadWorkerPrivate()->UsesSystemPrincipal();
 }