Skip to content
This repository was archived by the owner on Feb 1, 2022. It is now read-only.

Commit 0f8cd13

Browse files
author
Jan Krems
committed
feat: clearBreakpoint
1 parent 7f48c95 commit 0f8cd13

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

lib/internal/inspect-repl.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const SHORTCUTS = {
3434
out: 'o',
3535
backtrace: 'bt',
3636
setBreakpoint: 'sb',
37-
// clearBreakpoint: 'cb',
37+
clearBreakpoint: 'cb',
3838
// pause_: 'pause',
3939
// run: 'r',
4040
};
@@ -488,6 +488,24 @@ function createRepl(inspector) {
488488
});
489489
}
490490

491+
function clearBreakpoint(url, line) {
492+
const breakpoint = knownBreakpoints.find(({ location }) => {
493+
if (!location) return false;
494+
const script = knownScripts[location.scriptId];
495+
if (!script) return false;
496+
return script.url.indexOf(url) !== -1 && (location.lineNumber + 1) === line;
497+
});
498+
if (!breakpoint) {
499+
print(`Could not find breakpoint at ${url}:${line}`);
500+
return Promise.resolve();
501+
}
502+
return Debugger.removeBreakpoint({ breakpointId: breakpoint.breakpointId })
503+
.then(() => {
504+
const idx = knownBreakpoints.indexOf(breakpoint);
505+
knownBreakpoints.splice(idx, 1);
506+
});
507+
}
508+
491509
Debugger.on('paused', ({ callFrames, reason /* , hitBreakpoints */ }) => {
492510
// Save execution context's data
493511
currentBacktrace = Backtrace.from(callFrames);
@@ -567,6 +585,7 @@ function createRepl(inspector) {
567585

568586
scripts: listScripts,
569587
setBreakpoint,
588+
clearBreakpoint,
570589
list,
571590
});
572591
aliasProperties(context, SHORTCUTS);

test/cli/break.test.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,42 @@ test('sb before loading file', (t) => {
116116
.then(() => cli.quit())
117117
.then(null, onFatal);
118118
});
119+
120+
test('clearBreakpoint', (t) => {
121+
const cli = startCLI(['examples/break.js']);
122+
123+
function onFatal(error) {
124+
cli.quit();
125+
throw error;
126+
}
127+
128+
return cli.waitFor(/break/)
129+
.then(() => cli.waitForPrompt())
130+
.then(() => cli.command('sb("break.js", 3)'))
131+
.then(() => cli.command('sb("break.js", 9)'))
132+
.then(() => cli.command('breakpoints'))
133+
.then(() => {
134+
t.match(cli.output, '#0 examples/break.js:3');
135+
t.match(cli.output, '#1 examples/break.js:9');
136+
})
137+
.then(() => cli.command('clearBreakpoint("break.js", 4)'))
138+
.then(() => {
139+
t.match(cli.output, 'Could not find breakpoint');
140+
})
141+
.then(() => cli.command('clearBreakpoint("not-such-script.js", 3)'))
142+
.then(() => {
143+
t.match(cli.output, 'Could not find breakpoint');
144+
})
145+
.then(() => cli.command('clearBreakpoint("break.js", 3)'))
146+
.then(() => cli.command('breakpoints'))
147+
.then(() => {
148+
t.match(cli.output, '#0 examples/break.js:9');
149+
})
150+
.then(() => cli.stepCommand('cont'))
151+
.then(() => {
152+
t.match(cli.output, 'break in examples/break.js:9',
153+
'hits the 2nd breakpoint because the 1st was cleared');
154+
})
155+
.then(() => cli.quit())
156+
.then(null, onFatal);
157+
});

0 commit comments

Comments
 (0)