debugger: improve clearBreakpoint error and docs
authorJulian Duque <julianduquej@gmail.com>
Tue, 16 Dec 2014 16:27:31 +0000 (11:27 -0500)
committerBen Noordhuis <info@bnoordhuis.nl>
Fri, 19 Dec 2014 17:52:38 +0000 (18:52 +0100)
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š <miroslav@strongloop.com>
doc/api/debugger.markdown
lib/_debugger.js

index b4863a8..daa582b 100644 (file)
@@ -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:
index 2e708db..3886d35 100644 (file)
@@ -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,