From 7953c79b83c81a6ee469084d275e80c5eea18b25 Mon Sep 17 00:00:00 2001 From: "eungyu.lee" Date: Fri, 24 Feb 2023 18:50:15 +0900 Subject: [PATCH] repl: Add a command to set which lines to check for context --- lib/internal/debugger/inspect_repl.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/internal/debugger/inspect_repl.js b/lib/internal/debugger/inspect_repl.js index a1b3f0d705ec4c..cfb2068ca48ec8 100644 --- a/lib/internal/debugger/inspect_repl.js +++ b/lib/internal/debugger/inspect_repl.js @@ -64,6 +64,7 @@ const SHORTCUTS = { step: 's', out: 'o', backtrace: 'bt', + setContextLineNumber: 'scln', setBreakpoint: 'sb', clearBreakpoint: 'cb', run: 'r', @@ -81,7 +82,8 @@ 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, scln + Set which lines to check for context setBreakpoint, sb Set a breakpoint clearBreakpoint, cb Clear a breakpoint breakpoints List all known breakpoints @@ -381,6 +383,7 @@ function createRepl(inspector) { let currentBacktrace; let selectedFrame; let exitDebugRepl; + let contextLineNumber = 2; function resetOnStart() { knownScripts = {}; @@ -685,6 +688,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 +913,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 +1175,7 @@ function createRepl(inspector) { }, list, + setContextLineNumber }); aliasProperties(context, SHORTCUTS); }