diff --git a/lib/internal/debugger/inspect_repl.js b/lib/internal/debugger/inspect_repl.js index a1b3f0d705ec4c..effa45f88fd597 100644 --- a/lib/internal/debugger/inspect_repl.js +++ b/lib/internal/debugger/inspect_repl.js @@ -81,7 +81,7 @@ out, o Step out, leaving the current function backtrace, bt Print the current backtrace list Print the source around the current line where execution is currently paused - +setContextLineNumber Set which lines to check for context setBreakpoint, sb Set a breakpoint clearBreakpoint, cb Clear a breakpoint breakpoints List all known breakpoints @@ -381,6 +381,7 @@ function createRepl(inspector) { let currentBacktrace; let selectedFrame; let exitDebugRepl; + let contextLineNumber = 2; function resetOnStart() { knownScripts = {}; @@ -685,6 +686,19 @@ function createRepl(inspector) { }); } + function setContextLineNumber(delta = 2) { + if (!selectedFrame) { + throw new ERR_DEBUGGER_ERROR('Requires execution to be paused'); + } + try { + contextLineNumber = delta; + print(`The contextLine has been changed to ${delta}.`) + } catch (error) { + print("You can't setContextLineNumber source code right now"); + throw error; + } + } + function handleBreakpointResolved({ breakpointId, location }) { const script = knownScripts[location.scriptId]; const scriptUrl = script && script.url; @@ -897,7 +911,7 @@ function createRepl(inspector) { inspector.suspendReplWhile(() => PromisePrototypeThen( - SafePromiseAllReturnArrayLike([formatWatchers(true), selectedFrame.list(2)]), + SafePromiseAllReturnArrayLike([formatWatchers(true), selectedFrame.list(contextLineNumber)]), ({ 0: watcherList, 1: context }) => { const breakContext = watcherList ? `${watcherList}\n${inspect(context)}` : @@ -1159,6 +1173,7 @@ function createRepl(inspector) { }, list, + setContextLineNumber }); aliasProperties(context, SHORTCUTS); }