Skip to content

Commit

Permalink
loader: fix --inspect-brk
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
devsnek authored and addaleax committed Mar 5, 2018
1 parent 44d80c5 commit 59547cc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
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

0 comments on commit 59547cc

Please sign in to comment.