From d84e6264daad7cc8f7ab2892651065d30c464f52 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 19 Apr 2016 14:04:32 +1000 Subject: [PATCH] Bug 1265035 - Make ~WorkerJSRuntime() handle Initialize() failure better. r=khuey. --HG-- extra : rebase_source : 4b2cb2ef8192f314a28556826044f010a52b90b4 --- dom/workers/RuntimeService.cpp | 6 ++++-- js/xpconnect/src/XPCJSRuntime.cpp | 4 ++++ xpcom/base/CycleCollectedJSRuntime.h | 4 ++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/dom/workers/RuntimeService.cpp b/dom/workers/RuntimeService.cpp index dbe37c0817b1..e9e63740fd95 100644 --- a/dom/workers/RuntimeService.cpp +++ b/dom/workers/RuntimeService.cpp @@ -880,8 +880,10 @@ public: ~WorkerJSRuntime() { - JSRuntime* rt = Runtime(); - MOZ_ASSERT(rt); + JSRuntime* rt = MaybeRuntime(); + if (!rt) { + return; // Initialize() must have failed + } delete static_cast(JS_GetRuntimePrivate(rt)); JS_SetRuntimePrivate(rt, nullptr); diff --git a/js/xpconnect/src/XPCJSRuntime.cpp b/js/xpconnect/src/XPCJSRuntime.cpp index 7429a95ff8c7..983e66fadf6d 100644 --- a/js/xpconnect/src/XPCJSRuntime.cpp +++ b/js/xpconnect/src/XPCJSRuntime.cpp @@ -1591,6 +1591,10 @@ ReloadPrefsCallback(const char* pref, void* data) 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 diff --git a/xpcom/base/CycleCollectedJSRuntime.h b/xpcom/base/CycleCollectedJSRuntime.h index 48973890d85a..15e9b9c93d47 100644 --- a/xpcom/base/CycleCollectedJSRuntime.h +++ b/xpcom/base/CycleCollectedJSRuntime.h @@ -321,6 +321,10 @@ public: return mJSRuntime; } +protected: + JSRuntime* MaybeRuntime() const { return mJSRuntime; } + +public: // nsThread entrypoints virtual void BeforeProcessTask(bool aMightBlock) { }; virtual void AfterProcessTask(uint32_t aRecursionDepth);