diff --git a/lib/readline.js b/lib/readline.js index 9cdc94e8d1..7e20a08567 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -271,7 +271,7 @@ Interface.prototype._tabComplete = function() { var width = completions.reduce(function(a, b) { return a.length > b.length ? a : b; }).length + 2; // 2 space padding - var maxColumns = Math.floor(this.columns / width) || 1; + var maxColumns = Math.floor(self.columns / width) || 1; function handleGroup(group) { if (group.length == 0) { diff --git a/lib/repl.js b/lib/repl.js index cc9ffcea3a..3948a98418 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -64,10 +64,10 @@ module.paths = require('module')._nodeModulePaths(module.filename); exports.writer = util.inspect; -function REPLServer(prompt, stream, options) { +function REPLServer(prompt, stream) { var self = this; - self.eval = options && options.eval || function(code, context, file, cb) { + self.eval = function(code, context, file, cb) { try { var err, result = vm.runInContext(code, context, file); } catch (e) { @@ -186,15 +186,17 @@ function REPLServer(prompt, stream, options) { // Now as statement without parens. function tryExpr(ret) { - self.eval(self.bufferedCommand, self.context, - 'repl', function(e, ret) { - if (ret !== undefined) { - self.context._ = ret; - self.outputStream.write(exports.writer(ret) + '\n'); - } + self.bufferedCommand = ''; + + if (ret !== undefined) { + self.context._ = ret; + self.outputStream.write(exports.writer(ret) + '\n'); + return finish(null); + } - self.bufferedCommand = ''; + self.eval(self.bufferedCommand, self.context, + 'repl', function(e, ret) { if (e) { // instanceof doesn't work across context switches. @@ -467,13 +469,16 @@ REPLServer.prototype.complete = function(line, callback) { filter = expr + '.' + filter; } } + + finish(); }); + return; } } } // If reach this point - work like sync - finish(null, ret); + finish(null); function finish(err, ret) { if (err) throw err;