Bug 1047509 - Part 9: Remove final uses of mozJSComponentLoader's own JSContext and tidy up. r=bholley

This commit is contained in:
Bob Owen 2014-08-07 19:36:31 +01:00
Родитель d2c8747c63
Коммит 3f8ae37d6e
2 изменённых файлов: 7 добавлений и 34 удалений

Просмотреть файл

@ -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<nsIScriptSecurityManager> 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

Просмотреть файл

@ -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<nsIComponentManager> mCompMgr;
nsCOMPtr<nsIJSRuntimeService> mRuntimeService;
nsCOMPtr<nsIPrincipal> mSystemPrincipal;
nsCOMPtr<nsIXPConnectJSObjectHolder> mLoaderGlobal;
JSRuntime *mRuntime;
JSContext *mContext;
class ModuleEntry : public mozilla::Module
{