fix syntax error handling for 'throw ...', fix return value assertion

This commit is contained in:
Fedor Indutny 2011-09-11 14:05:00 +07:00 committed by Ryan Dahl
parent 55c1546f01
commit df480e0357

View File

@ -163,9 +163,9 @@ function REPLServer(prompt, stream, eval) {
self.context, self.context,
'repl', 'repl',
function(e, ret) { function(e, ret) {
if (e) return finish(e); if (e && !isSyntaxError(e)) return finish(e);
if (ret === 'function' || e) { if (typeof ret === 'function' || e) {
// Now as statement without parens. // Now as statement without parens.
self.eval(self.bufferedCommand, self.context, 'repl', finish); self.eval(self.bufferedCommand, self.context, 'repl', finish);
} else { } else {
@ -177,14 +177,18 @@ function REPLServer(prompt, stream, eval) {
finish(null); finish(null);
} }
function finish(e, ret) { function isSyntaxError(e) {
// Convert error to string // Convert error to string
e = e && (e.stack || e.toString()); e = e && (e.stack || e.toString());
return e && e.match(/^SyntaxError/) &&
!(e.match(/^SyntaxError: Unexpected token .*\n/) &&
e.match(/\n at Object.parse \(native\)\n/));
}
function finish(e, ret) {
// If error was SyntaxError and not JSON.parse error // If error was SyntaxError and not JSON.parse error
if (e && e.match(/^SyntaxError/) && if (isSyntaxError(e)) {
!(e.match(/^SyntaxError: Unexpected token .*\n/) &&
e.match(/\n at Object.parse \(native\)\n/))) {
// Start buffering data like that: // Start buffering data like that:
// { // {
// ... x: 1 // ... x: 1
@ -192,7 +196,7 @@ function REPLServer(prompt, stream, eval) {
self.displayPrompt(); self.displayPrompt();
return; return;
} else if (e) { } else if (e) {
self.outputStream.write(e + '\n'); self.outputStream.write((e.stack || e) + '\n');
} }
// Clear buffer if no SyntaxErrors // Clear buffer if no SyntaxErrors