diff options
author | Rich Trott <rtrott@gmail.com> | 2016-04-05 17:17:33 -0700 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2016-04-14 10:53:07 -0700 |
commit | 1df84f4f75843ad01d95dc55d63ba30b2b69fbd4 (patch) | |
tree | 0334d5a568202fca7c60ebfdcbf2a6ea001ef86d /lib | |
parent | b68827b1d1c20d0f3e0592734e845b87967a72bc (diff) | |
download | android-node-v8-1df84f4f75843ad01d95dc55d63ba30b2b69fbd4.tar.gz android-node-v8-1df84f4f75843ad01d95dc55d63ba30b2b69fbd4.tar.bz2 android-node-v8-1df84f4f75843ad01d95dc55d63ba30b2b69fbd4.zip |
debugger: run last command on presssing enter
PR-URL: https://github.com/nodejs/node/pull/6090
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Claudio Rodriguez <cjrodr@yahoo.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Fixes: https://github.com/nodejs/node/issues/2895
Diffstat (limited to 'lib')
-rw-r--r-- | lib/_debugger.js | 11 | ||||
-rw-r--r-- | lib/repl.js | 38 |
2 files changed, 26 insertions, 23 deletions
diff --git a/lib/_debugger.js b/lib/_debugger.js index e7e24d32a1..7b3abec27d 100644 --- a/lib/_debugger.js +++ b/lib/_debugger.js @@ -674,6 +674,9 @@ var helpMessage = 'Commands: ' + commands.map(function(group) { return group.join(', '); }).join(',\n'); +// Previous command received. Initialize to empty command. +var lastCommand = '\n'; + function SourceUnderline(sourceText, position, repl) { if (!sourceText) return ''; @@ -945,10 +948,10 @@ Interface.prototype.requireConnection = function() { Interface.prototype.controlEval = function(code, context, filename, callback) { try { // Repeat last command if empty line are going to be evaluated - if (this.repl.rli.history && this.repl.rli.history.length > 0) { - if (code === '\n') { - code = this.repl.rli.history[0] + '\n'; - } + if (code === '\n') { + code = lastCommand; + } else { + lastCommand = code; } // exec process.title => exec("process.title"); diff --git a/lib/repl.js b/lib/repl.js index 3a96eea136..82555497eb 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -224,6 +224,10 @@ function REPLServer(prompt, function defaultEval(code, context, file, cb) { var err, result, retry = false, input = code, wrappedErr; // first, create the Script object to check the syntax + + if (code === '\n') + return cb(null); + while (true) { try { if (!/^\s*$/.test(code) && @@ -421,28 +425,24 @@ function REPLServer(prompt, } } - if (cmd || self.bufferedCommand) { - var evalCmd = self.bufferedCommand + cmd; - if (/^\s*\{/.test(evalCmd) && /\}\s*$/.test(evalCmd)) { - // It's confusing for `{ a : 1 }` to be interpreted as a block - // statement rather than an object literal. So, we first try - // to wrap it in parentheses, so that it will be interpreted as - // an expression. - evalCmd = '(' + evalCmd + ')\n'; - self.wrappedCmd = true; - } else { - // otherwise we just append a \n so that it will be either - // terminated, or continued onto the next expression if it's an - // unexpected end of input. - evalCmd = evalCmd + '\n'; - } - - debug('eval %j', evalCmd); - self.eval(evalCmd, self.context, 'repl', finish); + var evalCmd = self.bufferedCommand + cmd; + if (/^\s*\{/.test(evalCmd) && /\}\s*$/.test(evalCmd)) { + // It's confusing for `{ a : 1 }` to be interpreted as a block + // statement rather than an object literal. So, we first try + // to wrap it in parentheses, so that it will be interpreted as + // an expression. + evalCmd = '(' + evalCmd + ')\n'; + self.wrappedCmd = true; } else { - finish(null); + // otherwise we just append a \n so that it will be either + // terminated, or continued onto the next expression if it's an + // unexpected end of input. + evalCmd = evalCmd + '\n'; } + debug('eval %j', evalCmd); + self.eval(evalCmd, self.context, 'repl', finish); + function finish(e, ret) { debug('finish', e, ret); self.memory(cmd); |