Skip to content

Commit 7953c79

Browse files
committed
repl: Add a command to set which lines to check for context
1 parent 86362b7 commit 7953c79

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

lib/internal/debugger/inspect_repl.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const SHORTCUTS = {
6464
step: 's',
6565
out: 'o',
6666
backtrace: 'bt',
67+
setContextLineNumber: 'scln',
6768
setBreakpoint: 'sb',
6869
clearBreakpoint: 'cb',
6970
run: 'r',
@@ -81,7 +82,8 @@ out, o Step out, leaving the current function
8182
backtrace, bt Print the current backtrace
8283
list Print the source around the current line where execution
8384
is currently paused
84-
85+
setContextLineNumber, scln
86+
Set which lines to check for context
8587
setBreakpoint, sb Set a breakpoint
8688
clearBreakpoint, cb Clear a breakpoint
8789
breakpoints List all known breakpoints
@@ -381,6 +383,7 @@ function createRepl(inspector) {
381383
let currentBacktrace;
382384
let selectedFrame;
383385
let exitDebugRepl;
386+
let contextLineNumber = 2;
384387

385388
function resetOnStart() {
386389
knownScripts = {};
@@ -685,6 +688,19 @@ function createRepl(inspector) {
685688
});
686689
}
687690

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

898914
inspector.suspendReplWhile(() =>
899915
PromisePrototypeThen(
900-
SafePromiseAllReturnArrayLike([formatWatchers(true), selectedFrame.list(2)]),
916+
SafePromiseAllReturnArrayLike([formatWatchers(true), selectedFrame.list(contextLineNumber)]),
901917
({ 0: watcherList, 1: context }) => {
902918
const breakContext = watcherList ?
903919
`${watcherList}\n${inspect(context)}` :
@@ -1159,6 +1175,7 @@ function createRepl(inspector) {
11591175
},
11601176

11611177
list,
1178+
setContextLineNumber
11621179
});
11631180
aliasProperties(context, SHORTCUTS);
11641181
}

0 commit comments

Comments
 (0)