diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2021-05-13 19:58:19 +0300 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2021-05-19 20:16:00 +0300 |
commit | 527da94a3e39c95c3acbc599772d45d57ce3b1fd (patch) | |
tree | d0cfced15d9abbd12815de46d6ac527cf6e17c7b /lib | |
parent | 5d7b6c249740824035aa779bceb20b738ae587fd (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. |