Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loader: fix --inspect-brk #18949

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
12 changes: 7 additions & 5 deletions lib/internal/loader/ModuleJob.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ModuleJob {
this.loader = loader;
this.error = null;
this.hadError = false;
this.inspectBrk = inspectBrk;

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

const dependencyJobs = [];
Expand Down Expand Up @@ -83,7 +80,12 @@ class ModuleJob {
throw e;
}
try {
this.module.instantiate();
if (this.inspectBrk) {
const initWrapper = process.binding('inspector').callAndPauseOnStart;
initWrapper(this.module.instantiate, this.module);
} else {
this.module.instantiate();
}
} catch (e) {
decorateErrorStack(e);
throw e;
Expand Down
4 changes: 3 additions & 1 deletion test/fixtures/es-modules/loop.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { message } from './message';

var t = 1;
var k = 1;
console.log('A message', 5);
console.log(message, 5);
while (t > 0) {
if (t++ === 1000) {
t = 0;
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/es-modules/message.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const message = 'A message';
10 changes: 6 additions & 4 deletions test/parallel/test-inspector-esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const common = require('../common');
common.skipIfInspectorDisabled();

const assert = require('assert');
const { resolve: UrlResolve } = require('url');
const fixtures = require('../common/fixtures');
const { NodeInstance } = require('../common/inspector-helper.js');

Expand Down Expand Up @@ -43,14 +44,15 @@ async function testBreakpointOnStart(session) {
];

await session.send(commands);
await session.waitForBreakOnLine(0, session.scriptURL());
await session.waitForBreakOnLine(
0, UrlResolve(session.scriptURL().toString(), 'message.mjs'));
}

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

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

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

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