From bfa46ac41b25a4780e1ca0469a1733f1ca77e4f9 Mon Sep 17 00:00:00 2001 From: "mrbkap%gmail.com" Date: Thu, 3 Nov 2005 03:14:00 +0000 Subject: [PATCH] bug 313220: Push the sandbox's context onto the context stack so that functions that need to use the current fp can find it. r=brendan sr=shaver a=asa git-svn-id: svn://10.0.0.236/branches/MOZILLA_1_8_BRANCH@184077 18797224-902f-48f8-a5cc-f745e15eee43 --- .../js/src/xpconnect/src/xpccomponents.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/mozilla/js/src/xpconnect/src/xpccomponents.cpp b/mozilla/js/src/xpconnect/src/xpccomponents.cpp index 9a72d125906..8555e628a5c 100644 --- a/mozilla/js/src/xpconnect/src/xpccomponents.cpp +++ b/mozilla/js/src/xpconnect/src/xpccomponents.cpp @@ -2409,6 +2409,21 @@ nsXPCComponents_Utils::EvalInSandbox(const nsAString &source) JS_SetGlobalObject(sandcx, sandbox); + XPCPerThreadData *data = XPCPerThreadData::GetData(); + XPCJSContextStack *stack; + PRBool popContext = PR_FALSE; + if (data && (stack = data->GetJSContextStack())) { + if (NS_FAILED(stack->Push(sandcx))) { + JS_ReportError(cx, + "Unable to initialize XPConnect with the sandbox context"); + JSPRINCIPALS_DROP(cx, jsPrincipals); + JS_DestroyContextNoGC(sandcx); + return NS_ERROR_FAILURE; + } + + popContext = PR_TRUE; + } + // Capture uncaught exceptions reported as errors on sandcx and // re-throw them on cx. JS_SetContextPrivate(sandcx, cx); @@ -2454,6 +2469,10 @@ nsXPCComponents_Utils::EvalInSandbox(const nsAString &source) cc->SetReturnValueWasSet(PR_TRUE); } + if (popContext) { + stack->Pop(nsnull); + } + JS_DestroyContextNoGC(sandcx); JSPRINCIPALS_DROP(cx, jsPrincipals); return rv;