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

Commit bc82ecc

Browse files
author
Jan Krems
committed
feat: breakpoints to list breakpoints
1 parent 1c60f91 commit bc82ecc

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/internal/inspect-repl.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,18 @@ function createRepl(inspector) {
255255
}
256256
}
257257

258+
function listBreakpoints() {
259+
function formatLocation(location) {
260+
if (!location) return '<unknown location>';
261+
const script = knownScripts[location.scriptId];
262+
const scriptUrl = script ? script.url : location.scriptUrl;
263+
return `${getRelativePath(scriptUrl)}:${location.lineNumber + 1}`;
264+
}
265+
knownBreakpoints.forEach((bp, idx) => {
266+
print(`#${idx} ${formatLocation(bp.location)}`);
267+
});
268+
}
269+
258270
function setBreakpoint(script, line, condition, silent) {
259271
function registerBreakpoint({ breakpointId, actualLocation }) {
260272
handleBreakpointResolved({ breakpointId, location: actualLocation });
@@ -398,6 +410,10 @@ function createRepl(inspector) {
398410
return currentBacktrace;
399411
},
400412

413+
get breakpoints() {
414+
return listBreakpoints();
415+
},
416+
401417
scripts: listScripts,
402418
setBreakpoint,
403419
list,

test/cli/break.test.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ test('stepping through breakpoints', (t) => {
4848
// Prepare additional breakpoints
4949
.then(() => cli.command('sb("break.js", 6)'))
5050
.then(() => cli.command('sb("otherFunction()")'))
51+
.then(() => cli.command('sb(16)'))
52+
.then(() => cli.command('breakpoints'))
53+
.then(() => {
54+
t.match(cli.output, '#0 examples/break.js:6');
55+
t.match(cli.output, '#1 examples/break.js:16');
56+
})
5157

5258
.then(() => cli.command('list()'))
5359
.then(() => {
@@ -69,9 +75,14 @@ test('stepping through breakpoints', (t) => {
6975
'entered timers.js');
7076
})
7177
.then(() => cli.stepCommand('cont'))
78+
.then(() => {
79+
t.match(cli.output, 'break in examples/break.js:16',
80+
'found breakpoint we set above w/ line number only');
81+
})
82+
.then(() => cli.stepCommand('cont'))
7283
.then(() => {
7384
t.match(cli.output, 'break in examples/break.js:6',
74-
'found breakpoint we set above');
85+
'found breakpoint we set above w/ line number & script');
7586
})
7687
.then(() => cli.stepCommand(''))
7788
.then(() => {

0 commit comments

Comments
 (0)