Bug 791157: Make sure the shell's 'evaluate' function properly restores the JSContext options. r=jorendorff
authorJim Blandy <jimb@mozilla.com>
Fri, 21 Sep 2012 16:10:30 -0700
changeset 107766 1233552047f475bb011dd35f6ad59dcb63659678
parent 107765 f753afbe0d85e49e52be57c6269c03ce3e30f51f
child 107767 87bcca77b8579875a593fddaa71b8ef91aee8be5
push id15209
push userjblandy@mozilla.com
push dateFri, 21 Sep 2012 23:09:58 +0000
treeherdermozilla-inbound@1233552047f4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs791157
milestone18.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 791157: Make sure the shell's 'evaluate' function properly restores the JSContext options. r=jorendorff
js/src/jit-test/tests/basic/evaluate-restore-options.js
js/src/shell/js.cpp
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/basic/evaluate-restore-options.js
@@ -0,0 +1,11 @@
+// Bug 791157: the shell 'evaluate' function should properly restore the
+// context's options.
+
+try {
+    evaluate('%', {noScriptRval: true});
+} catch(e) {}
+new Function("");
+
+try {
+  evaluate('new Function("");', {noScriptRval: true});
+} catch (e) {}
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -897,26 +897,27 @@ Evaluate(JSContext *cx, unsigned argc, j
     {
         JSAutoCompartment ac(cx, global);
         uint32_t saved = JS_GetOptions(cx);
         uint32_t options = saved & ~(JSOPTION_COMPILE_N_GO | JSOPTION_NO_SCRIPT_RVAL);
         if (compileAndGo)
             options |= JSOPTION_COMPILE_N_GO;
         if (noScriptRval)
             options |= JSOPTION_NO_SCRIPT_RVAL;
+
         JS_SetOptions(cx, options);
-
         JSScript *script = JS_CompileUCScript(cx, global, codeChars, codeLength, fileName, lineNumber);
+        JS_SetOptions(cx, saved);
         if (!script)
             return false;
+
         if (sourceMapURL && !script->scriptSource()->hasSourceMap()) {
             if (!script->scriptSource()->setSourceMap(cx, sourceMapURL, script->filename))
                 return false;
         }
-        JS_SetOptions(cx, saved);
         if (!JS_ExecuteScript(cx, global, script, vp))
             return false;
     }
 
     return JS_WrapValue(cx, vp);
 }
 
 static JSString *