From f34fcd16ea4d504c8a87c0873c65598d70bb1d07 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 9 May 2023 12:37:13 +0200 Subject: fix(core): let V8 drive extension ESM loads (#18997) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This now allows circular imports across extensions. Instead of load + eval of all ESM files in declaration order, all files are only loaded. Eval is done recursively by V8, only evaluating files that are listed in `Extension::esm_entry_point` fields. --------- Co-authored-by: Bartek IwaƄczuk --- core/modules.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'core/modules.rs') diff --git a/core/modules.rs b/core/modules.rs index 9352301ba..d1e871ba9 100644 --- a/core/modules.rs +++ b/core/modules.rs @@ -1093,6 +1093,28 @@ impl ModuleMap { output } + pub(crate) fn assert_all_modules_evaluated( + &self, + scope: &mut v8::HandleScope, + ) { + let mut not_evaluated = vec![]; + + for (i, handle) in self.handles.iter().enumerate() { + let module = v8::Local::new(scope, handle); + if !matches!(module.get_status(), v8::ModuleStatus::Evaluated) { + not_evaluated.push(self.info[i].name.as_str().to_string()); + } + } + + if !not_evaluated.is_empty() { + let mut msg = "Following modules were not evaluated; make sure they are imported from other code:\n".to_string(); + for m in not_evaluated { + msg.push_str(&format!(" - {}\n", m)); + } + panic!("{}", msg); + } + } + pub fn serialize_for_snapshotting( &self, scope: &mut v8::HandleScope, @@ -1366,7 +1388,7 @@ impl ModuleMap { /// Get module id, following all aliases in case of module specifier /// that had been redirected. - fn get_id( + pub(crate) fn get_id( &self, name: impl AsRef, asserted_module_type: AssertedModuleType, -- cgit v1.2.3