repl: isSyntaxError() catches "strict mode" errors
authorNathan Rajlich <nathan@tootallnate.net>
Sat, 30 Mar 2013 20:10:30 +0000 (13:10 -0700)
committerNathan Rajlich <nathan@tootallnate.net>
Sat, 30 Mar 2013 20:10:30 +0000 (13:10 -0700)
Closes #5178.

lib/repl.js
test/simple/test-repl.js

index f0c1cb270f8b01ecfa3e1dec6686fff2ee15a93f..522bfd7d5bd4dd4ceec105abbb699b7b0e170b49 100644 (file)
@@ -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/));
index 793346775b48aad48542b1e5c3a8641d86f0b467..27c2058b013fe875b3dd15a6a11cb075708a4d90 100644 (file)
@@ -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 },