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

This commit is contained in:
Johnny Stenback 2008-07-21 16:56:45 -07:00
Родитель fa9992c713
Коммит 6e95111554
2 изменённых файлов: 18 добавлений и 6 удалений

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

@ -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<nsIXPConnectJSObjectHolder> 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);
}

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

@ -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<nsIComponentManager> mCompMgr;
nsCOMPtr<nsIJSRuntimeService> mRuntimeService;
nsCOMPtr<nsIThreadJSContextStack> mContextStack;
nsCOMPtr<nsIFile> mFastLoadFile;
nsRefPtr<nsXPCFastLoadIO> mFastLoadIO;
nsCOMPtr<nsIObjectInputStream> mFastLoadInput;