Protect the sandbox object from GC and make the sandbox code request-safe. bug 265740, r=brendan sr=jst

This commit is contained in:
mrbkap%gmail.com 2006-02-18 03:00:33 +00:00
Родитель bf888a7955
Коммит 736fd2d205
1 изменённых файлов: 4 добавлений и 0 удалений

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

@ -2250,10 +2250,13 @@ nsXPCComponents_utils_Sandbox::CallOrConstruct(nsIXPConnectWrappedNative *wrappe
if (!tempcx) if (!tempcx)
return ThrowAndFail(NS_ERROR_OUT_OF_MEMORY, cx, _retval); return ThrowAndFail(NS_ERROR_OUT_OF_MEMORY, cx, _retval);
AutoJSRequestWithNoCallContext req(tempcx);
JSObject *sandbox = JS_NewObject(tempcx, &SandboxClass, nsnull, nsnull); JSObject *sandbox = JS_NewObject(tempcx, &SandboxClass, nsnull, nsnull);
if (!sandbox) if (!sandbox)
return ThrowAndFail(NS_ERROR_XPC_UNEXPECTED, cx, _retval); return ThrowAndFail(NS_ERROR_XPC_UNEXPECTED, cx, _retval);
JS_SetGlobalObject(tempcx, sandbox);
// Make sure to set up principals on the sandbox before initing classes // Make sure to set up principals on the sandbox before initing classes
nsIScriptObjectPrincipal *sop = nsnull; nsIScriptObjectPrincipal *sop = nsnull;
if (JSVAL_IS_STRING(argv[0])) { if (JSVAL_IS_STRING(argv[0])) {
@ -2415,6 +2418,7 @@ nsXPCComponents_Utils::EvalInSandbox(const nsAString &source)
JSPRINCIPALS_DROP(cx, jsPrincipals); JSPRINCIPALS_DROP(cx, jsPrincipals);
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
} }
AutoJSRequestWithNoCallContext req(sandcx);
JS_SetGlobalObject(sandcx, sandbox); JS_SetGlobalObject(sandcx, sandbox);