From 68b080c7c5fc5e464a1c7677df93691fc95e5910 Mon Sep 17 00:00:00 2001 From: Mike Kaply Date: Tue, 28 Jul 2015 13:57:55 -0500 Subject: [PATCH] Bug 1152512 - Use the latest JavaScript version when parsing AutoConfig files. r=mrbkap --HG-- extra : rebase_source : 4527671894b43e60e16d4b6be5e6af55b68b6ebe --- extensions/pref/autoconfig/src/nsJSConfigTriggers.cpp | 2 +- js/xpconnect/idl/nsIXPConnect.idl | 7 +++++-- js/xpconnect/src/nsXPConnect.cpp | 9 ++++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/extensions/pref/autoconfig/src/nsJSConfigTriggers.cpp b/extensions/pref/autoconfig/src/nsJSConfigTriggers.cpp index 8f46cef7419d..e2339ebefaa2 100644 --- a/extensions/pref/autoconfig/src/nsJSConfigTriggers.cpp +++ b/extensions/pref/autoconfig/src/nsJSConfigTriggers.cpp @@ -107,7 +107,7 @@ nsresult EvaluateAdminConfigScript(const char *js_buffer, size_t length, nsAutoCString script(js_buffer, length); JS::RootedValue v(cx); rv = xpc->EvalInSandboxObject(NS_ConvertUTF8toUTF16(script), filename, cx, - autoconfigSb, &v); + autoconfigSb, JSVERSION_LATEST, &v); NS_ENSURE_SUCCESS(rv, rv); return NS_OK; diff --git a/js/xpconnect/idl/nsIXPConnect.idl b/js/xpconnect/idl/nsIXPConnect.idl index 868743ecf2bd..0edde65a4da3 100644 --- a/js/xpconnect/idl/nsIXPConnect.idl +++ b/js/xpconnect/idl/nsIXPConnect.idl @@ -266,7 +266,7 @@ interface nsIXPCFunctionThisTranslator : nsISupports { 0xbd, 0xd6, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } } %} -[noscript, uuid(db83b3af-ac22-4dd2-99cf-7f79270ed4cd)] +[noscript, uuid(f339ea52-10ce-4103-b1f2-fd9659040e3c)] interface nsIXPConnect : nsISupports { %{ C++ @@ -486,6 +486,8 @@ 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 version The JavaScript version to use for evaluating the script. + * Should be a valid JSVersion from jspubtd.h. * @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 @@ -493,7 +495,8 @@ interface nsIXPConnect : nsISupports */ [noscript] jsval evalInSandboxObject(in AString source, in string filename, in JSContextPtr cx, - in JSObjectPtr sandbox); + in JSObjectPtr sandbox, + in int32_t version); /** * Whether or not XPConnect should report all JS exceptions when returning diff --git a/js/xpconnect/src/nsXPConnect.cpp b/js/xpconnect/src/nsXPConnect.cpp index 541dbb258947..26ae533daa69 100644 --- a/js/xpconnect/src/nsXPConnect.cpp +++ b/js/xpconnect/src/nsXPConnect.cpp @@ -771,8 +771,15 @@ nsXPConnect::CreateSandbox(JSContext* cx, nsIPrincipal* principal, NS_IMETHODIMP nsXPConnect::EvalInSandboxObject(const nsAString& source, const char* filename, JSContext* cx, JSObject* sandboxArg, + int32_t jsVersion, MutableHandleValue rval) { +#ifdef DEBUG + { + const char *version = JS_VersionToString(JSVersion(jsVersion)); + MOZ_ASSERT(version && strcmp(version, "unknown") != 0, "Illegal JS version passed"); + } +#endif if (!sandboxArg) return NS_ERROR_INVALID_ARG; @@ -784,7 +791,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_LATEST, rval); + JSVersion(jsVersion), rval); } /* JSObjectPtr getWrappedNativePrototype (in JSContextPtr aJSContext, in JSObjectPtr aScope); */