Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
refactor(renderer): guard module evaluation by document owner
ldm0527b408eaddb
diff --git a/moli-renderer-v8/src/script_vm/native_module.rs b/moli-renderer-v8/src/script_vm/native_module.rsindex 53f1ab7d3..baeafe17d 100644--- a/moli-renderer-v8/src/script_vm/native_module.rs+++ b/moli-renderer-v8/src/script_vm/native_module.rs@@ -3674,7 +3674,13 @@ impl ScriptVm {format!("native root module entry {root_entry:?} is not compiled"),)})?;- let runtime_generation_before_evaluation = self.document_runtime.runtime_reset_generation();+ let document_owner_before_evaluation =+ self.current_main_document_task_owner().ok_or_else(|| {+ ModuleLoadError::new(+ ModuleLoadStage::Evaluate,+ "native module evaluation has no current main Document owner",+ )+ })?;self.document_runtime.mark_native_module_evaluating(root_entry);let promise = self@@ -3759,8 +3765,7 @@ impl ScriptVm {ModuleLoadError::new(ModuleLoadStage::Evaluate, error.to_string())})??;if promise.is_none()- && self.document_runtime.runtime_reset_generation()- == runtime_generation_before_evaluation+ && self.current_main_document_task_owner() == Some(document_owner_before_evaluation){self.document_runtime.mark_native_module_evaluated(root_entry);diff --git a/moli-renderer-v8/src/script_vm/native_module/child_dynamic_import.rs b/moli-renderer-v8/src/script_vm/native_module/child_dynamic_import.rsindex ded2f9b6a..3e636258d 100644--- a/moli-renderer-v8/src/script_vm/native_module/child_dynamic_import.rs+++ b/moli-renderer-v8/src/script_vm/native_module/child_dynamic_import.rs@@ -915,6 +915,7 @@ impl ScriptVm {fn evaluate_native_dynamic_module_graph_with_modulator(&mut self,+ document_owner: FrameDocumentOwner,realm_id: FrameRealmId,document_modulator: &mut NativeDocumentModulator,root_entry: crate::module_runtime::ModuleEntryId,@@ -927,6 +928,8 @@ impl ScriptVm {})?;self.evaluate_native_module_graph_with_modulator_in_context(context_ptr,+ document_owner,+ realm_id,document_modulator,root_entry,NativeModuleEvaluationOwner::DynamicImport,@@ -963,6 +966,7 @@ impl ScriptVm {&graph,)?;vm.start_child_native_module_graph_evaluation(+ document_owner,realm_id,document_modulator,graph.root_entry,@@ -970,6 +974,7 @@ impl ScriptVm {}ModuleMapEntryState::Instantiated | ModuleMapEntryState::Evaluating => vm.start_child_native_module_graph_evaluation(+ document_owner,realm_id,document_modulator,graph.root_entry,@@ -1001,11 +1006,13 @@ impl ScriptVm {fn start_child_native_module_graph_evaluation(&mut self,+ document_owner: FrameDocumentOwner,realm_id: FrameRealmId,document_modulator: &mut NativeDocumentModulator,root_entry: crate::module_runtime::ModuleEntryId,) -> std::result::Result<DynamicModuleImportEvaluationStart, ModuleLoadError> {let evaluation = self.evaluate_native_dynamic_module_graph_with_modulator(+ document_owner,realm_id,document_modulator,root_entry,@@ -1020,6 +1027,8 @@ impl ScriptVm {pub(super) fn evaluate_native_module_graph_with_modulator_in_context(&mut self,context_ptr: *const v8::Global<v8::Context>,+ document_owner: FrameDocumentOwner,+ realm_id: FrameRealmId,document_modulator: &mut NativeDocumentModulator,root_entry: crate::module_runtime::ModuleEntryId,owner: NativeModuleEvaluationOwner,@@ -1033,7 +1042,6 @@ impl ScriptVm {format!("native root module entry {root_entry:?} is not compiled"),)})?;- let runtime_generation_before_evaluation = self.document_runtime.runtime_reset_generation();document_modulator.mark_evaluating(root_entry);let promise = self.renderer_document_isolate@@ -1112,10 +1120,12 @@ impl ScriptVm {.map_err(|error| {ModuleLoadError::new(ModuleLoadStage::Evaluate, error.to_string())})??;- if promise.is_none()- && self.document_runtime.runtime_reset_generation()- == runtime_generation_before_evaluation- {+ let document_owner_is_current = self+ ._context_host+ .borrow()+ .current_child_module_route_task_owner(document_owner, realm_id)+ .is_some();+ if promise.is_none() && document_owner_is_current {document_modulator.mark_evaluated(root_entry);}Ok(NativeModuleEvaluationResult {diff --git a/moli-renderer-v8/src/script_vm/native_module/child_parser_module/mod.rs b/moli-renderer-v8/src/script_vm/native_module/child_parser_module/mod.rsindex 4f07bdcbc..050ba5ee6 100644--- a/moli-renderer-v8/src/script_vm/native_module/child_parser_module/mod.rs+++ b/moli-renderer-v8/src/script_vm/native_module/child_parser_module/mod.rs@@ -61,6 +61,7 @@ impl ScriptVm {realm_id,|vm, document_modulator| {vm.start_child_parser_module_graph_evaluation_with_modulator(+ owner.document_owner(),realm_id,document_modulator,work.graph(),@@ -131,6 +132,7 @@ impl ScriptVm {fn start_child_parser_module_graph_evaluation_with_modulator(&mut self,+ document_owner: crate::frame_owner_model::FrameDocumentOwner,realm_id: FrameRealmId,document_modulator: &mut NativeDocumentModulator,graph: &crate::module_runtime::ModuleGraphHandle,@@ -154,6 +156,8 @@ impl ScriptVm {}let evaluation = self.evaluate_native_module_graph_with_modulator_in_context(context_ptr,+ document_owner,+ realm_id,document_modulator,graph.root_entry,NativeModuleEvaluationOwner::Script,