module: simplify --inspect-brk handling · nodejs/node@f507c05

@@ -1317,15 +1317,6 @@ Module.prototype.require = function(id) {

13171317

};

1318131813191319

let requireModuleWarningMode;

1320-

/**

1321-

* Resolved path to `process.argv[1]` will be lazily placed here

1322-

* (needed for setting breakpoint when called with `--inspect-brk`).

1323-

* @type {string | undefined}

1324-

*/

1325-

let resolvedArgv;

1326-

let hasPausedEntry = false;

1327-

/** @type {import('vm').Script} */

1328-13291320

/**

13301321

* Resolve and evaluate it synchronously as ESM if it's ESM.

13311322

* @param {Module} mod CJS module instance

@@ -1536,32 +1527,6 @@ Module.prototype._compile = function(content, filename, format) {

15361527

return;

15371528

}

153815291539-

// TODO(joyeecheung): the detection below is unnecessarily complex. Using the

1540-

// kIsMainSymbol, or a kBreakOnStartSymbol that gets passed from

1541-

// higher level instead of doing hacky detection here.

1542-

let inspectorWrapper = null;

1543-

if (getOptionValue('--inspect-brk') && process._eval == null) {

1544-

if (!resolvedArgv) {

1545-

// We enter the repl if we're not given a filename argument.

1546-

if (process.argv[1]) {

1547-

try {

1548-

resolvedArgv = Module._resolveFilename(process.argv[1], null, false);

1549-

} catch {

1550-

// We only expect this codepath to be reached in the case of a

1551-

// preloaded module (it will fail earlier with the main entry)

1552-

assert(ArrayIsArray(getOptionValue('--require')));

1553-

}

1554-

} else {

1555-

resolvedArgv = 'repl';

1556-

}

1557-

}

1558-1559-

// Set breakpoint on module start

1560-

if (resolvedArgv && !hasPausedEntry && filename === resolvedArgv) {

1561-

hasPausedEntry = true;

1562-

inspectorWrapper = internalBinding('inspector').callAndPauseOnStart;

1563-

}

1564-

}

15651530

const dirname = path.dirname(filename);

15661531

const require = makeRequireFunction(this, redirects);

15671532

let result;

@@ -1571,9 +1536,10 @@ Module.prototype._compile = function(content, filename, format) {

15711536

if (requireDepth === 0) { statCache = new SafeMap(); }

15721537

setHasStartedUserCJSExecution();

15731538

this[kIsExecuting] = true;

1574-

if (inspectorWrapper) {

1575-

result = inspectorWrapper(compiledWrapper, thisValue, exports,

1576-

require, module, filename, dirname);

1539+

if (this[kIsMainSymbol] && getOptionValue('--inspect-brk')) {

1540+

const { callAndPauseOnStart } = internalBinding('inspector');

1541+

result = callAndPauseOnStart(compiledWrapper, thisValue, exports,

1542+

require, module, filename, dirname);

15771543

} else {

15781544

result = ReflectApply(compiledWrapper, thisValue,

15791545

[exports, require, module, filename, dirname]);