From 7e46e4d5ab9d915d5b239ff776d79c406e296ea9 Mon Sep 17 00:00:00 2001 From: ldm0 Date: Fri, 18 Sep 2026 21:29:29 +0800 Subject: [PATCH] fix(scripts): execute child inline classics synchronously Prepare connected script candidates after DOM mutation borrows are released and execute child inline classics before the inserting DOM call returns. Reuse the child realm runner for CSP, error reporting and execution cleanup; remove the obsolete queued DynamicClassic work and preserve currentScript on the execution Document across nested scripts and adoption. Cover initial about:blank, srcdoc, reentrant fragments, script errors, Shadow DOM, retirement and microtask order. Move three location WPT cases to passed and the newly observable window.open referrer failure to failed. Validation: cargo fmt --all; full workspace clippy with all targets and features and -D warnings; cargo nextest run --no-fail-fast (19457 passed, 13 skipped). 35 related WPT cases show no previously passing regression; 104 timing/CSP checks pass against Chromium. The running-script shadow movement probe follows the HTML currentScript algorithm and differs from Chromium 145; both official Shadow DOM WPT cases pass. --- .../context_host/child_dynamic_scripts.rs | 10 +++------- .../context_host/child_runtime_script_order.rs | 11 ++++++----- moli-renderer-v8/src/runtime/page_vm/tests/bitmap.rs | 2 +- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/moli-renderer-v8/src/native_bridge/context_host/child_dynamic_scripts.rs b/moli-renderer-v8/src/native_bridge/context_host/child_dynamic_scripts.rs index f0a825ddc4d..3eb7c80971e 100644 --- a/moli-renderer-v8/src/native_bridge/context_host/child_dynamic_scripts.rs +++ b/moli-renderer-v8/src/native_bridge/context_host/child_dynamic_scripts.rs @@ -172,13 +172,9 @@ impl PageScriptHost { else { return Ok(()); }; - job.script_nonce = self - .dom_host() - .node(script_handle) - .and_then(crate::dom::native::Node::as_element) - .and_then(|element| element.cryptographic_nonce()) - .map(str::to_owned) - .or_else(|| self.dom_host().get_attribute(script_handle, "nonce")); + job.script_nonce = + crate::host::script_element_nonce_for_csp(self.dom_host(), script_handle) + .map(str::to_owned); job.script_integrity = self.dom_host().get_attribute(script_handle, "integrity"); // Commit before entering V8: the script can remove and reinsert itself, // mutate another pending script, or replace its preparation Document. diff --git a/moli-renderer-v8/src/native_bridge/context_host/child_runtime_script_order.rs b/moli-renderer-v8/src/native_bridge/context_host/child_runtime_script_order.rs index 41726dfaab8..5d307ef038e 100644 --- a/moli-renderer-v8/src/native_bridge/context_host/child_runtime_script_order.rs +++ b/moli-renderer-v8/src/native_bridge/context_host/child_runtime_script_order.rs @@ -132,7 +132,7 @@ mod tests { use super::*; use crate::frame_owner_model::{ DocumentId, FrameDocumentRealmBoundScriptWork, FrameSchedulerLaneId, LocalWindowId, - PendingChildDynamicDocumentScript, + PendingChildExternalClassicDocumentScript, }; fn owner(document: u64) -> FrameDocumentTaskOwner { @@ -144,14 +144,15 @@ mod tests { } fn work(owner: FrameDocumentTaskOwner, node: DomHandle) -> FrameDocumentScriptReadyTaskWork { - FrameDocumentRealmBoundScriptWork::DynamicClassic(PendingChildDynamicDocumentScript { + FrameDocumentRealmBoundScriptWork::ExternalClassic(PendingChildExternalClassicDocumentScript { child_handle: DomHandle::new(1), owner, realm_id: Some(FrameRealmId(2)), script_handle: node, - source: String::new(), - script_nonce: None, - script_integrity: None, + load_delay: crate::frame_owner_model::ChildDocumentAsyncClassicScriptLoadDelay::AlreadyUnblocked, + source_result: Ok(String::new()), + script_url: url::Url::parse("https://child-script-order.test/script.js").unwrap(), + script_base_url: url::Url::parse("https://child-script-order.test/").unwrap(), }) .into() } diff --git a/moli-renderer-v8/src/runtime/page_vm/tests/bitmap.rs b/moli-renderer-v8/src/runtime/page_vm/tests/bitmap.rs index f4765c17c45..07c24936cee 100644 --- a/moli-renderer-v8/src/runtime/page_vm/tests/bitmap.rs +++ b/moli-renderer-v8/src/runtime/page_vm/tests/bitmap.rs @@ -171,7 +171,7 @@ async fn bitmap_task_uses_child_intrinsics_and_retires_when_the_child_window_is_ 'scheduled' "#)?; run_expected_child_realm_materialization_for_wait(&mut page_vm, "child bitmap realm").await; - assert!(page_vm.run_exact_selected_page_task_for_test(PageSelectedTaskTestSelector::ChildDocumentScriptReady, &loader).await?); + assert!(!page_vm.run_exact_selected_page_task_for_test(PageSelectedTaskTestSelector::ChildDocumentScriptReady, &loader).await?, "inline execution must not leave a queued script task"); run_ready_bitmap_task(&mut page_vm).await?; assert_eq!(page_vm.vm_mut().eval("JSON.stringify(bitmapChildOutcome)")?, "[3,4,true]"); assert!(page_vm.vm().has_pending_bitmap_tasks());