Bug 1265035 - Make ~WorkerJSRuntime() handle Initialize() failure better. r=khuey.
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 19 Apr 2016 14:04:32 +1000
changeset 293976 242336dca06d789d466a2ac7700405c02e7ba487
parent 293975 a2a9cec0506a8646416afcdf1f46ac46ffa97bc4
child 293977 d08288654ec9a96d7b685c18efac351551d8fc35
push id30194
push usercbook@mozilla.com
push dateWed, 20 Apr 2016 09:50:56 +0000
treeherdermozilla-central@f05a1242fb29 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs1265035
milestone48.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 1265035 - Make ~WorkerJSRuntime() handle Initialize() failure better. r=khuey.
dom/workers/RuntimeService.cpp
js/xpconnect/src/XPCJSRuntime.cpp
xpcom/base/CycleCollectedJSRuntime.h
--- a/dom/workers/RuntimeService.cpp
+++ b/dom/workers/RuntimeService.cpp
@@ -875,18 +875,20 @@ public:
   explicit WorkerJSRuntime(WorkerPrivate* aWorkerPrivate)
     : mWorkerPrivate(aWorkerPrivate)
   {
     MOZ_ASSERT(aWorkerPrivate);
   }
 
   ~WorkerJSRuntime()
   {
-    JSRuntime* rt = Runtime();
-    MOZ_ASSERT(rt);
+    JSRuntime* rt = MaybeRuntime();
+    if (!rt) {
+      return;   // Initialize() must have failed
+    }
 
     delete static_cast<WorkerThreadRuntimePrivate*>(JS_GetRuntimePrivate(rt));
     JS_SetRuntimePrivate(rt, nullptr);
 
     // The worker global should be unrooted and the shutdown cycle collection
     // should break all remaining cycles. The superclass destructor will run
     // the GC one final time and finalize any JSObjects that were participating
     // in cycles that were broken during CC shutdown.
--- a/js/xpconnect/src/XPCJSRuntime.cpp
+++ b/js/xpconnect/src/XPCJSRuntime.cpp
@@ -1586,16 +1586,20 @@ ReloadPrefsCallback(const char* pref, vo
     JS_SetGlobalJitCompilerOption(rt, JSJITCOMPILER_BASELINE_WARMUP_TRIGGER,
                                   useBaselineEager ? 0 : -1);
     JS_SetGlobalJitCompilerOption(rt, JSJITCOMPILER_ION_WARMUP_TRIGGER,
                                   useIonEager ? 0 : -1);
 }
 
 XPCJSRuntime::~XPCJSRuntime()
 {
+    // Elsewhere we abort immediately if XPCJSRuntime initialization fails.
+    // Therefore the runtime must be non-null.
+    MOZ_ASSERT(MaybeRuntime());
+
     // This destructor runs before ~CycleCollectedJSRuntime, which does the
     // actual JS_DestroyRuntime() call. But destroying the runtime triggers
     // one final GC, which can call back into the runtime with various
     // callback if we aren't careful. Null out the relevant callbacks.
     js::SetActivityCallback(Runtime(), nullptr, nullptr);
     JS_RemoveFinalizeCallback(Runtime(), FinalizeCallback);
     JS_RemoveWeakPointerZoneGroupCallback(Runtime(), WeakPointerZoneGroupCallback);
     JS_RemoveWeakPointerCompartmentCallback(Runtime(), WeakPointerCompartmentCallback);
--- a/xpcom/base/CycleCollectedJSRuntime.h
+++ b/xpcom/base/CycleCollectedJSRuntime.h
@@ -316,16 +316,20 @@ public:
   virtual void DispatchDeferredDeletion(bool aContinuation, bool aPurge = false) = 0;
 
   JSRuntime* Runtime() const
   {
     MOZ_ASSERT(mJSRuntime);
     return mJSRuntime;
   }
 
+protected:
+  JSRuntime* MaybeRuntime() const { return mJSRuntime; }
+
+public:
   // nsThread entrypoints
   virtual void BeforeProcessTask(bool aMightBlock) { };
   virtual void AfterProcessTask(uint32_t aRecursionDepth);
 
   // microtask processor entry point
   void AfterProcessMicrotask();
 
   uint32_t RecursionDepth();