Fixing crash regression bug 234626. Add kungFuDeathGrips to functions in nsJSContext that execute JS (some already had them) to avoid having JSContexts die on us while they're still on the stack. r=caillon@aillon.org, sr=dbaron@dbaron.org, a=chofmann@mozilla.org

This commit is contained in:
jst%mozilla.jstenback.com 2004-02-18 02:17:32 +00:00
Родитель 73c175022f
Коммит 2c3fed598d
1 изменённых файлов: 11 добавлений и 4 удалений

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

@ -702,6 +702,10 @@ nsJSContext::EvaluateStringWithValue(const nsAString& aScript,
return NS_ERROR_FAILURE;
}
// This context can be deleted unexpectedly if the JS closes the
// owning window.
nsCOMPtr<nsIScriptContext> kungFuDeathGrip(this);
// 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 branch
// callback or from ScriptEvaluated. TODO: use JS_Begin/EndRequest to keep
@ -846,10 +850,8 @@ nsJSContext::EvaluateString(const nsAString& aScript,
aPrincipal->GetJSPrincipals(mContext, &jsprin);
}
else {
nsIScriptGlobalObject *global = GetGlobalObject();
if (!global)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIScriptObjectPrincipal> objPrincipal = do_QueryInterface(global, &rv);
nsCOMPtr<nsIScriptObjectPrincipal> objPrincipal =
do_QueryInterface(GetGlobalObject(), &rv);
if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
rv = objPrincipal->GetPrincipal(getter_AddRefs(principal));
@ -857,6 +859,11 @@ nsJSContext::EvaluateString(const nsAString& aScript,
return NS_ERROR_FAILURE;
principal->GetJSPrincipals(mContext, &jsprin);
}
// this context can be deleted unexpectedly if the JS closes the
// owning window.
nsCOMPtr<nsIScriptContext> kungFuDeathGrip(this);
// From here on, we must JSPRINCIPALS_DROP(jsprin) before returning...
PRBool ok = PR_FALSE;