From 5df09661ffba38e045a21ca6b870c9b2eec1c496 Mon Sep 17 00:00:00 2001 From: Jason Orendorff Date: Mon, 22 May 2017 14:40:13 -0500 Subject: [PATCH] Bug 1363200 - JSAPI for realms: JS_SetVersionForCompartment() -> JS::SetVersionForCurrentRealm(). r=sfink --HG-- extra : rebase_source : 8b0d53210fe827a648251395e038cb7b9eb616e9 --- ipc/testshell/XPCShellEnvironment.cpp | 3 +-- js/public/Realm.h | 11 +++++++++++ js/src/jsapi.cpp | 6 ------ js/src/jsapi.h | 11 ----------- js/src/shell/js.cpp | 2 +- js/src/vm/Realm.cpp | 7 +++++++ js/xpconnect/src/XPCShellImpl.cpp | 6 ++---- 7 files changed, 22 insertions(+), 24 deletions(-) diff --git a/ipc/testshell/XPCShellEnvironment.cpp b/ipc/testshell/XPCShellEnvironment.cpp index fbc9238fcdaf..2c325c85f89c 100644 --- a/ipc/testshell/XPCShellEnvironment.cpp +++ b/ipc/testshell/XPCShellEnvironment.cpp @@ -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; } diff --git a/js/public/Realm.h b/js/public/Realm.h index f3e28b26076b..c8f9ed3384a9 100644 --- a/js/public/Realm.h +++ b/js/public/Realm.h @@ -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 diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index a128063e603e..ea5a7d6df66a 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -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; diff --git a/js/src/jsapi.h b/js/src/jsapi.h index 1cad7c1f2791..92754a3ae796 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -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); diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index e6b403790046..16889ef5a7d4 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -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; diff --git a/js/src/vm/Realm.cpp b/js/src/vm/Realm.cpp index 0cc155eb22a5..f60af923564c 100644 --- a/js/src/vm/Realm.cpp +++ b/js/src/vm/Realm.cpp @@ -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); +} diff --git a/js/xpconnect/src/XPCShellImpl.cpp b/js/xpconnect/src/XPCShellImpl.cpp index 00da90b0d733..46439c23ba85 100644 --- a/js/xpconnect/src/XPCShellImpl.cpp +++ b/js/xpconnect/src/XPCShellImpl.cpp @@ -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;