Browse Source

repl: make "end of input" JSON.parse() errors throw in the REPL

v0.8.12-release
Nathan Rajlich 12 years ago
parent
commit
3b7312d23a
  1. 2
      lib/repl.js
  2. 4
      test/simple/test-repl.js

2
lib/repl.js

@ -275,7 +275,7 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
!e.match(/^SyntaxError: Invalid regular expression/) &&
!e.match(/^SyntaxError: Invalid flags supplied to RegExp constructor/) &&
// JSON.parse() error
!(e.match(/^SyntaxError: Unexpected token .*\n/) &&
!(e.match(/^SyntaxError: Unexpected (token .*|end of input)/) &&
e.match(/\n at Object.parse \(native\)\n/));
}

4
test/simple/test-repl.js

@ -126,6 +126,10 @@ function error_test() {
// should throw
{ client: client_unix, send: 'JSON.parse(\'{invalid: \\\'json\\\'}\');',
expect: /^SyntaxError: Unexpected token i/ },
// end of input to JSON.parse error is special case of syntax error,
// should throw
{ client: client_unix, send: 'JSON.parse(\'{\');',
expect: /^SyntaxError: Unexpected end of input/ },
// invalid RegExps are a special case of syntax error,
// should throw
{ client: client_unix, send: '/(/;',

Loading…
Cancel
Save