From 6fa329d450c5c3479cb68b95bb5068d622252bd9 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 4 Jul 2014 01:22:50 -0400 Subject: [PATCH] Bug 1018583 part 2. Remove the returnStringOnly gunk from sandboxes. r=bholley --- .../pref/autoconfig/src/nsJSConfigTriggers.cpp | 4 ++-- js/xpconnect/idl/nsIXPConnect.idl | 9 ++------- js/xpconnect/src/Sandbox.cpp | 13 +------------ js/xpconnect/src/XPCComponents.cpp | 2 +- js/xpconnect/src/nsXPConnect.cpp | 4 ++-- js/xpconnect/src/xpcprivate.h | 9 ++------- 6 files changed, 10 insertions(+), 31 deletions(-) diff --git a/extensions/pref/autoconfig/src/nsJSConfigTriggers.cpp b/extensions/pref/autoconfig/src/nsJSConfigTriggers.cpp index 47e077f554d..03bd530ad96 100644 --- a/extensions/pref/autoconfig/src/nsJSConfigTriggers.cpp +++ b/extensions/pref/autoconfig/src/nsJSConfigTriggers.cpp @@ -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; diff --git a/js/xpconnect/idl/nsIXPConnect.idl b/js/xpconnect/idl/nsIXPConnect.idl index 758a1c8cc42..3dd07076bd6 100644 --- a/js/xpconnect/idl/nsIXPConnect.idl +++ b/js/xpconnect/idl/nsIXPConnect.idl @@ -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 diff --git a/js/xpconnect/src/Sandbox.cpp b/js/xpconnect/src/Sandbox.cpp index a6d90b6ed16..572e914bc54 100644 --- a/js/xpconnect/src/Sandbox.cpp +++ b/js/xpconnect/src/Sandbox.cpp @@ -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(); - } } } diff --git a/js/xpconnect/src/XPCComponents.cpp b/js/xpconnect/src/XPCComponents.cpp index b448d126947..6ae5160dc11 100644 --- a/js/xpconnect/src/XPCComponents.cpp +++ b/js/xpconnect/src/XPCComponents.cpp @@ -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 diff --git a/js/xpconnect/src/nsXPConnect.cpp b/js/xpconnect/src/nsXPConnect.cpp index ce3258fe931..1f57a5471be 100644 --- a/js/xpconnect/src/nsXPConnect.cpp +++ b/js/xpconnect/src/nsXPConnect.cpp @@ -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); */ diff --git a/js/xpconnect/src/xpcprivate.h b/js/xpconnect/src/xpcprivate.h index e57a67a206f..008d9c53062 100644 --- a/js/xpconnect/src/xpcprivate.h +++ b/js/xpconnect/src/xpcprivate.h @@ -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,