From 113d0b70c904f3847825e21743a8d2474e8fe169 Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Thu, 28 Jun 2018 12:15:15 +0530 Subject: [PATCH] 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: https://github.com/nodejs/node/issues/17396 --- lib/internal/modules/cjs/loader.js | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index 8b357e5254ce4b..408030559c1309 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -691,19 +691,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) {