Bug 834732 - Improve pushing in nsJSEnvironment. r=mrbkap

This commit is contained in:
Bobby Holley 2013-02-13 00:22:27 +01:00
parent fd72f5bc97
commit 6d475c3487

View File

@ -1399,36 +1399,35 @@ nsJSContext::ExecuteScript(JSScript* aScriptObject,
// Push our JSContext on our thread's context stack, in case native code
// called from JS calls back into JS via XPConnect.
nsresult rv;
nsCOMPtr<nsIJSContextStack> stack =
do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv);
if (NS_FAILED(rv) || NS_FAILED(stack->Push(mContext))) {
return NS_ERROR_FAILURE;
}
nsCxPusher pusher;
pusher.Push(mContext);
nsJSContext::TerminationFuncHolder holder(this);
XPCAutoRequest ar(mContext);
JSAutoCompartment ac(mContext, aScopeObject);
++mExecuteDepth;
// The result of evaluation, used only if there were no errors. This need
// not be a GC root currently, provided we run the GC only from the
// operation callback or from ScriptEvaluated.
jsval val;
if (!JS_ExecuteScript(mContext, aScopeObject, aScriptObject, &val)) {
ReportPendingException();
// Scope the JSAutoCompartment so that it gets destroyed before we pop the
// cx and potentially call JS_RestoreFrameChain.
{
JSAutoCompartment ac(mContext, aScopeObject);
++mExecuteDepth;
// The result of evaluation, used only if there were no errors. This need
// not be a GC root currently, provided we run the GC only from the
// operation callback or from ScriptEvaluated.
jsval val;
if (!JS_ExecuteScript(mContext, aScopeObject, aScriptObject, &val)) {
ReportPendingException();
}
--mExecuteDepth;
}
--mExecuteDepth;
// Pop here, after JS_ValueToString and any other possible evaluation.
if (NS_FAILED(stack->Pop(nullptr))) {
rv = NS_ERROR_FAILURE;
}
pusher.Pop();
// ScriptEvaluated needs to come after we pop the stack
ScriptEvaluated(true);
return rv;
return NS_OK;
}
@ -1500,7 +1499,10 @@ nsJSContext::CallEventHandler(nsISupports* aTarget, JSObject* aScope,
xpc_UnmarkGrayObject(aScope);
xpc_UnmarkGrayObject(aHandler);
nsCxPusher pusher;
pusher.Push(mContext);
XPCAutoRequest ar(mContext);
JSObject* target = nullptr;
nsresult rv = JSObjectFromInterface(aTarget, aScope, &target);
NS_ENSURE_SUCCESS(rv, rv);
@ -1513,9 +1515,6 @@ nsJSContext::CallEventHandler(nsISupports* aTarget, JSObject* aScope,
// xxxmarkh - this comment is no longer true - principals are not used at
// all now, and never were in some cases.
nsCxPusher pusher;
pusher.Push(mContext);
// check if the event handler can be run on the object in question
rv = sSecurityManager->CheckFunctionAccess(mContext, aHandler, target);
@ -1748,6 +1747,8 @@ nsJSContext::SetProperty(JSObject* aTarget, const char* aPropName, nsISupports*
uint32_t argc;
jsval *argv = nullptr;
nsCxPusher pusher;
pusher.Push(mContext);
XPCAutoRequest ar(mContext);
Maybe<nsRootedJSValueArray> tempStorage;