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:
Gus Caplan 2018-02-23 00:19:50 -06:00
parent 3828fc6289
commit abd0d79304
No known key found for this signature in database
GPG Key ID: F00BD11880E82F0E
4 changed files with 17 additions and 10 deletions

View File

@ -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.
@ -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 = [];
@ -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;

View File

@ -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;

1
test/fixtures/es-modules/message.mjs vendored Normal file
View File

@ -0,0 +1 @@
export const message = 'A message';

View File

@ -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');
@ -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': ''
@ -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');
@ -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': {