From 84ca5308bc9b5b34be6a1dde38c4c36e9df4eede Mon Sep 17 00:00:00 2001 From: Blake Kaplan Date: Thu, 5 Aug 2010 12:38:07 -0700 Subject: [PATCH] Bug 584551 - Do things that require entering a request on the old compartment before entering a request on the new one. r=igor a=blocking-beta3 --HG-- extra : rebase_source : 6480bb872de3268230813d2bddda27a4d552daba --- js/src/xpconnect/src/xpccallcontext.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/js/src/xpconnect/src/xpccallcontext.cpp b/js/src/xpconnect/src/xpccallcontext.cpp index 616bace2003b..53a75c54e27e 100644 --- a/js/src/xpconnect/src/xpccallcontext.cpp +++ b/js/src/xpconnect/src/xpccallcontext.cpp @@ -146,14 +146,6 @@ XPCCallContext::Init(XPCContext::LangType callerLanguage, return; } - // Get into the request as early as we can to avoid problems with scanning - // callcontexts on other threads from within the gc callbacks. - - NS_ASSERTION(!callBeginRequest || mCallerLanguage == NATIVE_CALLER, - "Don't call JS_BeginRequest unless the caller is native."); - if(callBeginRequest) - JS_BeginRequest(mJSContext); - if(topJSContext != mJSContext) { if(NS_FAILED(stack->Push(mJSContext))) @@ -164,6 +156,14 @@ XPCCallContext::Init(XPCContext::LangType callerLanguage, mContextPopRequired = JS_TRUE; } + // Get into the request as early as we can to avoid problems with scanning + // callcontexts on other threads from within the gc callbacks. + + NS_ASSERTION(!callBeginRequest || mCallerLanguage == NATIVE_CALLER, + "Don't call JS_BeginRequest unless the caller is native."); + if(callBeginRequest) + JS_BeginRequest(mJSContext); + mXPCContext = XPCContext::GetXPCContext(mJSContext); mPrevCallerLanguage = mXPCContext->SetCallingLangType(mCallerLanguage); @@ -386,6 +386,10 @@ XPCCallContext::~XPCCallContext() shouldReleaseXPC = mPrevCallContext == nsnull; } + // NB: Needs to happen before the context stack pop. + if(mJSContext && mCallerLanguage == NATIVE_CALLER) + JS_EndRequest(mJSContext); + if(mContextPopRequired) { XPCJSContextStack* stack = mThreadData->GetJSContextStack(); @@ -404,9 +408,6 @@ XPCCallContext::~XPCCallContext() if(mJSContext) { - if(mCallerLanguage == NATIVE_CALLER) - JS_EndRequest(mJSContext); - if(mDestroyJSContextInDestructor) { #ifdef DEBUG_xpc_hacker