From c4a308d223e2796b6af77213abb8f3dd5e31e67f Mon Sep 17 00:00:00 2001 From: Julian Duque Date: Tue, 16 Dec 2014 11:27:31 -0500 Subject: [PATCH] debugger: improve clearBreakpoint error and docs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently clearBreakpoint error is confusing, it says "Script not found" when there is no breakpoint, also documentation doesn't include signature for clearBreakpoint. PR-URL: https://github.com/iojs/io.js/pull/175 Reviewed-By: Miroslav Bajtoš --- doc/api/debugger.markdown | 3 ++- lib/_debugger.js | 26 ++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/doc/api/debugger.markdown b/doc/api/debugger.markdown index b4863a81a2..daa582bc20 100644 --- a/doc/api/debugger.markdown +++ b/doc/api/debugger.markdown @@ -107,7 +107,8 @@ prints the active watchers. To remove a watcher, type functions body * `setBreakpoint('script.js', 1)`, `sb(...)` - Set breakpoint on first line of script.js -* `clearBreakpoint`, `cb(...)` - Clear breakpoint +* `clearBreakpoint('script.js', 1)`, `cb(...)` - Clear breakpoint in script.js +on line 1 It is also possible to set a breakpoint in a file (module) that isn't loaded yet: diff --git a/lib/_debugger.js b/lib/_debugger.js index 2e708db76d..3886d3530e 100644 --- a/lib/_debugger.js +++ b/lib/_debugger.js @@ -1375,9 +1375,7 @@ Interface.prototype.setBreakpoint = function(script, line, // setBreakpoint('scriptname') if (script != +script && !this.client.scripts[script]) { var scripts = this.client.scripts; - var keys = Object.keys(scripts); - for (var v = 0; v < keys.length; v++) { - var id = keys[v]; + for (var id in scripts) { if (scripts[id] && scripts[id].name && scripts[id].name.indexOf(script) !== -1) { @@ -1452,6 +1450,7 @@ Interface.prototype.clearBreakpoint = function(script, line) { var ambiguous, breakpoint, + scriptId, index; this.client.breakpoints.some(function(bp, i) { @@ -1461,6 +1460,7 @@ Interface.prototype.clearBreakpoint = function(script, line) { if (!util.isUndefined(index)) { ambiguous = true; } + scriptId = script; if (bp.line === line) { index = i; breakpoint = bp.id; @@ -1469,10 +1469,28 @@ Interface.prototype.clearBreakpoint = function(script, line) { } }); + if (!scriptId && !this.client.scripts[script]) { + var scripts = this.client.scripts; + for (var id in scripts) { + if (scripts[id] && + scripts[id].name && + scripts[id].name.indexOf(script) !== -1) { + if (scriptId) { + ambiguous = true; + } + scriptId = id; + } + } + } + if (ambiguous) return this.error('Script name is ambiguous'); + if (util.isUndefined(scriptId)) { + return this.error('Script ' + script + ' not found'); + } + if (util.isUndefined(breakpoint)) { - return this.error('Script : ' + script + ' not found'); + return this.error('Breakpoint not found on line ' + line); } var self = this,