Bug 520386. Don't clear scope while executing code in that scope. r=bzbarsky@mit.edu, sr=jst@mozilla.org

This commit is contained in:
Blake Kaplan
2009-11-19 15:11:44 -08:00
parent e553e503c6
commit a90ccae37f
5 changed files with 87 additions and 12 deletions

View File

@@ -1312,7 +1312,9 @@ nsJSContext::JSOptionChangedCallback(const char *pref, void *data)
return 0;
}
nsJSContext::nsJSContext(JSRuntime *aRuntime) : mGCOnDestruction(PR_TRUE)
nsJSContext::nsJSContext(JSRuntime *aRuntime)
: mGCOnDestruction(PR_TRUE),
mExecuteDepth(0)
{
++sContextCount;
@@ -1522,6 +1524,8 @@ nsJSContext::EvaluateStringWithValue(const nsAString& aScript,
JSAutoRequest ar(mContext);
nsJSVersionSetter setVersion(mContext, aVersion);
++mExecuteDepth;
ok = ::JS_EvaluateUCScriptForPrincipals(mContext,
(JSObject *)aScopeObject,
jsprin,
@@ -1531,6 +1535,8 @@ nsJSContext::EvaluateStringWithValue(const nsAString& aScript,
aLineNo,
&val);
--mExecuteDepth;
if (!ok) {
// Tell XPConnect about any pending exceptions. This is needed
// to avoid dropping JS exceptions in case we got here through
@@ -1688,6 +1694,8 @@ nsJSContext::EvaluateString(const nsAString& aScript,
nsJSContext::TerminationFuncHolder holder(this);
++mExecuteDepth;
// SecurityManager said "ok", but don't compile if aVersion is unknown.
// Since the caller is responsible for parsing the version strings, we just
// check it isn't JSVERSION_UNKNOWN.
@@ -1731,6 +1739,8 @@ nsJSContext::EvaluateString(const nsAString& aScript,
}
}
--mExecuteDepth;
// Pop here, after JS_ValueToString and any other possible evaluation.
if (NS_FAILED(stack->Pop(nsnull)))
rv = NS_ERROR_FAILURE;
@@ -1849,6 +1859,7 @@ nsJSContext::ExecuteScript(void *aScriptObject,
nsJSContext::TerminationFuncHolder holder(this);
JSAutoRequest ar(mContext);
++mExecuteDepth;
ok = ::JS_ExecuteScript(mContext,
(JSObject *)aScopeObject,
(JSScript*)::JS_GetPrivate(mContext,
@@ -1868,6 +1879,8 @@ nsJSContext::ExecuteScript(void *aScriptObject,
}
}
--mExecuteDepth;
// Pop here, after JS_ValueToString and any other possible evaluation.
if (NS_FAILED(stack->Pop(nsnull)))
rv = NS_ERROR_FAILURE;
@@ -2111,8 +2124,10 @@ nsJSContext::CallEventHandler(nsISupports* aTarget, void *aScope, void *aHandler
jsval funval = OBJECT_TO_JSVAL(static_cast<JSObject *>(aHandler));
JSAutoRequest ar(mContext);
++mExecuteDepth;
PRBool ok = ::JS_CallFunctionValue(mContext, target,
funval, argc, argv, &rval);
--mExecuteDepth;
if (!ok) {
// Tell XPConnect about any pending exceptions. This is needed
@@ -3498,6 +3513,12 @@ nsJSContext::SetProcessingScriptTag(PRBool aFlag)
mProcessingScriptTag = aFlag;
}
PRBool
nsJSContext::GetExecutingScript()
{
return JS_IsRunning(mContext) || mExecuteDepth > 0;
}
void
nsJSContext::SetGCOnDestruction(PRBool aGCOnDestruction)
{