Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions lib/internal/debugger/inspect_repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const {
Promise,
PromisePrototypeThen,
PromiseResolve,
PromiseWithResolvers,
ReflectGetOwnPropertyDescriptor,
ReflectOwnKeys,
RegExpPrototypeExec,
Expand Down Expand Up @@ -380,6 +381,8 @@ function createRepl(inspector) {
let selectedFrame;
let exitDebugRepl;
let contextLineNumber = 2;
let initialBreakRender;
let waitForInitialBreakRender = false;

function resetOnStart() {
knownScripts = {};
Expand Down Expand Up @@ -890,6 +893,13 @@ function createRepl(inspector) {
});
}

function createInitialBreakRenderPromise(pauseRender) {
const { promise, resolve, reject } = PromiseWithResolvers();
initialBreakRender = promise;
PromisePrototypeThen(pauseRender, resolve, reject);
return promise;
}

Debugger.on('paused', ({ callFrames, reason /* , hitBreakpoints */ }) => {
if (process.env.NODE_INSPECT_RESUME_ON_START === '1' &&
reason === 'Break on start') {
Expand All @@ -910,7 +920,7 @@ function createRepl(inspector) {

const header = `${breakType} in ${scriptUrl}:${lineNumber + 1}`;

inspector.suspendReplWhile(() =>
const pauseRender = inspector.suspendReplWhile(() =>
PromisePrototypeThen(
SafePromiseAllReturnArrayLike([formatWatchers(true), selectedFrame.list(contextLineNumber)]),
({ 0: watcherList, 1: context }) => {
Expand All @@ -919,6 +929,10 @@ function createRepl(inspector) {
inspect(context);
print(`${header}\n${breakContext}`);
}));

if (waitForInitialBreakRender && !initialBreakRender) {
createInitialBreakRenderPromise(pauseRender);
}
});

function handleResumed() {
Expand Down Expand Up @@ -1186,6 +1200,9 @@ function createRepl(inspector) {
}

async function initAfterStart() {
waitForInitialBreakRender =
!!inspector.options?.script &&
process.env.NODE_INSPECT_RESUME_ON_START !== '1';
await Runtime.enable();
await Profiler.enable();
await Profiler.setSamplingInterval({ interval: 100 });
Expand All @@ -1194,7 +1211,12 @@ function createRepl(inspector) {
await Debugger.setBlackboxPatterns({ patterns: [] });
await Debugger.setPauseOnExceptions({ state: pauseOnExceptionState });
await restoreBreakpoints();
return Runtime.runIfWaitingForDebugger();
await Runtime.runIfWaitingForDebugger();
await PromiseResolve();
waitForInitialBreakRender = false;
const initialBreakRenderPromise = initialBreakRender;
initialBreakRender = null;
await initialBreakRenderPromise;
}

return async function startRepl() {
Expand Down
Loading