Skip to content

Commit 42f4c14

Browse files
committed
debugger: add a command to set which lines to check for context
1 parent 86362b7 commit 42f4c14

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

lib/internal/debugger/inspect_repl.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ out, o Step out, leaving the current function
8181
backtrace, bt Print the current backtrace
8282
list Print the source around the current line where execution
8383
is currently paused
84-
84+
setContextLineNumber Set which lines to check for context
8585
setBreakpoint, sb Set a breakpoint
8686
clearBreakpoint, cb Clear a breakpoint
8787
breakpoints List all known breakpoints
@@ -381,6 +381,7 @@ function createRepl(inspector) {
381381
let currentBacktrace;
382382
let selectedFrame;
383383
let exitDebugRepl;
384+
let contextLineNumber = 2;
384385

385386
function resetOnStart() {
386387
knownScripts = {};
@@ -685,6 +686,19 @@ function createRepl(inspector) {
685686
});
686687
}
687688

689+
function setContextLineNumber(delta = 2) {
690+
if (!selectedFrame) {
691+
throw new ERR_DEBUGGER_ERROR('Requires execution to be paused');
692+
}
693+
try {
694+
contextLineNumber = delta;
695+
print(`The contextLine has been changed to ${delta}.`);
696+
} catch (error) {
697+
print("You can't setContextLineNumber source code right now");
698+
throw error;
699+
}
700+
}
701+
688702
function handleBreakpointResolved({ breakpointId, location }) {
689703
const script = knownScripts[location.scriptId];
690704
const scriptUrl = script && script.url;
@@ -897,7 +911,7 @@ function createRepl(inspector) {
897911

898912
inspector.suspendReplWhile(() =>
899913
PromisePrototypeThen(
900-
SafePromiseAllReturnArrayLike([formatWatchers(true), selectedFrame.list(2)]),
914+
SafePromiseAllReturnArrayLike([formatWatchers(true), selectedFrame.list(contextLineNumber)]),
901915
({ 0: watcherList, 1: context }) => {
902916
const breakContext = watcherList ?
903917
`${watcherList}\n${inspect(context)}` :
@@ -1159,6 +1173,7 @@ function createRepl(inspector) {
11591173
},
11601174

11611175
list,
1176+
setContextLineNumber,
11621177
});
11631178
aliasProperties(context, SHORTCUTS);
11641179
}

0 commit comments

Comments
 (0)