From 55019396a8bbf9788e4a66c47bf5a27830476a7c Mon Sep 17 00:00:00 2001 From: Jason Orendorff Date: Mon, 25 Jun 2012 14:47:33 -0500 Subject: [PATCH] Bug 765302 - Add noScriptRval option to JS shell evaluate() function. r=luke. --- js/src/shell/js.cpp | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index 668b212d0fe..1337e05b261 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -795,6 +795,7 @@ Evaluate(JSContext *cx, unsigned argc, jsval *vp) bool newContext = false; bool compileAndGo = true; + bool noScriptRval = false; const char *fileName = "@evaluate"; JSAutoByteString fileNameBytes; unsigned lineNumber = 1; @@ -814,7 +815,7 @@ Evaluate(JSContext *cx, unsigned argc, jsval *vp) JSBool b; if (!JS_ValueToBoolean(cx, v, &b)) return false; - newContext = !!b; + newContext = b; } if (!JS_GetProperty(cx, options, "compileAndGo", &v)) @@ -823,7 +824,16 @@ Evaluate(JSContext *cx, unsigned argc, jsval *vp) JSBool b; if (!JS_ValueToBoolean(cx, v, &b)) return false; - compileAndGo = !!b; + compileAndGo = b; + } + + if (!JS_GetProperty(cx, options, "noScriptRval", &v)) + return false; + if (!JSVAL_IS_VOID(v)) { + JSBool b; + if (!JS_ValueToBoolean(cx, v, &b)) + return false; + noScriptRval = b; } if (!JS_GetProperty(cx, options, "fileName", &v)) @@ -884,20 +894,18 @@ Evaluate(JSContext *cx, unsigned argc, jsval *vp) if (!aec.enter(cx, global)) return false; - if (compileAndGo) { - // JS_EvaluateUCScript always enables the compile-and-go option. - if (!JS_EvaluateUCScript(cx, global, codeChars, codeLength, fileName, lineNumber, vp)) - return false; - } else { - uint32_t saved = JS_GetOptions(cx); + 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); - JS_SetOptions(cx, saved & ~JSOPTION_COMPILE_N_GO); - JSScript *script = JS_CompileUCScript(cx, global, codeChars, codeLength, fileName, lineNumber); - JS_SetOptions(cx, saved); - - if (!script || !JS_ExecuteScript(cx, global, script, vp)) - return false; - } + JSScript *script = JS_CompileUCScript(cx, global, codeChars, codeLength, fileName, lineNumber); + JS_SetOptions(cx, saved); + if (!script || !JS_ExecuteScript(cx, global, script, vp)) + return false; } return JS_WrapValue(cx, vp); @@ -3487,6 +3495,7 @@ static JSFunctionSpecWithHelp shell_functions[] = { " Evaluate code as though it were the contents of a file.\n" " options is an optional object that may have these properties:\n" " compileAndGo: use the compile-and-go compiler option (default: true)\n" +" noScriptRval: use the no-script-rval compiler option (default: false)\n" " fileName: filename for error messages and debug info\n" " lineNumber: starting line number for error messages and debug info\n" " global: global in which to execute the code\n"