diff options
author | Nathan Rajlich <nathan@tootallnate.net> | 2013-03-30 13:10:30 -0700 |
---|---|---|
committer | Nathan Rajlich <nathan@tootallnate.net> | 2013-03-30 13:10:30 -0700 |
commit | 085f9d636b260724af2e80d6757e9d0f4bcd9193 (patch) | |
tree | 29c1c21dce7ef28b609efb6c24417e8e63fc3238 | |
parent | 7af075ee30485e6f2d295d3ad32923dd5ecb7536 (diff) | |
download | node-085f9d636b260724af2e80d6757e9d0f4bcd9193.tar.gz |
repl: isSyntaxError() catches "strict mode" errors
Closes #5178.
-rw-r--r-- | lib/repl.js | 2 | ||||
-rw-r--r-- | test/simple/test-repl.js | 15 |
2 files changed, 17 insertions, 0 deletions
diff --git a/lib/repl.js b/lib/repl.js index f0c1cb270..522bfd7d5 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -920,6 +920,8 @@ function isSyntaxError(e) { // RegExp syntax error !e.match(/^SyntaxError: Invalid regular expression/) && !e.match(/^SyntaxError: Invalid flags supplied to RegExp constructor/) && + // "strict mode" syntax errors + !e.match(/^SyntaxError: .*strict mode.*/i) && // JSON.parse() error !(e.match(/^SyntaxError: Unexpected (token .*|end of input)/) && e.match(/\n at Object.parse \(native\)\n/)); diff --git a/test/simple/test-repl.js b/test/simple/test-repl.js index 793346775..27c2058b0 100644 --- a/test/simple/test-repl.js +++ b/test/simple/test-repl.js @@ -144,6 +144,21 @@ function error_test() { // should throw (GH-4012) { client: client_unix, send: 'new RegExp("foo", "wrong modifier");', expect: /^SyntaxError: Invalid flags supplied to RegExp constructor/ }, + // strict mode syntax errors should be caught (GH-5178) + { client: client_unix, send: '(function() { "use strict"; return 0755; })()', + expect: /^SyntaxError: Octal literals are not allowed in strict mode/ }, + { client: client_unix, send: '(function() { "use strict"; return { p: 1, p: 2 }; })()', + expect: /^SyntaxError: Duplicate data property in object literal not allowed in strict mode/ }, + { client: client_unix, send: '(function(a, a, b) { "use strict"; return a + b + c; })()', + expect: /^SyntaxError: Strict mode function may not have duplicate parameter names/ }, + { client: client_unix, send: '(function() { "use strict"; with (this) {} })()', + expect: /^SyntaxError: Strict mode code may not include a with statement/ }, + { client: client_unix, send: '(function() { "use strict"; var x; delete x; })()', + expect: /^SyntaxError: Delete of an unqualified identifier in strict mode/ }, + { client: client_unix, send: '(function() { "use strict"; eval = 17; })()', + expect: /^SyntaxError: Assignment to eval or arguments is not allowed in strict mode/ }, + { client: client_unix, send: '(function() { "use strict"; if (true){ function f() { } } })()', + expect: /^SyntaxError: In strict mode code, functions can only be declared at top level or immediately within another function/ }, // Named functions can be used: { client: client_unix, send: 'function blah() { return 1; }', expect: prompt_unix }, |