diff options
author | Gus Caplan <me@gus.host> | 2020-04-22 00:43:58 +0300 |
---|---|---|
committer | Gus Caplan <me@gus.host> | 2020-04-25 17:49:53 +0300 |
commit | 74c393dd93cc0e461e3796fbcc09545fcacdecaf (patch) | |
tree | 75c9f468f6d53280cd9a2bdc0262e3f95d6eadb4 /lib/internal/modules | |
parent | 24a4e6153dae01cc7d5b28a21a105d680e9a5037 (diff) |
vm: add importModuleDynamically option to compileFunction
Fixes: https://github.com/nodejs/node/issues/31860
PR-URL: https://github.com/nodejs/node/pull/32985
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Diffstat (limited to 'lib/internal/modules')
-rw-r--r-- | lib/internal/modules/cjs/loader.js | 40 |
1 files changed, 12 insertions, 28 deletions
diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index e09cc437068..96988a6a471 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -77,7 +77,6 @@ const preserveSymlinksMain = getOptionValue('--preserve-symlinks-main'); const manifest = getOptionValue('--experimental-policy') ? require('internal/process/policy').manifest : null; -const { compileFunction } = internalBinding('contextify'); // Whether any user-provided CJS modules had been loaded (executed). // Used for internal assertions. @@ -1100,40 +1099,25 @@ function wrapSafe(filename, content, cjsModuleInstance) { }, }); } - let compiled; try { - compiled = compileFunction( - content, + return vm.compileFunction(content, [ + 'exports', + 'require', + 'module', + '__filename', + '__dirname', + ], { filename, - 0, - 0, - undefined, - false, - undefined, - [], - [ - 'exports', - 'require', - 'module', - '__filename', - '__dirname', - ] - ); + importModuleDynamically(specifier) { + const loader = asyncESM.ESMLoader; + return loader.import(specifier, normalizeReferrerURL(filename)); + }, + }); } catch (err) { if (process.mainModule === cjsModuleInstance) enrichCJSError(err); throw err; } - - const { callbackMap } = internalBinding('module_wrap'); - callbackMap.set(compiled.cacheKey, { - importModuleDynamically: async (specifier) => { - const loader = asyncESM.ESMLoader; - return loader.import(specifier, normalizeReferrerURL(filename)); - } - }); - - return compiled.function; } // Run the file contents in the correct scope or sandbox. Expose |