Bug 1018583 part 2. Remove the returnStringOnly gunk from sandboxes. r=bholley

This commit is contained in:
Boris Zbarsky 2014-07-04 01:22:50 -04:00
parent c5a64e9225
commit 6fa329d450
6 changed files with 10 additions and 31 deletions

View File

@ -112,8 +112,8 @@ nsresult EvaluateAdminConfigScript(const char *js_buffer, size_t length,
nsAutoCString script(js_buffer, length);
JS::RootedValue v(cx);
rv = xpc->EvalInSandboxObject(NS_ConvertASCIItoUTF16(script), filename, cx, autoconfigSb.ref(),
/* returnStringOnly = */ false, &v);
rv = xpc->EvalInSandboxObject(NS_ConvertASCIItoUTF16(script), filename, cx,
autoconfigSb.ref(), &v);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;

View File

@ -274,7 +274,7 @@ interface nsIXPCFunctionThisTranslator : nsISupports
{ 0xbd, 0xd6, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
%}
[noscript, uuid(febddcc9-5a88-4121-815a-934cd159b3e9)]
[noscript, uuid(9ec7367c-0dde-4b7a-963c-5a590ee3ee42)]
interface nsIXPConnect : nsISupports
{
%{ C++
@ -511,10 +511,6 @@ interface nsIXPConnect : nsISupports
* the script. The actual evaluation will happen on a new
* temporary context.
* @param sandbox The sandbox object to evaluate the script in.
* @param returnStringOnly The only results to come out of the
* computation (including exceptions) will
* be coerced into strings created in the
* sandbox.
* @return The result of the evaluation as a jsval. If the caller
* intends to use the return value from this call the caller
* is responsible for rooting the jsval before making a call
@ -522,8 +518,7 @@ interface nsIXPConnect : nsISupports
*/
[noscript] jsval evalInSandboxObject(in AString source, in string filename,
in JSContextPtr cx,
in JSObjectPtr sandbox,
in boolean returnStringOnly);
in JSObjectPtr sandbox);
/**
* Whether or not XPConnect should report all JS exceptions when returning

View File

@ -1505,7 +1505,7 @@ ContextHolder::~ContextHolder()
nsresult
xpc::EvalInSandbox(JSContext *cx, HandleObject sandboxArg, const nsAString& source,
const nsACString& filename, int32_t lineNo,
JSVersion jsVersion, bool returnStringOnly, MutableHandleValue rval)
JSVersion jsVersion, MutableHandleValue rval)
{
JS_AbortIfWrongThread(JS_GetRuntime(cx));
rval.set(UndefinedValue());
@ -1556,22 +1556,11 @@ xpc::EvalInSandbox(JSContext *cx, HandleObject sandboxArg, const nsAString& sour
JS::RootedObject rootedSandbox(sandcx, sandbox);
ok = JS::Evaluate(sandcx, rootedSandbox, options,
PromiseFlatString(source).get(), source.Length(), &v);
if (ok && returnStringOnly && !v.isUndefined()) {
JSString *str = ToString(sandcx, v);
ok = !!str;
v = ok ? JS::StringValue(str) : JS::UndefinedValue();
}
// If the sandbox threw an exception, grab it off the context.
if (JS_GetPendingException(sandcx, &exn)) {
MOZ_ASSERT(!ok);
JS_ClearPendingException(sandcx);
if (returnStringOnly) {
// The caller asked for strings only, convert the
// exception into a string.
JSString *str = ToString(sandcx, exn);
exn = str ? JS::StringValue(str) : JS::UndefinedValue();
}
}
}

View File

@ -2679,7 +2679,7 @@ nsXPCComponents_Utils::EvalInSandbox(const nsAString& source,
}
return xpc::EvalInSandbox(cx, sandbox, source, filename, lineNo,
jsVersion, false, retval);
jsVersion, retval);
}
NS_IMETHODIMP

View File

@ -789,7 +789,7 @@ nsXPConnect::CreateSandbox(JSContext *cx, nsIPrincipal *principal,
NS_IMETHODIMP
nsXPConnect::EvalInSandboxObject(const nsAString& source, const char *filename,
JSContext *cx, JSObject *sandboxArg,
bool returnStringOnly, MutableHandleValue rval)
MutableHandleValue rval)
{
if (!sandboxArg)
return NS_ERROR_INVALID_ARG;
@ -802,7 +802,7 @@ nsXPConnect::EvalInSandboxObject(const nsAString& source, const char *filename,
filenameStr = NS_LITERAL_CSTRING("x-bogus://XPConnect/Sandbox");
}
return EvalInSandbox(cx, sandbox, source, filenameStr, 1,
JSVERSION_DEFAULT, returnStringOnly, rval);
JSVERSION_DEFAULT, rval);
}
/* nsIXPConnectJSObjectHolder getWrappedNativePrototype (in JSContextPtr aJSContext, in JSObjectPtr aScope, in nsIClassInfo aClassInfo); */

View File

@ -3506,16 +3506,11 @@ CreateSandboxObject(JSContext *cx, JS::MutableHandleValue vp, nsISupports *prinO
// that *rval doesn't get collected during the call or usage after the
// call. This helper will use filename and lineNo for error reporting,
// and if no filename is provided it will use the codebase from the
// principal and line number 1 as a fallback. if returnStringOnly is
// true, then the result in *rval, or the exception in cx->exception
// will be coerced into strings. If an exception is thrown converting
// an exception to a string, evalInSandbox will return an NS_ERROR_*
// result, and cx->exception will be empty.
// principal and line number 1 as a fallback.
nsresult
EvalInSandbox(JSContext *cx, JS::HandleObject sandbox, const nsAString& source,
const nsACString& filename, int32_t lineNo,
JSVersion jsVersion, bool returnStringOnly,
JS::MutableHandleValue rval);
JSVersion jsVersion, JS::MutableHandleValue rval);
nsresult
GetSandboxAddonId(JSContext *cx, JS::HandleObject sandboxArg,