Bug 856257 - Clean up nsXPConnect sandbox API a bit. r=mrbkap

This commit is contained in:
Bobby Holley 2013-04-02 09:45:01 -07:00
parent b72bc01b64
commit d9e8801803
3 changed files with 12 additions and 16 deletions

View File

@ -296,8 +296,6 @@ nsresult nsJSThunk::EvaluateScript(nsIChannel *aChannel,
NS_ENSURE_SUCCESS(rv, rv);
sandboxObj = js::UnwrapObject(sandboxObj);
JSAutoCompartment ac(cx, sandboxObj);
rv = xpc->HoldObject(cx, sandboxObj, getter_AddRefs(sandbox));
NS_ENSURE_SUCCESS(rv, rv);
// Push our JSContext on the context stack so the JS_ValueToString call (and
// JS_ReportPendingException, if relevant) will use the principal of cx.
@ -311,8 +309,9 @@ nsresult nsJSThunk::EvaluateScript(nsIChannel *aChannel,
return rv;
}
rv = xpc->EvalInSandboxObject(NS_ConvertUTF8toUTF16(script), cx,
sandbox, true, &v);
rv = xpc->EvalInSandboxObject(NS_ConvertUTF8toUTF16(script),
/* filename = */ nullptr, cx,
sandboxObj, true, &v);
// Propagate and report exceptions that happened in the
// sandbox.

View File

@ -290,7 +290,7 @@ interface nsIXPCFunctionThisTranslator : nsISupports
{ 0xbd, 0xd6, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
%}
[uuid(7dc3a740-7ba9-11e2-b92a-0800200c9a66)]
[uuid(7e7a9a90-4607-4e3a-8ef1-b0f4b8de1c27)]
interface nsIXPConnect : nsISupports
{
%{ C++
@ -553,6 +553,7 @@ interface nsIXPConnect : nsISupports
* other running scripts.
*
* @param source The source of the script to evaluate.
* @param filename The filename of the script. May be null.
* @param cx The context to use when setting up the evaluation of
* the script. The actual evaluation will happen on a new
* temporary context.
@ -566,8 +567,9 @@ interface nsIXPConnect : nsISupports
* is responsible for rooting the jsval before making a call
* to this method.
*/
[noscript] jsval evalInSandboxObject(in AString source, in JSContextPtr cx,
in nsIXPConnectJSObjectHolder sandbox,
[noscript] jsval evalInSandboxObject(in AString source, in string filename,
in JSContextPtr cx,
in JSObjectPtr sandbox,
in boolean returnStringOnly);
/**

View File

@ -1656,20 +1656,15 @@ nsXPConnect::CreateSandbox(JSContext *cx, nsIPrincipal *principal,
}
NS_IMETHODIMP
nsXPConnect::EvalInSandboxObject(const nsAString& source, JSContext *cx,
nsIXPConnectJSObjectHolder *sandbox,
nsXPConnect::EvalInSandboxObject(const nsAString& source, const char *filename,
JSContext *cx, JSObject *sandbox,
bool returnStringOnly, jsval *rval)
{
if (!sandbox)
return NS_ERROR_INVALID_ARG;
JSObject *obj;
nsresult rv = sandbox->GetJSObject(&obj);
NS_ENSURE_SUCCESS(rv, rv);
return xpc_EvalInSandbox(cx, obj, source,
NS_ConvertUTF16toUTF8(source).get(), 1,
JSVERSION_DEFAULT, returnStringOnly, rval);
return xpc_EvalInSandbox(cx, sandbox, source, filename ? filename : "x-bogus://XPConnect/Sandbox",
1, JSVERSION_DEFAULT, returnStringOnly, rval);
}
/* nsIXPConnectJSObjectHolder getWrappedNativePrototype (in JSContextPtr aJSContext, in JSObjectPtr aScope, in nsIClassInfo aClassInfo); */