Skip to content

Commit 19b1edf

Browse 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 <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent 9b351b0 commit 19b1edf

File tree

1 file changed

+4
-38
lines changed

1 file changed

+4
-38
lines changed

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

Lines 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-
letresolvedArgv;
1341-
lethasPausedEntry=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-
letinspectorWrapper=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
constdirname=path.dirname(filename);
15721537
constrequire=makeRequireFunction(this,redirects);
15731538
letresult;
@@ -1577,9 +1542,10 @@ Module.prototype._compile = function(content, filename, format){
15771542
if(requireDepth===0){statCache=newSafeMap();}
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)