diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2021-05-13 19:58:19 +0300 |
---|---|---|
committer | Danielle Adams <adamzdanielle@gmail.com> | 2021-05-31 22:34:47 +0300 |
commit | a98d6319053c76328152ebb0364588b8bb9bb66a (patch) | |
tree | 82687c1466ce944f893d6ecf11bb30ed46dbf34e /lib | |
parent | 2268d1cf4c99ab1074d1d5480839df465a6837ae (diff) |
bootstrap: include vm and contextify binding into the snapshot
In addition, defer the patching of the vm module based on the
value of --experimental-vm-modules to runtime.
PR-URL: https://github.com/nodejs/node/pull/38677
Refs: https://github.com/nodejs/node/issues/35711
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/internal/bootstrap/node.js | 1 | ||||
-rw-r--r-- | lib/internal/bootstrap/pre_execution.js | 12 | ||||
-rw-r--r-- | lib/vm.js | 11 |
3 files changed, 16 insertions, 8 deletions
diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 81a9547b907..de5acbef5b5 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -361,6 +361,7 @@ process.emitWarning = emitWarning; // Preload modules so that they are included in the builtin snapshot. require('fs'); require('v8'); +require('vm'); function setupPrepareStackTrace() { const { diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js index e52da0868e1..62ba7da371d 100644 --- a/lib/internal/bootstrap/pre_execution.js +++ b/lib/internal/bootstrap/pre_execution.js @@ -434,6 +434,18 @@ function initializeESMLoader() { // track of for different ESM modules. setInitializeImportMetaObjectCallback(esm.initializeImportMetaObject); setImportModuleDynamicallyCallback(esm.importModuleDynamicallyCallback); + + // Patch the vm module when --experimental-vm-modules is on. + // Please update the comments in vm.js when this block changes. + if (getOptionValue('--experimental-vm-modules')) { + const { + Module, SourceTextModule, SyntheticModule, + } = require('internal/vm/module'); + const vm = require('vm'); + vm.Module = Module; + vm.SourceTextModule = SourceTextModule; + vm.SyntheticModule = SyntheticModule; + } } function initializeFrozenIntrinsics() { diff --git a/lib/vm.js b/lib/vm.js index 5c39429b3d1..0b643110ae9 100644 --- a/lib/vm.js +++ b/lib/vm.js @@ -422,11 +422,6 @@ module.exports = { measureMemory, }; -if (require('internal/options').getOptionValue('--experimental-vm-modules')) { - const { - Module, SourceTextModule, SyntheticModule, - } = require('internal/vm/module'); - module.exports.Module = Module; - module.exports.SourceTextModule = SourceTextModule; - module.exports.SyntheticModule = SyntheticModule; -} +// The vm module is patched to include vm.Module, vm.SourceTextModule +// and vm.SyntheticModule in the pre-execution phase when +// --experimental-vm-modules is on. |