Skip to content

Commit c4a308d

Browse files
julianduquebnoordhuis
authored andcommitted
debugger: improve clearBreakpoint error and docs
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: #175 Reviewed-By: Miroslav Bajtoš <[email protected]>
1 parent 5678595 commit c4a308d

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

doc/api/debugger.markdown

+2-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ prints the active watchers. To remove a watcher, type
107107
functions body
108108
* `setBreakpoint('script.js', 1)`, `sb(...)` - Set breakpoint on first line of
109109
script.js
110-
* `clearBreakpoint`, `cb(...)` - Clear breakpoint
110+
* `clearBreakpoint('script.js', 1)`, `cb(...)` - Clear breakpoint in script.js
111+
on line 1
111112

112113
It is also possible to set a breakpoint in a file (module) that
113114
isn't loaded yet:

lib/_debugger.js

+22-4
Original file line numberDiff line numberDiff line change
@@ -1375,9 +1375,7 @@ Interface.prototype.setBreakpoint = function(script, line,
13751375
// setBreakpoint('scriptname')
13761376
if (script != +script && !this.client.scripts[script]) {
13771377
var scripts = this.client.scripts;
1378-
var keys = Object.keys(scripts);
1379-
for (var v = 0; v < keys.length; v++) {
1380-
var id = keys[v];
1378+
for (var id in scripts) {
13811379
if (scripts[id] &&
13821380
scripts[id].name &&
13831381
scripts[id].name.indexOf(script) !== -1) {
@@ -1452,6 +1450,7 @@ Interface.prototype.clearBreakpoint = function(script, line) {
14521450

14531451
var ambiguous,
14541452
breakpoint,
1453+
scriptId,
14551454
index;
14561455

14571456
this.client.breakpoints.some(function(bp, i) {
@@ -1461,6 +1460,7 @@ Interface.prototype.clearBreakpoint = function(script, line) {
14611460
if (!util.isUndefined(index)) {
14621461
ambiguous = true;
14631462
}
1463+
scriptId = script;
14641464
if (bp.line === line) {
14651465
index = i;
14661466
breakpoint = bp.id;
@@ -1469,10 +1469,28 @@ Interface.prototype.clearBreakpoint = function(script, line) {
14691469
}
14701470
});
14711471

1472+
if (!scriptId && !this.client.scripts[script]) {
1473+
var scripts = this.client.scripts;
1474+
for (var id in scripts) {
1475+
if (scripts[id] &&
1476+
scripts[id].name &&
1477+
scripts[id].name.indexOf(script) !== -1) {
1478+
if (scriptId) {
1479+
ambiguous = true;
1480+
}
1481+
scriptId = id;
1482+
}
1483+
}
1484+
}
1485+
14721486
if (ambiguous) return this.error('Script name is ambiguous');
14731487

1488+
if (util.isUndefined(scriptId)) {
1489+
return this.error('Script ' + script + ' not found');
1490+
}
1491+
14741492
if (util.isUndefined(breakpoint)) {
1475-
return this.error('Script : ' + script + ' not found');
1493+
return this.error('Breakpoint not found on line ' + line);
14761494
}
14771495

14781496
var self = this,

0 commit comments

Comments
 (0)