Skip to content

Commit d345b0d

Browse files
committed
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 <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 8375c70 commit d345b0d

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

lib/internal/modules/cjs/loader.js

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

701701
content = stripShebang(content);
702702

703-
// create wrapper function
704-
var wrapper = Module.wrap(content);
705-
706-
var compiledWrapper = vm.runInThisContext(wrapper, {
707-
filename: filename,
708-
lineOffset: 0,
709-
displayErrors: true,
710-
importModuleDynamically: experimentalModules ? async (specifier) => {
711-
if (asyncESM === undefined) lazyLoadESM();
712-
const loader = await asyncESM.loaderPromise;
713-
return loader.import(specifier, normalizeReferrerURL(filename));
714-
} : undefined,
715-
});
703+
const compiledWrapper = vm.compileFunction(content, [
704+
'exports',
705+
'require',
706+
'module',
707+
'__filename',
708+
'__dirname',
709+
], { filename });
716710

717711
var inspectorWrapper = null;
718712
if (process._breakFirstLine && process._eval == null) {

0 commit comments

Comments
 (0)