From 4f5d414a609dae81b2a8406433429b98dec45882 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Sat, 29 Jun 2013 09:11:17 -0600 Subject: [PATCH] Bug 880917 - Introduce an API for callers to set the version for a compartment. r=luke This has lower precedence than 'overrides' and running script, and higher precedence than the cx's version. We can migrate the API consumers who clearly want something like this, which will eventually let us remove the override mechanism. --- js/src/jsapi.h | 5 +++++ js/src/jscntxt.cpp | 3 +++ js/src/jscntxt.h | 1 + 3 files changed, 9 insertions(+) diff --git a/js/src/jsapi.h b/js/src/jsapi.h index 8a291fbaf58..91f02cb56e9 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -3153,11 +3153,16 @@ SameZoneAs(JSObject *obj) struct JS_PUBLIC_API(CompartmentOptions) { ZoneSpecifier zoneSpec; + bool hasVersion; + JSVersion version; explicit CompartmentOptions() : zoneSpec(JS::FreshZone) + , hasVersion(false) + , version(JSVERSION_UNKNOWN) {} CompartmentOptions &setZone(ZoneSpecifier spec) { zoneSpec = spec; return *this; } + CompartmentOptions &setVersion(JSVersion version_) { hasVersion = true; version = version_; return *this; } }; } /* namespace JS */ diff --git a/js/src/jscntxt.cpp b/js/src/jscntxt.cpp index 240ac6f8714..95dc27f98e0 100644 --- a/js/src/jscntxt.cpp +++ b/js/src/jscntxt.cpp @@ -1536,6 +1536,9 @@ JSContext::findVersion() const if (JSScript *script = currentScript(NULL, ALLOW_CROSS_COMPARTMENT)) return script->getVersion(); + if (compartment() && compartment()->options().hasVersion) + return compartment()->options().version; + return defaultVersion; } diff --git a/js/src/jscntxt.h b/js/src/jscntxt.h index ea996ab5dec..d50eb5146a8 100644 --- a/js/src/jscntxt.h +++ b/js/src/jscntxt.h @@ -1802,6 +1802,7 @@ struct JSContext : js::ThreadSafeContext, * Return: * - The override version, if there is an override version. * - The newest scripted frame's version, if there is such a frame. + * - The version from the compartment. * - The default version. * * Note: if this ever shows up in a profile, just add caching!