From 59547cc438b9d2036c373167aac6b0eb548ea8b6 Mon Sep 17 00:00:00 2001 From: Gus Caplan Date: Fri, 23 Feb 2018 00:19:50 -0600 Subject: [PATCH] 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 Reviewed-By: Guy Bedford Reviewed-By: Colin Ihrig Reviewed-By: Eugene Ostroukhov Reviewed-By: James M Snell --- lib/internal/loader/ModuleJob.js | 12 +++++++----- test/fixtures/es-modules/loop.mjs | 4 +++- test/fixtures/es-modules/message.mjs | 1 + test/parallel/test-inspector-esm.js | 10 ++++++---- 4 files changed, 17 insertions(+), 10 deletions(-) create mode 100644 test/fixtures/es-modules/message.mjs diff --git a/lib/internal/loader/ModuleJob.js b/lib/internal/loader/ModuleJob.js index db37765b20bd0c..f79cc6cfe1d94a 100644 --- a/lib/internal/loader/ModuleJob.js +++ b/lib/internal/loader/ModuleJob.js @@ -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; diff --git a/test/fixtures/es-modules/loop.mjs b/test/fixtures/es-modules/loop.mjs index edd111abb9e9b7..1b5cab10edc7bf 100644 --- a/test/fixtures/es-modules/loop.mjs +++ b/test/fixtures/es-modules/loop.mjs @@ -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; diff --git a/test/fixtures/es-modules/message.mjs b/test/fixtures/es-modules/message.mjs new file mode 100644 index 00000000000000..d50f57b7b6a5f7 --- /dev/null +++ b/test/fixtures/es-modules/message.mjs @@ -0,0 +1 @@ +export const message = 'A message'; diff --git a/test/parallel/test-inspector-esm.js b/test/parallel/test-inspector-esm.js index 696f2af9a77462..3171da58cf7a4c 100644 --- a/test/parallel/test-inspector-esm.js +++ b/test/parallel/test-inspector-esm.js @@ -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': {