From 3f8ae37d6e1a88c89c8013a85bc3aeb073df9c62 Mon Sep 17 00:00:00 2001 From: Bob Owen Date: Thu, 7 Aug 2014 19:36:31 +0100 Subject: [PATCH] Bug 1047509 - Part 9: Remove final uses of mozJSComponentLoader's own JSContext and tidy up. r=bholley --- js/xpconnect/loader/mozJSComponentLoader.cpp | 37 ++++---------------- js/xpconnect/loader/mozJSComponentLoader.h | 4 --- 2 files changed, 7 insertions(+), 34 deletions(-) diff --git a/js/xpconnect/loader/mozJSComponentLoader.cpp b/js/xpconnect/loader/mozJSComponentLoader.cpp index 51a60a6e54d4..d129637b0712 100644 --- a/js/xpconnect/loader/mozJSComponentLoader.cpp +++ b/js/xpconnect/loader/mozJSComponentLoader.cpp @@ -28,7 +28,6 @@ #include "nsIFile.h" #include "mozJSComponentLoader.h" #include "mozJSLoaderUtils.h" -#include "nsIJSRuntimeService.h" #include "nsIXPConnect.h" #include "nsIObserverService.h" #include "nsIScriptSecurityManager.h" @@ -74,7 +73,6 @@ static const JSClass kFakeBackstagePassJSClass = JS_ConvertStub }; -static const char kJSRuntimeServiceContractID[] = "@mozilla.org/js/xpc/RuntimeService;1"; static const char kXPConnectServiceContractID[] = "@mozilla.org/js/xpc/XPConnect;1"; static const char kObserverServiceContractID[] = "@mozilla.org/observer-service;1"; static const char kJSCachePrefix[] = "jsloader"; @@ -287,9 +285,7 @@ ReportOnCaller(JSCLContextHelper &helper, } mozJSComponentLoader::mozJSComponentLoader() - : mRuntime(nullptr), - mContext(nullptr), - mModules(16), + : mModules(16), mImports(16), mInProgressImports(16), mInitialized(false), @@ -397,22 +393,6 @@ mozJSComponentLoader::ReallyInit() mReuseLoaderGlobal = true; #endif - /* - * Get the JSRuntime from the runtime svc, if possible. - * We keep a reference around, because it's a Bad Thing if the runtime - * service gets shut down before we're done. Bad! - */ - - mRuntimeService = do_GetService(kJSRuntimeServiceContractID, &rv); - if (NS_FAILED(rv) || - NS_FAILED(rv = mRuntimeService->GetRuntime(&mRuntime))) - return rv; - - // Create our compilation context. - mContext = JS_NewContext(mRuntime, 256); - if (!mContext) - return NS_ERROR_OUT_OF_MEMORY; - nsCOMPtr secman = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID); if (!secman) @@ -1074,11 +1054,13 @@ mozJSComponentLoader::UnloadModules() if (mLoaderGlobal) { MOZ_ASSERT(mReuseLoaderGlobal, "How did this happen?"); - JSAutoRequest ar(mContext); - RootedObject global(mContext, mLoaderGlobal->GetJSObject()); + dom::AutoJSAPI jsapi; + jsapi.Init(); + JSContext* cx = jsapi.cx(); + RootedObject global(cx, mLoaderGlobal->GetJSObject()); if (global) { - JSAutoCompartment ac(mContext, global); - JS_SetAllNonReservedSlotsToUndefined(mContext, global); + JSAutoCompartment ac(cx, global); + JS_SetAllNonReservedSlotsToUndefined(cx, global); } else { NS_WARNING("Going to leak!"); } @@ -1090,11 +1072,6 @@ mozJSComponentLoader::UnloadModules() mImports.Clear(); mModules.Enumerate(ClearModules, nullptr); - - JS_DestroyContextNoGC(mContext); - mContext = nullptr; - - mRuntimeService = nullptr; } NS_IMETHODIMP diff --git a/js/xpconnect/loader/mozJSComponentLoader.h b/js/xpconnect/loader/mozJSComponentLoader.h index 5f0ea8caaa58..67f55352e60c 100644 --- a/js/xpconnect/loader/mozJSComponentLoader.h +++ b/js/xpconnect/loader/mozJSComponentLoader.h @@ -21,7 +21,6 @@ #include "xpcIJSGetFactory.h" class nsIFile; -class nsIJSRuntimeService; class nsIPrincipal; class nsIXPConnectJSObjectHolder; class ComponentLoaderInfo; @@ -82,11 +81,8 @@ class mozJSComponentLoader : public mozilla::ModuleLoader, JS::MutableHandleObject vp); nsCOMPtr mCompMgr; - nsCOMPtr mRuntimeService; nsCOMPtr mSystemPrincipal; nsCOMPtr mLoaderGlobal; - JSRuntime *mRuntime; - JSContext *mContext; class ModuleEntry : public mozilla::Module {