From f382139f9f9c7769396e64d07bc4bc9a45aa7fe6 Mon Sep 17 00:00:00 2001 From: Chengzhong Wu Date: Tue, 24 Oct 2023 16:18:01 +0800 Subject: [PATCH 1/2] 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`. --- 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 | 21 +++++- src/node_contextify.h | 1 + .../test-vm-module-referrer-realm.mjs | 70 +++++++++++++++++++ 8 files changed, 146 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`.