Bug 1363200 - JSAPI for realms: JS_SetVersionForCompartment() -> JS::SetVersionForCurrentRealm(). r=sfink

--HG--
extra : rebase_source : 8b0d53210fe827a648251395e038cb7b9eb616e9
This commit is contained in:
Jason Orendorff 2017-05-22 14:40:13 -05:00
parent 8399e3ecd5
commit 5df09661ff
7 changed files with 22 additions and 24 deletions

View File

@ -181,8 +181,7 @@ Version(JSContext *cx,
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
args.rval().setInt32(JS_GetVersion(cx));
if (args.get(0).isInt32())
JS_SetVersionForCompartment(js::GetContextCompartment(cx),
JSVersion(args[0].toInt32()));
JS::SetVersionForCurrentRealm(cx, JSVersion(args[0].toInt32()));
return true;
}

View File

@ -74,6 +74,17 @@ GetRealmErrorPrototype(JSContext* cx);
extern JS_PUBLIC_API(JSObject*)
GetRealmIteratorPrototype(JSContext* cx);
/**
* Change the JS language version for the current Realm. This is discouraged,
* but necessary to support the `version()` builtin function in the js and xpc
* shells.
*
* It would be nice to put this in jsfriendapi, but the linkage requirements
* of the shells make that impossible.
*/
JS_PUBLIC_API(void)
SetVersionForCurrentRealm(JSContext* cx, JSVersion version);
} // namespace JS
#endif // js_Realm_h

View File

@ -588,12 +588,6 @@ JS_GetVersion(JSContext* cx)
return VersionNumber(cx->findVersion());
}
JS_PUBLIC_API(void)
JS_SetVersionForCompartment(JSCompartment* compartment, JSVersion version)
{
compartment->behaviors().setVersion(version);
}
static const struct v2smap {
JSVersion version;
const char* string;

View File

@ -1138,17 +1138,6 @@ class MOZ_RAII JSAutoRequest
extern JS_PUBLIC_API(JSVersion)
JS_GetVersion(JSContext* cx);
/**
* Mutate the version on the compartment. This is generally discouraged, but
* necessary to support the version mutation in the js and xpc shell command
* set.
*
* It would be nice to put this in jsfriendapi, but the linkage requirements
* of the shells make that impossible.
*/
JS_PUBLIC_API(void)
JS_SetVersionForCompartment(JSCompartment* compartment, JSVersion version);
extern JS_PUBLIC_API(const char*)
JS_VersionToString(JSVersion version);

View File

@ -992,7 +992,7 @@ Version(JSContext* cx, unsigned argc, Value* vp)
"version");
return false;
}
JS_SetVersionForCompartment(js::GetContextCompartment(cx), JSVersion(v));
SetVersionForCurrentRealm(cx, JSVersion(v));
args.rval().setInt32(origVersion);
}
return true;

View File

@ -69,3 +69,10 @@ JS::GetRealmIteratorPrototype(JSContext* cx)
CHECK_REQUEST(cx);
return GlobalObject::getOrCreateIteratorPrototype(cx, cx->global());
}
JS_PUBLIC_API(void)
JS::SetVersionForCurrentRealm(JSContext* cx, JSVersion version)
{
JSCompartment* compartment = GetContextCompartment(cx);
compartment->behaviors().setVersion(version);
}

View File

@ -392,8 +392,7 @@ Version(JSContext* cx, unsigned argc, Value* vp)
CallArgs args = CallArgsFromVp(argc, vp);
args.rval().setInt32(JS_GetVersion(cx));
if (args.get(0).isInt32())
JS_SetVersionForCompartment(js::GetContextCompartment(cx),
JSVersion(args[0].toInt32()));
SetVersionForCurrentRealm(cx, JSVersion(args[0].toInt32()));
return true;
}
@ -1086,8 +1085,7 @@ ProcessArgs(AutoJSAPI& jsapi, char** argv, int argc, XPCShellDirProvider* aDirPr
if (++i == argc) {
return printUsageAndSetExitCode();
}
JS_SetVersionForCompartment(js::GetContextCompartment(cx),
JSVersion(atoi(argv[i])));
SetVersionForCurrentRealm(cx, JSVersion(atoi(argv[i])));
break;
case 'W':
reportWarnings = false;