Skip to content
Permalink
Browse files

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>
  • Loading branch information...
ryzokuken authored and rvagg committed Jun 28, 2018
1 parent 25ddbc9 commit b338edbb0ab1ae9823d1128ef9baa4295885b9d7
Showing with 7 additions and 13 deletions.
  1. +7 −13 lib/internal/modules/cjs/loader.js
@@ -692,19 +692,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) {

0 comments on commit b338edb

Please sign in to comment.
You can’t perform that action at this time.