Bug 880917 - Add support for "latest" as a version to evalInSandbox, and use it for sjs files. r=luke
authorBobby Holley <bobbyholley@gmail.com>
Fri, 19 Jul 2013 18:21:47 -0700
changeset 147960 3715eb057c1033801f56507cff3d89cfe238253b
parent 147959 702f0d86aeb4214c643b7eb42993d8679bdee92e
child 147961 e9c9e5508ccfd040ac5d555d53311425dec114b7
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs880917
milestone24.0a2
Bug 880917 - Add support for "latest" as a version to evalInSandbox, and use it for sjs files. r=luke Sandboxes always default to JSVERSION_DEFAULT in the browser. But XPCShell sets up a ContextCallback that does JS_SetVersion(cx, JSVERSION_LATEST) on every context that gets created, including the ephemerial Sandbox JSContexts. Since httpd.js runs in xpcshell and evaluates SJS in a sandbox, we've (somewhat accidentally) supported JSVERSION_LATEST in SJS, which certain SJS files have taken advantage of. Let's continue to support it explicitly.
js/xpconnect/src/XPCComponents.cpp
netwerk/test/httpserver/httpd.js
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -3813,16 +3813,23 @@ nsXPCComponents_Utils::EvalInSandbox(con
         if (!jsVersionStr)
             return NS_ERROR_INVALID_ARG;
 
         JSAutoByteString bytes(cx, jsVersionStr);
         if (!bytes)
             return NS_ERROR_INVALID_ARG;
 
         jsVersion = JS_StringToVersion(bytes.ptr());
+        // Explicitly check for "latest", which we support for sandboxes but
+        // isn't in the set of web-exposed version strings.
+        if (jsVersion == JSVERSION_UNKNOWN &&
+            !strcmp(bytes.ptr(), "latest"))
+        {
+            jsVersion = JSVERSION_LATEST;
+        }
         if (jsVersion == JSVERSION_UNKNOWN)
             return NS_ERROR_INVALID_ARG;
     }
 
     // Optional fourth and fifth arguments: filename and line number.
     nsXPIDLCString filename;
     int32_t lineNo = (optionalArgc >= 3) ? lineNumber : 0;
     if (optionalArgc >= 2) {
--- a/netwerk/test/httpserver/httpd.js
+++ b/netwerk/test/httpserver/httpd.js
@@ -2723,17 +2723,17 @@ ServerHandler.prototype =
         try
         {
           // Alas, the line number in errors dumped to console when calling the
           // request handler is simply an offset from where we load the SJS file.
           // Work around this in a reasonably non-fragile way by dynamically
           // getting the line number where we evaluate the SJS file.  Don't
           // separate these two lines!
           var line = new Error().lineNumber;
-          Cu.evalInSandbox(sis.read(file.fileSize), s);
+          Cu.evalInSandbox(sis.read(file.fileSize), s, "latest");
         }
         catch (e)
         {
           dumpn("*** syntax error in SJS at " + file.path + ": " + e);
           throw HTTP_500;
         }
 
         try