From 6e951115549995ea7b958723bebc1cae52003f0a Mon Sep 17 00:00:00 2001 From: Johnny Stenback Date: Mon, 21 Jul 2008 16:56:45 -0700 Subject: [PATCH] Landing fix for bug 444880. Make the JS component loader use the JS context stack so that pending requests are suspended while components load. Patch by bent.mozilla@gmail.com, r+sr=jst@mozilla.org --- .../xpconnect/loader/mozJSComponentLoader.cpp | 22 ++++++++++++++----- .../xpconnect/loader/mozJSComponentLoader.h | 2 ++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/js/src/xpconnect/loader/mozJSComponentLoader.cpp b/js/src/xpconnect/loader/mozJSComponentLoader.cpp index 2535e331c5c8..976e632d8df2 100644 --- a/js/src/xpconnect/loader/mozJSComponentLoader.cpp +++ b/js/src/xpconnect/loader/mozJSComponentLoader.cpp @@ -293,7 +293,7 @@ static JSFunctionSpec gGlobalFun[] = { class JSCLContextHelper { public: - JSCLContextHelper(JSContext* cx); + JSCLContextHelper(mozJSComponentLoader* loader); ~JSCLContextHelper(); operator JSContext*() const {return mContext;} @@ -301,7 +301,8 @@ public: JSCLContextHelper(); // not implemnted private: JSContext* mContext; - intN mContextThread; + intN mContextThread; + nsIThreadJSContextStack* mContextStack; }; @@ -518,6 +519,10 @@ mozJSComponentLoader::ReallyInit() NS_FAILED(rv = mRuntimeService->GetRuntime(&mRuntime))) return rv; + mContextStack = do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv); + if (NS_FAILED(rv)) + return rv; + // Create our compilation context. mContext = JS_NewContext(mRuntime, 256); if (!mContext) @@ -644,7 +649,7 @@ mozJSComponentLoader::LoadModule(nsILocalFile* aComponentFile, if (NS_FAILED(rv)) return rv; - JSCLContextHelper cx(mContext); + JSCLContextHelper cx(this); JSObject* cm_jsobj; nsCOMPtr cm_holder; @@ -1054,7 +1059,7 @@ mozJSComponentLoader::GlobalForLocation(nsILocalFile *aComponent, nsresult rv; JSPrincipals* jsPrincipals = nsnull; - JSCLContextHelper cx(mContext); + JSCLContextHelper cx(this); #ifndef XPCONNECT_STANDALONE rv = mSystemPrincipal->GetJSPrincipals(cx, &jsPrincipals); @@ -1324,6 +1329,7 @@ mozJSComponentLoader::UnloadModules() mContext = nsnull; mRuntimeService = nsnull; + mContextStack = nsnull; #ifdef DEBUG_shaver_off fprintf(stderr, "mJCL: UnloadAll(%d)\n", aWhen); #endif @@ -1601,9 +1607,11 @@ mozJSComponentLoader::Observe(nsISupports *subject, const char *topic, //---------------------------------------------------------------------- -JSCLContextHelper::JSCLContextHelper(JSContext *cx) - : mContext(cx), mContextThread(0) +JSCLContextHelper::JSCLContextHelper(mozJSComponentLoader *loader) + : mContext(loader->mContext), mContextThread(0), + mContextStack(loader->mContextStack) { + mContextStack->Push(mContext); mContextThread = JS_GetContextThread(mContext); if (mContextThread) { JS_BeginRequest(mContext); @@ -1615,4 +1623,6 @@ JSCLContextHelper::~JSCLContextHelper() JS_ClearNewbornRoots(mContext); if (mContextThread) JS_EndRequest(mContext); + + mContextStack->Pop(nsnull); } diff --git a/js/src/xpconnect/loader/mozJSComponentLoader.h b/js/src/xpconnect/loader/mozJSComponentLoader.h index 9ea6e2ac183e..25fdd6010fd6 100644 --- a/js/src/xpconnect/loader/mozJSComponentLoader.h +++ b/js/src/xpconnect/loader/mozJSComponentLoader.h @@ -92,6 +92,7 @@ class mozJSComponentLoader : public nsIModuleLoader, public xpcIJSModuleLoader, public nsIObserver { + friend class JSCLContextHelper; public: NS_DECL_ISUPPORTS NS_DECL_NSIMODULELOADER @@ -124,6 +125,7 @@ class mozJSComponentLoader : public nsIModuleLoader, nsCOMPtr mCompMgr; nsCOMPtr mRuntimeService; + nsCOMPtr mContextStack; nsCOMPtr mFastLoadFile; nsRefPtr mFastLoadIO; nsCOMPtr mFastLoadInput;