Skip to content

Commit 115c9f8

Browse files
ryzokukenaddaleax
authored andcommitted
module: use compileFunction over Module.wrap
Use vm.compileFunction (which is a binding for v8::CompileFunctionInContext) instead of Module.wrap internally in Module._compile for the cjs loader. Fixes: #17396 PR-URL: #21573 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 79376ce commit 115c9f8

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

lib/internal/modules/cjs/loader.js

+7-13
Original file line numberDiff line numberDiff line change
@@ -692,19 +692,13 @@ Module.prototype._compile = function(content, filename) {
692692

693693
content = stripShebang(content);
694694

695-
// create wrapper function
696-
var wrapper = Module.wrap(content);
697-
698-
var compiledWrapper = vm.runInThisContext(wrapper, {
699-
filename: filename,
700-
lineOffset: 0,
701-
displayErrors: true,
702-
importModuleDynamically: experimentalModules ? async (specifier) => {
703-
if (asyncESM === undefined) lazyLoadESM();
704-
const loader = await asyncESM.loaderPromise;
705-
return loader.import(specifier, normalizeReferrerURL(filename));
706-
} : undefined,
707-
});
695+
const compiledWrapper = vm.compileFunction(content, [
696+
'exports',
697+
'require',
698+
'module',
699+
'__filename',
700+
'__dirname',
701+
], { filename });
708702

709703
var inspectorWrapper = null;
710704
if (process._breakFirstLine && process._eval == null) {

0 commit comments

Comments
 (0)