Skip to content

Commit 4e6f8ab

Browse files
ryzokukenguybedford
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: nodejs/node#17396 PR-URL: nodejs/node#21573 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 2643801 commit 4e6f8ab

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

lib/internal/modules/cjs/loader.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -658,19 +658,13 @@ Module.prototype._compile = function(content, filename) {
658658

659659
content = stripShebang(content);
660660

661-
// create wrapper function
662-
var wrapper = Module.wrap(content);
663-
664-
var compiledWrapper = vm.runInThisContext(wrapper, {
665-
filename: filename,
666-
lineOffset: 0,
667-
displayErrors: true,
668-
importModuleDynamically: experimentalModules ? async (specifier) => {
669-
if (asyncESM === undefined) lazyLoadESM();
670-
const loader = await asyncESM.loaderPromise;
671-
return loader.import(specifier, normalizeReferrerURL(filename));
672-
} : undefined,
673-
});
661+
const compiledWrapper = vm.compileFunction(content, [
662+
'exports',
663+
'require',
664+
'module',
665+
'__filename',
666+
'__dirname',
667+
], { filename });
674668

675669
var inspectorWrapper = null;
676670
if (process._breakFirstLine && process._eval == null) {

0 commit comments

Comments
 (0)