loader: fix --inspect-brk
PR-URL: https://github.com/nodejs/node/pull/18949 Fixes: https://github.com/nodejs/node/issues/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>
This commit is contained in:
parent
3828fc6289
commit
abd0d79304
@ -15,6 +15,7 @@ class ModuleJob {
|
|||||||
this.loader = loader;
|
this.loader = loader;
|
||||||
this.error = null;
|
this.error = null;
|
||||||
this.hadError = false;
|
this.hadError = false;
|
||||||
|
this.inspectBrk = inspectBrk;
|
||||||
|
|
||||||
// This is a Promise<{ module, reflect }>, whose fields will be copied
|
// This is a Promise<{ module, reflect }>, whose fields will be copied
|
||||||
// onto `this` by `link()` below once it has been resolved.
|
// onto `this` by `link()` below once it has been resolved.
|
||||||
@ -26,10 +27,6 @@ class ModuleJob {
|
|||||||
const link = async () => {
|
const link = async () => {
|
||||||
({ module: this.module,
|
({ module: this.module,
|
||||||
reflect: this.reflect } = await this.modulePromise);
|
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);
|
assert(this.module instanceof ModuleWrap);
|
||||||
|
|
||||||
const dependencyJobs = [];
|
const dependencyJobs = [];
|
||||||
@ -83,7 +80,12 @@ class ModuleJob {
|
|||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
if (this.inspectBrk) {
|
||||||
|
const initWrapper = process.binding('inspector').callAndPauseOnStart;
|
||||||
|
initWrapper(this.module.instantiate, this.module);
|
||||||
|
} else {
|
||||||
this.module.instantiate();
|
this.module.instantiate();
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
decorateErrorStack(e);
|
decorateErrorStack(e);
|
||||||
throw e;
|
throw e;
|
||||||
|
4
test/fixtures/es-modules/loop.mjs
vendored
4
test/fixtures/es-modules/loop.mjs
vendored
@ -1,6 +1,8 @@
|
|||||||
|
import { message } from './message';
|
||||||
|
|
||||||
var t = 1;
|
var t = 1;
|
||||||
var k = 1;
|
var k = 1;
|
||||||
console.log('A message', 5);
|
console.log(message, 5);
|
||||||
while (t > 0) {
|
while (t > 0) {
|
||||||
if (t++ === 1000) {
|
if (t++ === 1000) {
|
||||||
t = 0;
|
t = 0;
|
||||||
|
1
test/fixtures/es-modules/message.mjs
vendored
Normal file
1
test/fixtures/es-modules/message.mjs
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
export const message = 'A message';
|
@ -5,6 +5,7 @@ const common = require('../common');
|
|||||||
common.skipIfInspectorDisabled();
|
common.skipIfInspectorDisabled();
|
||||||
|
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
const { resolve: UrlResolve } = require('url');
|
||||||
const fixtures = require('../common/fixtures');
|
const fixtures = require('../common/fixtures');
|
||||||
const { NodeInstance } = require('../common/inspector-helper.js');
|
const { NodeInstance } = require('../common/inspector-helper.js');
|
||||||
|
|
||||||
@ -43,14 +44,15 @@ async function testBreakpointOnStart(session) {
|
|||||||
];
|
];
|
||||||
|
|
||||||
await session.send(commands);
|
await session.send(commands);
|
||||||
await session.waitForBreakOnLine(0, session.scriptURL());
|
await session.waitForBreakOnLine(
|
||||||
|
0, UrlResolve(session.scriptURL().toString(), 'message.mjs'));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function testBreakpoint(session) {
|
async function testBreakpoint(session) {
|
||||||
console.log('[test]', 'Setting a breakpoint and verifying it is hit');
|
console.log('[test]', 'Setting a breakpoint and verifying it is hit');
|
||||||
const commands = [
|
const commands = [
|
||||||
{ 'method': 'Debugger.setBreakpointByUrl',
|
{ 'method': 'Debugger.setBreakpointByUrl',
|
||||||
'params': { 'lineNumber': 5,
|
'params': { 'lineNumber': 7,
|
||||||
'url': session.scriptURL(),
|
'url': session.scriptURL(),
|
||||||
'columnNumber': 0,
|
'columnNumber': 0,
|
||||||
'condition': ''
|
'condition': ''
|
||||||
@ -66,7 +68,7 @@ async function testBreakpoint(session) {
|
|||||||
`Script source is wrong: ${scriptSource}`);
|
`Script source is wrong: ${scriptSource}`);
|
||||||
|
|
||||||
await session.waitForConsoleOutput('log', ['A message', 5]);
|
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;
|
const scopeId = paused.params.callFrames[0].scopeChain[0].object.objectId;
|
||||||
|
|
||||||
console.log('[test]', 'Verify we can read current application state');
|
console.log('[test]', 'Verify we can read current application state');
|
||||||
@ -79,7 +81,7 @@ async function testBreakpoint(session) {
|
|||||||
'generatePreview': true
|
'generatePreview': true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertScopeValues(response, { t: 1001, k: 1 });
|
assertScopeValues(response, { t: 1001, k: 1, message: 'A message' });
|
||||||
|
|
||||||
let { result } = await session.send({
|
let { result } = await session.send({
|
||||||
'method': 'Debugger.evaluateOnCallFrame', 'params': {
|
'method': 'Debugger.evaluateOnCallFrame', 'params': {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user