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 107891 1233552047f475bb011dd35f6ad59dcb63659678
parent 107890 f753afbe0d85e49e52be57c6269c03ce3e30f51f
child 107892 87bcca77b8579875a593fddaa71b8ef91aee8be5
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersjorendorff
bugs791157
milestone18.0a1
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 *