Bug 1363200 - JSAPI for realms: JS_SetVersionForCompartment() -> JS::SetVersionForCurrentRealm(). r=sfink
authorJason Orendorff <jorendorff@mozilla.com>
Mon, 22 May 2017 14:40:13 -0500
changeset 422834 c8cb6a5096f3d472d1f65c41a93da4411742cc36
parent 422833 7556c838fcf7baf4000f54b068411874e1b9849d
child 422835 687a55549ca080f579c0136c96ebff2b52fb6470
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1363200
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1363200 - JSAPI for realms: JS_SetVersionForCompartment() -> JS::SetVersionForCurrentRealm(). r=sfink
ipc/testshell/XPCShellEnvironment.cpp
js/public/Realm.h
js/src/jsapi.cpp
js/src/jsapi.h
js/src/shell/js.cpp
js/src/vm/Realm.cpp
js/xpconnect/src/XPCShellImpl.cpp
--- a/ipc/testshell/XPCShellEnvironment.cpp
+++ b/ipc/testshell/XPCShellEnvironment.cpp
@@ -176,18 +176,17 @@ Load(JSContext *cx,
 static bool
 Version(JSContext *cx,
         unsigned argc,
         JS::Value *vp)
 {
     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;
 }
 
 static bool
 Quit(JSContext *cx,
      unsigned argc,
      JS::Value *vp)
 {
--- a/js/public/Realm.h
+++ b/js/public/Realm.h
@@ -69,13 +69,24 @@ extern JS_PUBLIC_API(JSObject*)
 GetRealmArrayPrototype(JSContext* cx);
 
 extern JS_PUBLIC_API(JSObject*)
 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
 
 
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -583,22 +583,16 @@ JS::SetSingleThreadedExecutionCallbacks(
 }
 
 JS_PUBLIC_API(JSVersion)
 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;
 } v2smap[] = {
     {JSVERSION_ECMA_3,  "ECMAv3"},
     {JSVERSION_1_6,     "1.6"},
     {JSVERSION_1_7,     "1.7"},
     {JSVERSION_1_8,     "1.8"},
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -1133,27 +1133,16 @@ class MOZ_RAII JSAutoRequest
     static void* operator new(size_t) CPP_THROW_NEW { return 0; }
     static void operator delete(void*, size_t) { }
 #endif
 };
 
 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);
 
 extern JS_PUBLIC_API(JSVersion)
 JS_StringToVersion(const char* string);
 
 namespace JS {
 
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -987,17 +987,17 @@ Version(JSContext* cx, unsigned argc, Va
             if (NumberEqualsInt32(fv, &fvi))
                 v = fvi;
         }
         if (v < 0 || v > JSVERSION_LATEST) {
             JS_ReportErrorNumberASCII(cx, my_GetErrorMessage, nullptr, JSSMSG_INVALID_ARGS,
                                       "version");
             return false;
         }
-        JS_SetVersionForCompartment(js::GetContextCompartment(cx), JSVersion(v));
+        SetVersionForCurrentRealm(cx, JSVersion(v));
         args.rval().setInt32(origVersion);
     }
     return true;
 }
 
 #ifdef XP_WIN
 #  define GET_FD_FROM_FILE(a) int(_get_osfhandle(fileno(a)))
 #else
--- a/js/src/vm/Realm.cpp
+++ b/js/src/vm/Realm.cpp
@@ -64,8 +64,15 @@ JS::GetRealmErrorPrototype(JSContext* cx
 }
 
 JS_PUBLIC_API(JSObject*)
 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);
+}
--- a/js/xpconnect/src/XPCShellImpl.cpp
+++ b/js/xpconnect/src/XPCShellImpl.cpp
@@ -387,18 +387,17 @@ Load(JSContext* cx, unsigned argc, Value
 }
 
 static bool
 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;
 }
 
 static bool
 Quit(JSContext* cx, unsigned argc, Value* vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
 
@@ -1081,18 +1080,17 @@ ProcessArgs(AutoJSAPI& jsapi, char** arg
             isInteractive = false;
             break;
         }
         switch (argv[i][1]) {
         case 'v':
             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;
             break;
         case 'w':
             reportWarnings = true;
             break;
         case 'x':