diff --git a/js/src/frontend/BytecodeEmitter.h b/js/src/frontend/BytecodeEmitter.h index c0ed8a73f35b..e1c6ad24f14d 100644 --- a/js/src/frontend/BytecodeEmitter.h +++ b/js/src/frontend/BytecodeEmitter.h @@ -426,6 +426,8 @@ struct TreeContext { /* tree context for semantic checks */ }; bool init(JSContext *cx, InitBehavior ib = USED_AS_TREE_CONTEXT) { + if (cx->hasRunOption(JSOPTION_STRICT_MODE)) + flags |= TCF_STRICT_MODE_CODE; if (ib == USED_AS_CODE_GENERATOR) return true; return decls.init() && lexdeps.ensureMap(cx); diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index f89cb9de606a..33e2300835e9 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -144,6 +144,8 @@ Parser::init(const jschar *base, size_t length, const char *filename, unsigned l cx->tempLifoAlloc().release(tempPoolMark); return false; } + if (context->hasRunOption(JSOPTION_STRICT_MODE)) + tokenStream.setStrictMode(); return true; } diff --git a/js/src/jsapi.h b/js/src/jsapi.h index 5a8c3f5ea8ec..55191565ac07 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -2768,11 +2768,15 @@ JS_StringToVersion(const char *string); #define JSOPTION_PCCOUNT JS_BIT(17) /* Collect per-op execution counts */ #define JSOPTION_TYPE_INFERENCE JS_BIT(18) /* Perform type inference. */ +#define JSOPTION_STRICT_MODE JS_BIT(19) /* Provides a way to force + strict mode for all code + without requiring + "use strict" annotations. */ /* Options which reflect compile-time properties of scripts. */ #define JSCOMPILEOPTION_MASK (JSOPTION_XML) -#define JSRUNOPTION_MASK (JS_BITMASK(19) & ~JSCOMPILEOPTION_MASK) +#define JSRUNOPTION_MASK (JS_BITMASK(20) & ~JSCOMPILEOPTION_MASK) #define JSALLOPTION_MASK (JSCOMPILEOPTION_MASK | JSRUNOPTION_MASK) extern JS_PUBLIC_API(uint32_t) diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index 36e66d79dd27..c025fb69f1a0 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -618,6 +618,7 @@ static const struct JSOption { {"typeinfer", JSOPTION_TYPE_INFERENCE}, {"werror", JSOPTION_WERROR}, {"xml", JSOPTION_XML}, + {"strict_mode", JSOPTION_STRICT_MODE}, }; static uint32_t diff --git a/js/src/tests/browser.js b/js/src/tests/browser.js index bbd312ba99d9..977f107d76d7 100644 --- a/js/src/tests/browser.js +++ b/js/src/tests/browser.js @@ -224,7 +224,8 @@ function optionsInit() { xml: true, relimit: true, methodjit: true, - methodjit_always: true + methodjit_always: true, + strict_mode: true }; // record initial values to support resetting diff --git a/js/src/tests/js1_8_5/regress/regress-736792.js b/js/src/tests/js1_8_5/regress/regress-736792.js new file mode 100644 index 000000000000..01744f6a8e0e --- /dev/null +++ b/js/src/tests/js1_8_5/regress/regress-736792.js @@ -0,0 +1,23 @@ +/* + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/licenses/publicdomain/ + */ + +if (typeof options == "function") { + var opts = options(); + if (!/\bstrict_mode\b/.test(opts)) + options("strict_mode"); +} + +var ok = false; +try { + eval('foo = true;'); +} catch (e) { + if (/^ReferenceError:/.test(e.toString())) + ok = true; +} + +if (ok) + reportCompare(0, 0, "ok"); +else + reportCompare(true, false, "this should have thrown a ReferenceError"); diff --git a/js/xpconnect/idl/xpccomponents.idl b/js/xpconnect/idl/xpccomponents.idl index edf2e24aeb5c..62ff4958f633 100644 --- a/js/xpconnect/idl/xpccomponents.idl +++ b/js/xpconnect/idl/xpccomponents.idl @@ -360,6 +360,9 @@ interface nsIXPCComponents_Utils : nsISupports [implicit_jscontext] attribute boolean methodjit_always; + [implicit_jscontext] + attribute boolean strict_mode; + [implicit_jscontext] void setGCZeal(in long zeal); }; diff --git a/js/xpconnect/shell/xpcshell.cpp b/js/xpconnect/shell/xpcshell.cpp index 975da7ab3101..1ca7e53ceb99 100644 --- a/js/xpconnect/shell/xpcshell.cpp +++ b/js/xpconnect/shell/xpcshell.cpp @@ -717,6 +717,7 @@ static const struct JSOption { {"strict", JSOPTION_STRICT}, {"werror", JSOPTION_WERROR}, {"xml", JSOPTION_XML}, + {"strict_mode", JSOPTION_STRICT_MODE}, }; static uint32_t diff --git a/js/xpconnect/src/XPCComponents.cpp b/js/xpconnect/src/XPCComponents.cpp index e402d038e1f0..9c36d3837932 100644 --- a/js/xpconnect/src/XPCComponents.cpp +++ b/js/xpconnect/src/XPCComponents.cpp @@ -4092,6 +4092,7 @@ GENERATE_JSOPTION_GETTER_SETTER(Xml, JSOPTION_XML) GENERATE_JSOPTION_GETTER_SETTER(Relimit, JSOPTION_RELIMIT) GENERATE_JSOPTION_GETTER_SETTER(Methodjit, JSOPTION_METHODJIT) GENERATE_JSOPTION_GETTER_SETTER(Methodjit_always, JSOPTION_METHODJIT_ALWAYS) +GENERATE_JSOPTION_GETTER_SETTER(Strict_mode, JSOPTION_STRICT_MODE) #undef GENERATE_JSOPTION_GETTER_SETTER