Skip to content

Commit 59547cc

Browse files
devsnekaddaleax
authored andcommitted
loader: fix --inspect-brk
PR-URL: #18949 Fixes: #18948 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 44d80c5 commit 59547cc

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

lib/internal/loader/ModuleJob.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class ModuleJob {
1515
this.loader = loader;
1616
this.error = null;
1717
this.hadError = false;
18+
this.inspectBrk = inspectBrk;
1819

1920
// This is a Promise<{ module, reflect }>, whose fields will be copied
2021
// onto `this` by `link()` below once it has been resolved.
@@ -26,10 +27,6 @@ class ModuleJob {
2627
const link = async () => {
2728
({ module: this.module,
2829
reflect: this.reflect } = await this.modulePromise);
29-
if (inspectBrk) {
30-
const initWrapper = process.binding('inspector').callAndPauseOnStart;
31-
initWrapper(this.module.instantiate, this.module);
32-
}
3330
assert(this.module instanceof ModuleWrap);
3431

3532
const dependencyJobs = [];
@@ -83,7 +80,12 @@ class ModuleJob {
8380
throw e;
8481
}
8582
try {
86-
this.module.instantiate();
83+
if (this.inspectBrk) {
84+
const initWrapper = process.binding('inspector').callAndPauseOnStart;
85+
initWrapper(this.module.instantiate, this.module);
86+
} else {
87+
this.module.instantiate();
88+
}
8789
} catch (e) {
8890
decorateErrorStack(e);
8991
throw e;

test/fixtures/es-modules/loop.mjs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { message } from './message';
2+
13
var t = 1;
24
var k = 1;
3-
console.log('A message', 5);
5+
console.log(message, 5);
46
while (t > 0) {
57
if (t++ === 1000) {
68
t = 0;

test/fixtures/es-modules/message.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const message = 'A message';

test/parallel/test-inspector-esm.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const common = require('../common');
55
common.skipIfInspectorDisabled();
66

77
const assert = require('assert');
8+
const { resolve: UrlResolve } = require('url');
89
const fixtures = require('../common/fixtures');
910
const { NodeInstance } = require('../common/inspector-helper.js');
1011

@@ -43,14 +44,15 @@ async function testBreakpointOnStart(session) {
4344
];
4445

4546
await session.send(commands);
46-
await session.waitForBreakOnLine(0, session.scriptURL());
47+
await session.waitForBreakOnLine(
48+
0, UrlResolve(session.scriptURL().toString(), 'message.mjs'));
4749
}
4850

4951
async function testBreakpoint(session) {
5052
console.log('[test]', 'Setting a breakpoint and verifying it is hit');
5153
const commands = [
5254
{ 'method': 'Debugger.setBreakpointByUrl',
53-
'params': { 'lineNumber': 5,
55+
'params': { 'lineNumber': 7,
5456
'url': session.scriptURL(),
5557
'columnNumber': 0,
5658
'condition': ''
@@ -66,7 +68,7 @@ async function testBreakpoint(session) {
6668
`Script source is wrong: ${scriptSource}`);
6769

6870
await session.waitForConsoleOutput('log', ['A message', 5]);
69-
const paused = await session.waitForBreakOnLine(5, session.scriptURL());
71+
const paused = await session.waitForBreakOnLine(7, session.scriptURL());
7072
const scopeId = paused.params.callFrames[0].scopeChain[0].object.objectId;
7173

7274
console.log('[test]', 'Verify we can read current application state');
@@ -79,7 +81,7 @@ async function testBreakpoint(session) {
7981
'generatePreview': true
8082
}
8183
});
82-
assertScopeValues(response, { t: 1001, k: 1 });
84+
assertScopeValues(response, { t: 1001, k: 1, message: 'A message' });
8385

8486
let { result } = await session.send({
8587
'method': 'Debugger.evaluateOnCallFrame', 'params': {

0 commit comments

Comments
 (0)