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.
This commit is contained in:
Bobby Holley 2013-06-29 09:11:17 -06:00
parent f5f7bf3be5
commit 4f5d414a60
3 changed files with 9 additions and 0 deletions

View File

@ -3153,11 +3153,16 @@ SameZoneAs(JSObject *obj)
struct JS_PUBLIC_API(CompartmentOptions) { struct JS_PUBLIC_API(CompartmentOptions) {
ZoneSpecifier zoneSpec; ZoneSpecifier zoneSpec;
bool hasVersion;
JSVersion version;
explicit CompartmentOptions() : zoneSpec(JS::FreshZone) explicit CompartmentOptions() : zoneSpec(JS::FreshZone)
, hasVersion(false)
, version(JSVERSION_UNKNOWN)
{} {}
CompartmentOptions &setZone(ZoneSpecifier spec) { zoneSpec = spec; return *this; } CompartmentOptions &setZone(ZoneSpecifier spec) { zoneSpec = spec; return *this; }
CompartmentOptions &setVersion(JSVersion version_) { hasVersion = true; version = version_; return *this; }
}; };
} /* namespace JS */ } /* namespace JS */

View File

@ -1536,6 +1536,9 @@ JSContext::findVersion() const
if (JSScript *script = currentScript(NULL, ALLOW_CROSS_COMPARTMENT)) if (JSScript *script = currentScript(NULL, ALLOW_CROSS_COMPARTMENT))
return script->getVersion(); return script->getVersion();
if (compartment() && compartment()->options().hasVersion)
return compartment()->options().version;
return defaultVersion; return defaultVersion;
} }

View File

@ -1802,6 +1802,7 @@ struct JSContext : js::ThreadSafeContext,
* Return: * Return:
* - The override version, if there is an override version. * - The override version, if there is an override version.
* - The newest scripted frame's version, if there is such a frame. * - The newest scripted frame's version, if there is such a frame.
* - The version from the compartment.
* - The default version. * - The default version.
* *
* Note: if this ever shows up in a profile, just add caching! * Note: if this ever shows up in a profile, just add caching!