From ecac9eb95402d0da5fe7cbf8f639ee95d194dcdf Mon Sep 17 00:00:00 2001 From: Jan de Mooij Date: Fri, 22 Jun 2018 11:15:51 +0200 Subject: [PATCH] Bug 1465693 - Disallow toggling werror in the JS shell when there are off-thread jobs. r=jonco --- .../tests/basic/werror-off-thread-parsing.js | 7 +++++++ js/src/shell/js.cpp | 17 ++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 js/src/jit-test/tests/basic/werror-off-thread-parsing.js diff --git a/js/src/jit-test/tests/basic/werror-off-thread-parsing.js b/js/src/jit-test/tests/basic/werror-off-thread-parsing.js new file mode 100644 index 000000000000..9f53ebeab4ef --- /dev/null +++ b/js/src/jit-test/tests/basic/werror-off-thread-parsing.js @@ -0,0 +1,7 @@ +// |jit-test| error:toggle werror +if (helperThreadCount() === 0) + throw "toggle werror"; +options("werror"); +offThreadCompileScript("function f(){return 1;''}"); +options("werror"); +runOffThreadScript(); diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index 15709b7d0e21..a7145d0f70dd 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -1481,15 +1481,22 @@ Options(JSContext* cx, unsigned argc, Value* vp) if (!opt.encodeUtf8(cx, str)) return false; - if (strcmp(opt.ptr(), "strict") == 0) + if (strcmp(opt.ptr(), "strict") == 0) { JS::ContextOptionsRef(cx).toggleExtraWarnings(); - else if (strcmp(opt.ptr(), "werror") == 0) + } else if (strcmp(opt.ptr(), "werror") == 0) { + // Disallow toggling werror when there are off-thread jobs, to avoid + // confusing CompileError::throwError. + ShellContext* sc = GetShellContext(cx); + if (!sc->offThreadJobs.empty()) { + JS_ReportErrorASCII(cx, "can't toggle werror when there are off-thread jobs"); + return false; + } JS::ContextOptionsRef(cx).toggleWerror(); - else if (strcmp(opt.ptr(), "throw_on_asmjs_validation_failure") == 0) + } else if (strcmp(opt.ptr(), "throw_on_asmjs_validation_failure") == 0) { JS::ContextOptionsRef(cx).toggleThrowOnAsmJSValidationFailure(); - else if (strcmp(opt.ptr(), "strict_mode") == 0) + } else if (strcmp(opt.ptr(), "strict_mode") == 0) { JS::ContextOptionsRef(cx).toggleStrictMode(); - else { + } else { JS_ReportErrorUTF8(cx, "unknown option name '%s'." " The valid names are strict,"