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-13 10:09:25 -07:00
Родитель c9c12ae8ba
Коммит 2685398e0e
3 изменённых файлов: 9 добавлений и 0 удалений

Просмотреть файл

@ -3146,11 +3146,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 */

Просмотреть файл

@ -1691,6 +1691,7 @@ struct JSContext : js::ContextFriendFields,
* 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!

Просмотреть файл

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