|
|
@ -171,36 +171,26 @@ function REPLServer(prompt, stream) { |
|
|
|
e.constructor.name === 'SyntaxError')) { |
|
|
|
finish(e); |
|
|
|
} else { |
|
|
|
tryExpr(); |
|
|
|
tryExpr(e); |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (typeof ret !== 'function') { |
|
|
|
return tryExpr(ret); |
|
|
|
} |
|
|
|
|
|
|
|
tryExpr(); |
|
|
|
tryExpr(typeof ret === 'function', ret); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
// Now as statement without parens.
|
|
|
|
function tryExpr(ret) { |
|
|
|
|
|
|
|
self.bufferedCommand = ''; |
|
|
|
|
|
|
|
if (ret !== undefined) { |
|
|
|
self.context._ = ret; |
|
|
|
self.outputStream.write(exports.writer(ret) + '\n'); |
|
|
|
return finish(null); |
|
|
|
} |
|
|
|
function tryExpr(e, ret) { |
|
|
|
if (!e) return finish(null, ret); |
|
|
|
|
|
|
|
self.eval(self.bufferedCommand, self.context, |
|
|
|
'repl', function(e, ret) { |
|
|
|
|
|
|
|
if (e) { |
|
|
|
// instanceof doesn't work across context switches.
|
|
|
|
if (!(e && e.constructor && e.constructor.name === 'SyntaxError')) { |
|
|
|
if (!(e && e.constructor && |
|
|
|
e.constructor.name === 'SyntaxError')) { |
|
|
|
return finish(e); |
|
|
|
// It could also be an error from JSON.parse
|
|
|
|
} else if (e && |
|
|
@ -208,6 +198,9 @@ function REPLServer(prompt, stream) { |
|
|
|
e.stack.match(/^SyntaxError: Unexpected token .*\n/) && |
|
|
|
e.stack.match(/\n at Object.parse \(native\)\n/)) { |
|
|
|
return finish(e); |
|
|
|
} else { |
|
|
|
finish(true); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
finish(null, ret); |
|
|
@ -222,12 +215,23 @@ function REPLServer(prompt, stream) { |
|
|
|
if (e) { |
|
|
|
if (e.stack) { |
|
|
|
self.outputStream.write(e.stack + '\n'); |
|
|
|
} else if (e === true) { |
|
|
|
self.displayPrompt(); |
|
|
|
return; |
|
|
|
} else { |
|
|
|
self.outputStream.write(e.toString() + '\n'); |
|
|
|
} |
|
|
|
// On error: Print the error and clear the buffer
|
|
|
|
self.bufferedCommand = ''; |
|
|
|
} else { |
|
|
|
self.bufferedCommand = ''; |
|
|
|
} |
|
|
|
|
|
|
|
if (ret !== undefined) { |
|
|
|
self.context._ = ret; |
|
|
|
self.outputStream.write(exports.writer(ret) + '\n'); |
|
|
|
} |
|
|
|
|
|
|
|
self.displayPrompt(); |
|
|
|
}; |
|
|
|
}); |
|
|
@ -413,7 +417,27 @@ REPLServer.prototype.complete = function(line, callback) { |
|
|
|
// Resolve expr and get its completions.
|
|
|
|
var obj, memberGroups = []; |
|
|
|
if (!expr) { |
|
|
|
if (this.context.constructor.name === 'Context') { |
|
|
|
completionGroups.push(Object.getOwnPropertyNames(this.context)); |
|
|
|
next(); |
|
|
|
} else { |
|
|
|
this.eval('.scope', this.context, 'repl', function(err, globals) { |
|
|
|
if (Array.isArray(globals[0])) { |
|
|
|
// Add grouped globals
|
|
|
|
globals.forEach(function(group) { |
|
|
|
completionGroups.push(group); |
|
|
|
}); |
|
|
|
finish(); |
|
|
|
} else { |
|
|
|
completionGroups.push(globals); |
|
|
|
next(); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
function next() { |
|
|
|
// Global object properties
|
|
|
|
// (http://www.ecma-international.org/publications/standards/Ecma-262.htm)
|
|
|
|
completionGroups.push(['NaN', 'Infinity', 'undefined', |
|
|
@ -433,6 +457,9 @@ REPLServer.prototype.complete = function(line, callback) { |
|
|
|
'throw', 'true', 'try', 'typeof', 'undefined', 'var', 'void', |
|
|
|
'while', 'with', 'yield']); |
|
|
|
} |
|
|
|
|
|
|
|
finish(); |
|
|
|
} |
|
|
|
} else { |
|
|
|
this.eval(expr, this.context, 'repl', function(e, obj) { |
|
|
|
// if (e) console.log(e);
|
|
|
|