From 8a63d768844b1d3869b8561e9ccfbb6f6ca99867 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Thu, 13 Jun 2013 10:09:26 -0700 Subject: [PATCH] Bug 880917 - Convert JS_SetVersion API consumers to per-compartment versions. r=luke --- content/base/src/nsFrameMessageManager.cpp | 4 ++-- dom/workers/RuntimeService.cpp | 4 ---- dom/workers/WorkerScope.cpp | 5 ++++- ipc/testshell/XPCShellEnvironment.cpp | 4 ++-- js/src/gdb/gdb-tests.cpp | 5 +++-- js/src/jsapi-tests/tests.cpp | 4 +++- js/src/jsapi-tests/tests.h | 1 - js/src/shell/js.cpp | 4 ++-- js/xpconnect/loader/mozJSComponentLoader.cpp | 6 ++---- js/xpconnect/shell/xpcshell.cpp | 4 ++-- js/xpconnect/src/XPCComponents.cpp | 5 ++--- netwerk/base/src/ProxyAutoConfig.cpp | 4 ++-- 12 files changed, 24 insertions(+), 26 deletions(-) diff --git a/content/base/src/nsFrameMessageManager.cpp b/content/base/src/nsFrameMessageManager.cpp index 9209b5ba8c3b..b89240d60399 100644 --- a/content/base/src/nsFrameMessageManager.cpp +++ b/content/base/src/nsFrameMessageManager.cpp @@ -1108,7 +1108,6 @@ nsFrameScriptExecutor::InitTabChildGlobalInternal(nsISupports* aScope, nsContentUtils::GetSecurityManager()->GetSystemPrincipal(getter_AddRefs(mPrincipal)); JS_SetOptions(cx, JS_GetOptions(cx) | JSOPTION_PRIVATE_IS_NSISUPPORTS); - JS_SetVersion(cx, JSVERSION_LATEST); JS_SetErrorReporter(cx, ContentScriptErrorReporter); nsIXPConnect* xpc = nsContentUtils::XPConnect(); @@ -1118,7 +1117,8 @@ nsFrameScriptExecutor::InitTabChildGlobalInternal(nsISupports* aScope, JS_SetContextPrivate(cx, aScope); JS::CompartmentOptions options; - options.setZone(JS::SystemZone); + options.setZone(JS::SystemZone) + .setVersion(JSVERSION_LATEST); nsresult rv = xpc->InitClassesWithNewWrappedGlobal(cx, aScope, mPrincipal, flags, options, getter_AddRefs(mGlobal)); diff --git a/dom/workers/RuntimeService.cpp b/dom/workers/RuntimeService.cpp index 89d0f72a1afd..fb5ad18a7bde 100644 --- a/dom/workers/RuntimeService.cpp +++ b/dom/workers/RuntimeService.cpp @@ -829,10 +829,6 @@ CreateJSContextForWorker(WorkerPrivate* aWorkerPrivate) JS_SetGCZeal(workerCx, settings.gcZeal, settings.gcZealFrequency); #endif - if (aWorkerPrivate->IsChromeWorker()) { - JS_SetVersion(workerCx, JSVERSION_LATEST); - } - return workerCx; } diff --git a/dom/workers/WorkerScope.cpp b/dom/workers/WorkerScope.cpp index 6a9bd62e26f3..00dc3d6b7a71 100644 --- a/dom/workers/WorkerScope.cpp +++ b/dom/workers/WorkerScope.cpp @@ -967,9 +967,12 @@ CreateDedicatedWorkerGlobalScope(JSContext* aCx) WorkerPrivate* worker = GetWorkerPrivateFromContext(aCx); JS_ASSERT(worker); + JS::CompartmentOptions options; + if (worker->IsChromeWorker()) + options.setVersion(JSVERSION_LATEST); JS::Rooted global(aCx, JS_NewGlobalObject(aCx, DedicatedWorkerGlobalScope::Class(), - GetWorkerPrincipal())); + GetWorkerPrincipal(), options)); if (!global) { return NULL; } diff --git a/ipc/testshell/XPCShellEnvironment.cpp b/ipc/testshell/XPCShellEnvironment.cpp index fc746b7140aa..8e247a29c919 100644 --- a/ipc/testshell/XPCShellEnvironment.cpp +++ b/ipc/testshell/XPCShellEnvironment.cpp @@ -188,7 +188,6 @@ ContextCallback(JSContext *cx, if (contextOp == JSCONTEXT_NEW) { JS_SetErrorReporter(cx, ScriptErrorReporter); - JS_SetVersion(cx, JSVERSION_LATEST); } return JS_TRUE; } @@ -784,7 +783,8 @@ XPCShellEnvironment::Init() } JS::CompartmentOptions options; - options.setZone(JS::SystemZone); + options.setZone(JS::SystemZone) + .setVersion(JSVERSION_LATEST); nsCOMPtr holder; rv = xpc->InitClassesWithNewWrappedGlobal(cx, static_cast(backstagePass), diff --git a/js/src/gdb/gdb-tests.cpp b/js/src/gdb/gdb-tests.cpp index a5ce25cf364d..8398859818c1 100644 --- a/js/src/gdb/gdb-tests.cpp +++ b/js/src/gdb/gdb-tests.cpp @@ -62,13 +62,14 @@ main (int argc, const char **argv) JS_SetNativeStackQuota(runtime, 5000000); JSContext *cx = checkPtr(JS_NewContext(runtime, 8192)); - JS_SetVersion(cx, JSVERSION_LATEST); JS_SetErrorReporter(cx, reportError); JSAutoRequest ar(cx); /* Create the global object. */ - RootedObject global(cx, checkPtr(JS_NewGlobalObject(cx, &global_class, NULL))); + JS::CompartmentOptions options; + options.setVersion(JSVERSION_LATEST); + RootedObject global(cx, checkPtr(JS_NewGlobalObject(cx, &global_class, NULL, options))); JS_SetGlobalObject(cx, global); JSAutoCompartment ac(cx, global); diff --git a/js/src/jsapi-tests/tests.cpp b/js/src/jsapi-tests/tests.cpp index 30b89be2d3b8..9267eb6b2cbc 100644 --- a/js/src/jsapi-tests/tests.cpp +++ b/js/src/jsapi-tests/tests.cpp @@ -51,7 +51,9 @@ bool JSAPITest::definePrint() JSObject * JSAPITest::createGlobal(JSPrincipals *principals) { /* Create the global object. */ - global = JS_NewGlobalObject(cx, getGlobalClass(), principals); + JS::CompartmentOptions options; + options.setVersion(JSVERSION_LATEST); + global = JS_NewGlobalObject(cx, getGlobalClass(), principals, options); if (!global) return NULL; JS_AddNamedObjectRoot(cx, &global, "test-global"); diff --git a/js/src/jsapi-tests/tests.h b/js/src/jsapi-tests/tests.h index c3c7e4cb8265..b2e3ed50b839 100644 --- a/js/src/jsapi-tests/tests.h +++ b/js/src/jsapi-tests/tests.h @@ -299,7 +299,6 @@ class JSAPITest if (!cx) return NULL; JS_SetOptions(cx, JSOPTION_VAROBJFIX); - JS_SetVersion(cx, JSVERSION_LATEST); JS_SetErrorReporter(cx, &reportError); return cx; } diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index 823137fdacd2..224df8601801 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -4774,7 +4774,6 @@ NewContext(JSRuntime *rt) JS_SetContextPrivate(cx, data); JS_SetErrorReporter(cx, my_ErrorReporter); - JS_SetVersion(cx, JSVERSION_LATEST); SetContextOptions(cx); if (enableTypeInference) JS_ToggleOptions(cx, JSOPTION_TYPE_INFERENCE); @@ -4800,7 +4799,8 @@ static JSObject * NewGlobalObject(JSContext *cx, JSObject *sameZoneAs) { JS::CompartmentOptions options; - options.setZone(sameZoneAs ? JS::SameZoneAs(sameZoneAs) : JS::FreshZone); + options.setZone(sameZoneAs ? JS::SameZoneAs(sameZoneAs) : JS::FreshZone) + .setVersion(JSVERSION_LATEST); RootedObject glob(cx, JS_NewGlobalObject(cx, &global_class, NULL, options)); if (!glob) return NULL; diff --git a/js/xpconnect/loader/mozJSComponentLoader.cpp b/js/xpconnect/loader/mozJSComponentLoader.cpp index a3340ccc2b00..36040843005e 100644 --- a/js/xpconnect/loader/mozJSComponentLoader.cpp +++ b/js/xpconnect/loader/mozJSComponentLoader.cpp @@ -460,9 +460,6 @@ mozJSComponentLoader::ReallyInit() if (!mContext) return NS_ERROR_OUT_OF_MEMORY; - // Always use the latest js version - JS_SetVersion(mContext, JSVERSION_LATEST); - nsCOMPtr secman = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID); if (!secman) @@ -727,7 +724,8 @@ mozJSComponentLoader::PrepareObjectForLocation(JSCLContextHelper& aCx, NS_ENSURE_SUCCESS(rv, nullptr); JS::CompartmentOptions options; - options.setZone(JS::SystemZone); + options.setZone(JS::SystemZone) + .setVersion(JSVERSION_LATEST); rv = xpc->InitClassesWithNewWrappedGlobal(aCx, static_cast(backstagePass), mSystemPrincipal, diff --git a/js/xpconnect/shell/xpcshell.cpp b/js/xpconnect/shell/xpcshell.cpp index b8ffc10d9f4c..6be520e96d1c 100644 --- a/js/xpconnect/shell/xpcshell.cpp +++ b/js/xpconnect/shell/xpcshell.cpp @@ -1400,7 +1400,6 @@ ContextCallback(JSContext *cx, unsigned contextOp) if (contextOp == JSCONTEXT_NEW) { JS_SetErrorReporter(cx, my_ErrorReporter); - JS_SetVersion(cx, JSVERSION_LATEST); } return true; } @@ -1635,7 +1634,8 @@ main(int argc, char **argv, char **envp) } JS::CompartmentOptions options; - options.setZone(JS::SystemZone); + options.setZone(JS::SystemZone) + .setVersion(JSVERSION_LATEST); nsCOMPtr holder; rv = xpc->InitClassesWithNewWrappedGlobal(cx, static_cast(backstagePass), diff --git a/js/xpconnect/src/XPCComponents.cpp b/js/xpconnect/src/XPCComponents.cpp index 32da95bfd9fd..fe6c6d7295c0 100644 --- a/js/xpconnect/src/XPCComponents.cpp +++ b/js/xpconnect/src/XPCComponents.cpp @@ -3913,12 +3913,11 @@ xpc_EvalInSandbox(JSContext *cx, HandleObject sandboxArg, const nsAString& sourc pusher.Push(sandcx); JSAutoCompartment ac(sandcx, sandbox); - if (jsVersion != JSVERSION_DEFAULT) - JS_SetVersion(sandcx, jsVersion); - JS::CompileOptions options(sandcx); options.setPrincipals(nsJSPrincipals::get(prin)) .setFileAndLine(filename, lineNo); + if (jsVersion != JSVERSION_DEFAULT) + options.setVersion(jsVersion); JS::RootedObject rootedSandbox(sandcx, sandbox); ok = JS::Evaluate(sandcx, rootedSandbox, options, PromiseFlatString(source).get(), source.Length(), diff --git a/netwerk/base/src/ProxyAutoConfig.cpp b/netwerk/base/src/ProxyAutoConfig.cpp index 26ed6fbd19b0..a70754d98bea 100644 --- a/netwerk/base/src/ProxyAutoConfig.cpp +++ b/netwerk/base/src/ProxyAutoConfig.cpp @@ -537,14 +537,14 @@ private: JSAutoRequest ar(mContext); JS::CompartmentOptions options; - options.setZone(JS::SystemZone); + options.setZone(JS::SystemZone) + .setVersion(JSVERSION_LATEST); mGlobal = JS_NewGlobalObject(mContext, &sGlobalClass, nullptr, options); NS_ENSURE_TRUE(mGlobal, NS_ERROR_OUT_OF_MEMORY); JS_SetGlobalObject(mContext, mGlobal); JS_InitStandardClasses(mContext, mGlobal); - JS_SetVersion(mContext, JSVERSION_LATEST); JS_SetErrorReporter(mContext, PACErrorReporter); if (!JS_DefineFunctions(mContext, mGlobal, PACGlobalFunctions))