diff options
author | Luca Casonato <hello@lcas.dev> | 2023-05-09 12:37:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-09 12:37:13 +0200 |
commit | f34fcd16ea4d504c8a87c0873c65598d70bb1d07 (patch) | |
tree | db7eb7b1dd7f082fc28eb16f8cb3760296bed8e5 /core/modules.rs | |
parent | 723d4b038203e35f5be6d11088a7288e6d709869 (diff) |
fix(core): let V8 drive extension ESM loads (#18997)
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 <biwanczuk@gmail.com>
Diffstat (limited to 'core/modules.rs')
-rw-r--r-- | core/modules.rs | 24 |
1 files changed, 23 insertions, 1 deletions
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<str>, asserted_module_type: AssertedModuleType, |