From 86afefafdae2bb00e2f2e886d17ca077bde4cf53 Mon Sep 17 00:00:00 2001 From: Chengzhong Wu Date: Wed, 1 Nov 2023 14:05:13 +0800 Subject: [PATCH] vm: allow dynamic import with a referrer realm A referrer can be a Script Record, a Cyclic Module Record, or a Realm Record as defined in https://tc39.es/ecma262/#sec-HostLoadImportedModule. Add support for dynamic import calls with a realm as the referrer and allow specifying an `importModuleDynamically` callback in `vm.createContext`. PR-URL: https://github.com/nodejs/node/pull/50360 Refs: https://github.com/nodejs/node/issues/49726 Reviewed-By: Joyee Cheung Reviewed-By: Antoine du Hamel --- doc/api/vm.md | 18 +++++ lib/internal/modules/esm/utils.js | 22 ++++-- lib/internal/vm.js | 4 +- lib/vm.js | 10 ++- src/module_wrap.cc | 22 +++--- src/node_contextify.cc | 28 +++++++- src/node_contextify.h | 1 + test/es-module/test-esm-dynamic-import.js | 6 ++ .../test-vm-module-referrer-realm.mjs | 70 +++++++++++++++++++ 9 files changed, 159 insertions(+), 22 deletions(-) create mode 100644 test/parallel/test-vm-module-referrer-realm.mjs diff --git a/doc/api/vm.md b/doc/api/vm.md index 3978a14cbf7584..fd94c932db9de8 100644 --- a/doc/api/vm.md +++ b/doc/api/vm.md @@ -1052,6 +1052,9 @@ function with the given `params`.