Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 19b1edf

Browse filesBrowse files
joyeecheungaduh95
authored andcommitted
module: simplify --inspect-brk handling
Previously in the CommonJS loader, --inspect-brk is implemented checking whether the module points to the result of re-resolving process.argv[1] to determine whether the module is the entry point. This is unnecessarily complex, especially now that we store that information in the module as kIsMainSymbol. This patch updates it to simply check that symbol property instead. PR-URL: #55679 Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 9b351b0 commit 19b1edf
Copy full SHA for 19b1edf

File tree

Expand file treeCollapse file tree

1 file changed

+4
-38
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+4
-38
lines changed
Open diff view settings
Collapse file

‎lib/internal/modules/cjs/loader.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/cjs/loader.js
+4-38Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,15 +1332,6 @@ Module.prototype.require = function(id) {
13321332
}
13331333
};
13341334

1335-
/**
1336-
* Resolved path to `process.argv[1]` will be lazily placed here
1337-
* (needed for setting breakpoint when called with `--inspect-brk`).
1338-
* @type {string | undefined}
1339-
*/
1340-
let resolvedArgv;
1341-
let hasPausedEntry = false;
1342-
/** @type {import('vm').Script} */
1343-
13441335
/**
13451336
* Resolve and evaluate it synchronously as ESM if it's ESM.
13461337
* @param {Module} mod CJS module instance
@@ -1542,32 +1533,6 @@ Module.prototype._compile = function(content, filename, format) {
15421533
return;
15431534
}
15441535

1545-
// TODO(joyeecheung): the detection below is unnecessarily complex. Using the
1546-
// kIsMainSymbol, or a kBreakOnStartSymbol that gets passed from
1547-
// higher level instead of doing hacky detection here.
1548-
let inspectorWrapper = null;
1549-
if (getOptionValue('--inspect-brk') && process._eval == null) {
1550-
if (!resolvedArgv) {
1551-
// We enter the repl if we're not given a filename argument.
1552-
if (process.argv[1]) {
1553-
try {
1554-
resolvedArgv = Module._resolveFilename(process.argv[1], null, false);
1555-
} catch {
1556-
// We only expect this codepath to be reached in the case of a
1557-
// preloaded module (it will fail earlier with the main entry)
1558-
assert(ArrayIsArray(getOptionValue('--require')));
1559-
}
1560-
} else {
1561-
resolvedArgv = 'repl';
1562-
}
1563-
}
1564-
1565-
// Set breakpoint on module start
1566-
if (resolvedArgv && !hasPausedEntry && filename === resolvedArgv) {
1567-
hasPausedEntry = true;
1568-
inspectorWrapper = internalBinding('inspector').callAndPauseOnStart;
1569-
}
1570-
}
15711536
const dirname = path.dirname(filename);
15721537
const require = makeRequireFunction(this, redirects);
15731538
let result;
@@ -1577,9 +1542,10 @@ Module.prototype._compile = function(content, filename, format) {
15771542
if (requireDepth === 0) { statCache = new SafeMap(); }
15781543
setHasStartedUserCJSExecution();
15791544
this[kIsExecuting] = true;
1580-
if (inspectorWrapper) {
1581-
result = inspectorWrapper(compiledWrapper, thisValue, exports,
1582-
require, module, filename, dirname);
1545+
if (this[kIsMainSymbol] && getOptionValue('--inspect-brk')) {
1546+
const { callAndPauseOnStart } = internalBinding('inspector');
1547+
result = callAndPauseOnStart(compiledWrapper, thisValue, exports,
1548+
require, module, filename, dirname);
15831549
} else {
15841550
result = ReflectApply(compiledWrapper, thisValue,
15851551
[exports, require, module, filename, dirname]);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.