Skip to content

Commit

Permalink
module: use compileFunction over Module.wrap
Browse files Browse the repository at this point in the history
Use vm.compileFunction (which is a binding for
v8::CompileFunctionInContext) instead of Module.wrap internally in
Module._compile for the cjs loader.

Fixes: #17396

Backport-PR-URL: #27124
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]>
  • Loading branch information
ryzokuken authored and MylesBorins committed May 16, 2019
1 parent 51ec21c commit 590e8d3
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,19 +673,13 @@ Module.prototype._compile = function(content, filename) {

content = stripShebang(content);

// create wrapper function
var wrapper = Module.wrap(content);

var compiledWrapper = vm.runInThisContext(wrapper, {
filename: filename,
lineOffset: 0,
displayErrors: true,
importModuleDynamically: experimentalModules ? async (specifier) => {
if (asyncESM === undefined) lazyLoadESM();
const loader = await asyncESM.loaderPromise;
return loader.import(specifier, normalizeReferrerURL(filename));
} : undefined,
});
const compiledWrapper = vm.compileFunction(content, [
'exports',
'require',
'module',
'__filename',
'__dirname',
], { filename });

var inspectorWrapper = null;
if (process._breakFirstLine && process._eval == null) {
Expand Down

0 comments on commit 590e8d3

Please sign in to comment.