diff --git a/lib/_debugger.js b/lib/_debugger.js index d3936def82..802e2da1e6 100644 --- a/lib/_debugger.js +++ b/lib/_debugger.js @@ -174,7 +174,11 @@ Client.prototype.reqEval = function(expression, cb) { arguments: { expression: expression } }; - if (this.currentFrame == NO_FRAME) req.arguments.global = true; + if (this.currentFrame == NO_FRAME) { + req.arguments.global = true; + } else { + req.arguments.frame = this.currentFrame; + } this.req(req, function (res) { if (cb) cb(res.body); @@ -215,13 +219,27 @@ Client.prototype.reqScripts = function(cb) { Client.prototype.reqContinue = function(cb) { - this.req({ command: 'continue' } , function (res) { + this.req({ command: 'continue' }, function (res) { + if (cb) cb(res); + }); +}; + +// c.next(1, cb); +Client.prototype.step = function(action, count, cb) { + var req = { + command: 'continue', + arguments: { stepaction: action, stepcount: count } + }; + + this.req(req, function (res) { if (cb) cb(res); }); }; -var helpMessage = "Commands: scripts, backtrace, version, eval, help, quit"; + + +var helpMessage = "Commands: print, step, next, continue, scripts, backtrace, version, quit"; function SourceUnderline(source_text, position) { if (!source_text) { @@ -303,7 +321,7 @@ function startInterface() { }); term.on('line', function(cmd) { - if (cmd == 'quit') { + if (cmd == 'quit' || cmd == 'q' || cmd == 'exit') { tryQuit(); } else if (/^help/.test(cmd)) { console.log(helpMessage); @@ -322,9 +340,7 @@ function startInterface() { } else if (bt.totalFrames == 0) { console.log('(empty stack)'); } else { - var result = 'Frames #' + bt.fromFrame + - ' to #' + (bt.toFrame - 1) + - ' of ' + bt.totalFrames + '\n'; + var result = ''; for (j = 0; j < bt.frames.length; j++) { if (j != 0) result += '\n'; result += bt.frames[j].text; @@ -336,7 +352,17 @@ function startInterface() { } else if (/^continue/.test(cmd) || /^c/.test(cmd)) { c.reqContinue(function (res) { - // Wait for break point. (disable raw mode?) + // Wait for break point. (disable raw mode?) + }); + + } else if (/^next/.test(cmd) || /^n/.test(cmd)) { + c.step('next', 1, function (res) { + // Wait for break point. (disable raw mode?) + }); + + } else if (/^step/.test(cmd) || /^s/.test(cmd)) { + c.step('in', 1, function (res) { + // Wait for break point. (disable raw mode?) }); } else if (/^scripts/.test(cmd)) { @@ -350,11 +376,22 @@ function startInterface() { term.prompt(); }); - } else if (/^eval/.test(cmd)) { - c.reqEval(cmd.slice(5), function (res) { - console.log(res); + } else if (/^print/.test(cmd) || /^p/.test(cmd)) { + var i = cmd.indexOf(' '); + if (i < 0) { + console.log("print [expression]"); term.prompt(); - }); + } else { + cmd = cmd.slice(i); + c.reqEval(cmd, function (res) { + if (res) { + console.log(res.text); + } else { + console.log(res); + } + term.prompt(); + }); + } } else { if (!/^\s*$/.test(cmd)) {