Skip to content

Commit 25692a9

Browse files
Eugene Ostroukhovjasnell
Eugene Ostroukhov
authored andcommitted
inspector: break in eval script
Fixes: #14577 PR-URL: #14581 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 66a5f99 commit 25692a9

6 files changed

+53
-11
lines changed

lib/internal/bootstrap_node.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,13 @@
434434
}
435435
}
436436

437+
function wrapForBreakOnFirstLine(source) {
438+
if (!process._breakFirstLine)
439+
return source;
440+
const fn = `function() {\n\n${source};\n\n}`;
441+
return `process.binding('inspector').callAndPauseOnStart(${fn}, {})`;
442+
}
443+
437444
function evalScript(name) {
438445
const Module = NativeModule.require('module');
439446
const path = NativeModule.require('path');
@@ -442,7 +449,7 @@
442449
const module = new Module(name);
443450
module.filename = path.join(cwd, name);
444451
module.paths = Module._nodeModulePaths(cwd);
445-
const body = process._eval;
452+
const body = wrapForBreakOnFirstLine(process._eval);
446453
const script = `global.__filename = ${JSON.stringify(name)};\n` +
447454
'global.exports = exports;\n' +
448455
'global.module = module;\n' +

test/inspector/test-async-hook-setup-at-inspect-brk.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@ setTimeout(() => {
1313
}, 50);
1414
`;
1515

16+
async function skipBreakpointAtStart(session) {
17+
await session.waitForBreakOnLine(0, '[eval]');
18+
await session.send({ 'method': 'Debugger.resume' });
19+
}
20+
1621
async function checkAsyncStackTrace(session) {
1722
console.error('[test]', 'Verify basic properties of asyncStackTrace');
18-
const paused = await session.waitForBreakOnLine(2, '[eval]');
23+
const paused = await session.waitForBreakOnLine(4, '[eval]');
1924
assert(paused.params.asyncStackTrace,
2025
`${Object.keys(paused.params)} contains "asyncStackTrace" property`);
2126
assert(paused.params.asyncStackTrace.description, 'Timeout');
@@ -35,7 +40,7 @@ async function runTests() {
3540
'params': { 'patterns': [] } },
3641
{ 'method': 'Runtime.runIfWaitingForDebugger' }
3742
]);
38-
43+
await skipBreakpointAtStart(session);
3944
await checkAsyncStackTrace(session);
4045

4146
await session.runToCompletion();

test/inspector/test-async-stack-traces-promise-then.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,18 @@ async function runTests() {
3131
{ 'method': 'Runtime.runIfWaitingForDebugger' }
3232
]);
3333

34+
await session.waitForBreakOnLine(0, '[eval]');
35+
await session.send({ 'method': 'Debugger.resume' });
36+
3437
console.error('[test] Waiting for break1');
35-
debuggerPausedAt(await session.waitForBreakOnLine(4, '[eval]'),
36-
'break1', 'runTest:3');
38+
debuggerPausedAt(await session.waitForBreakOnLine(6, '[eval]'),
39+
'break1', 'runTest:5');
3740

3841
await session.send({ 'method': 'Debugger.resume' });
3942

4043
console.error('[test] Waiting for break2');
41-
debuggerPausedAt(await session.waitForBreakOnLine(7, '[eval]'),
42-
'break2', 'runTest:6');
44+
debuggerPausedAt(await session.waitForBreakOnLine(9, '[eval]'),
45+
'break2', 'runTest:8');
4346

4447
await session.runToCompletion();
4548
assert.strictEqual(0, (await instance.expectShutdown()).exitCode);

test/inspector/test-async-stack-traces-set-interval.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@ const assert = require('assert');
88

99
const script = 'setInterval(() => { debugger; }, 50);';
1010

11+
async function skipFirstBreakpoint(session) {
12+
console.log('[test]', 'Skipping the first breakpoint in the eval script');
13+
await session.waitForBreakOnLine(0, '[eval]');
14+
await session.send({ 'method': 'Debugger.resume' });
15+
}
16+
1117
async function checkAsyncStackTrace(session) {
1218
console.error('[test]', 'Verify basic properties of asyncStackTrace');
13-
const paused = await session.waitForBreakOnLine(0, '[eval]');
19+
const paused = await session.waitForBreakOnLine(2, '[eval]');
1420
assert(paused.params.asyncStackTrace,
1521
`${Object.keys(paused.params)} contains "asyncStackTrace" property`);
1622
assert(paused.params.asyncStackTrace.description, 'Timeout');
@@ -31,6 +37,7 @@ async function runTests() {
3137
{ 'method': 'Runtime.runIfWaitingForDebugger' }
3238
]);
3339

40+
await skipFirstBreakpoint(session);
3441
await checkAsyncStackTrace(session);
3542

3643
console.error('[test]', 'Stopping child instance');
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
common.skipIfInspectorDisabled();
5+
6+
const assert = require('assert');
7+
const { NodeInstance } = require('./inspector-helper.js');
8+
9+
async function runTests() {
10+
const instance = new NodeInstance(undefined, 'console.log(10)');
11+
const session = await instance.connectInspectorSession();
12+
await session.send([
13+
{ 'method': 'Runtime.enable' },
14+
{ 'method': 'Debugger.enable' },
15+
{ 'method': 'Runtime.runIfWaitingForDebugger' }
16+
]);
17+
await session.waitForBreakOnLine(0, '[eval]');
18+
await session.runToCompletion();
19+
assert.strictEqual(0, (await instance.expectShutdown()).exitCode);
20+
}
21+
22+
runTests();

test/inspector/test-scriptparsed-context.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ const script = `
1010
const assert = require('assert');
1111
const vm = require('vm');
1212
const { kParsingContext } = process.binding('contextify');
13-
debugger;
14-
1513
global.outer = true;
1614
global.inner = false;
1715
const context = vm.createContext({
@@ -61,7 +59,7 @@ async function runTests() {
6159
{ 'method': 'Debugger.enable' },
6260
{ 'method': 'Runtime.runIfWaitingForDebugger' }
6361
]);
64-
await session.waitForBreakOnLine(5, '[eval]');
62+
await session.waitForBreakOnLine(0, '[eval]');
6563

6664
await session.send({ 'method': 'Runtime.enable' });
6765
const topContext = await getContext(session);

0 commit comments

Comments
 (0)