diff --git a/moli-renderer-v8/src/document_runtime/mutation_commands.rs b/moli-renderer-v8/src/document_runtime/mutation_commands.rs index e90326390d1..fb0731d596c 100644 --- a/moli-renderer-v8/src/document_runtime/mutation_commands.rs +++ b/moli-renderer-v8/src/document_runtime/mutation_commands.rs @@ -1832,7 +1832,7 @@ impl DocumentRuntime { owner = ?binding.owner(), element = ?binding.element(), load_delay_token = ?binding.load_delay_token(), - settled, + ?settled, "settled invalidated connected-style lease at mutation commit" ); } diff --git a/moli-renderer-v8/src/frame_owner_model.rs b/moli-renderer-v8/src/frame_owner_model.rs index a0eb8cdbfd7..801ebaa0d4c 100644 --- a/moli-renderer-v8/src/frame_owner_model.rs +++ b/moli-renderer-v8/src/frame_owner_model.rs @@ -22,6 +22,8 @@ mod script_events; mod store; mod task_sources; +pub(crate) use load_event_gate::DocumentLoadDelaySettlement; + pub(crate) use classic_script_tasks::{ FrameClassicDocumentScriptExecutionAction, FrameClassicDocumentScriptExecutionStart, FrameDocumentClassicCompletionFinishAction, FrameDocumentClassicCompletionFollowup, diff --git a/moli-renderer-v8/src/frame_owner_model/lifecycle_blockers.rs b/moli-renderer-v8/src/frame_owner_model/lifecycle_blockers.rs index f040b537496..876358b4793 100644 --- a/moli-renderer-v8/src/frame_owner_model/lifecycle_blockers.rs +++ b/moli-renderer-v8/src/frame_owner_model/lifecycle_blockers.rs @@ -1,6 +1,8 @@ use std::collections::BTreeSet; -use super::load_event_gate::{DocumentLoadGate, DocumentLoadGateRelease}; +use super::load_event_gate::{ + DocumentLoadDelaySettlement, DocumentLoadGate, DocumentLoadGateRelease, +}; use super::records::{DocumentLoadDelayReason, DocumentLoadDelayTokenId}; /// All phase-specific blockers owned by one exact Document lifecycle. @@ -12,6 +14,17 @@ use super::records::{DocumentLoadDelayReason, DocumentLoadDelayTokenId}; pub(super) struct DocumentLifecycleBlockers { parser_deferred_scripts: BTreeSet, window_load: DocumentLoadGate, + state: DocumentLoadDelayState, +} + +/// Blocking authority and token identity have different lifetimes. A current +/// Document can invalidate all delays while their resource tasks still exist. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +enum DocumentLoadDelayState { + #[default] + Open, + Invalidated, + Retired, } impl DocumentLifecycleBlockers { @@ -20,7 +33,7 @@ impl DocumentLifecycleBlockers { token: DocumentLoadDelayTokenId, reason: DocumentLoadDelayReason, ) -> bool { - if self.owns_any(token) { + if self.state != DocumentLoadDelayState::Open || self.owns_any(token) { return false; } if reason == DocumentLoadDelayReason::ParserDeferredScript { @@ -30,15 +43,30 @@ impl DocumentLifecycleBlockers { } } - pub(super) fn release( + pub(super) fn settle( &mut self, token: DocumentLoadDelayTokenId, reason: DocumentLoadDelayReason, - ) -> bool { + ) -> DocumentLoadDelaySettlement { + match self.state { + DocumentLoadDelayState::Invalidated => { + return if self.owns_exact_token(token, reason) { + DocumentLoadDelaySettlement::Invalidated + } else { + DocumentLoadDelaySettlement::NotOwned + }; + } + DocumentLoadDelayState::Retired => return DocumentLoadDelaySettlement::NotOwned, + DocumentLoadDelayState::Open => {} + } if reason == DocumentLoadDelayReason::ParserDeferredScript { - self.parser_deferred_scripts.remove(&token) + if self.parser_deferred_scripts.remove(&token) { + DocumentLoadDelaySettlement::Released + } else { + DocumentLoadDelaySettlement::NotOwned + } } else { - self.window_load.release(token, reason).released() + self.window_load.release(token, reason).settlement() } } @@ -48,6 +76,17 @@ impl DocumentLifecycleBlockers { reason: DocumentLoadDelayReason, ) -> DocumentLoadGateRelease { debug_assert!(reason.blocks_window_load_directly()); + match self.state { + DocumentLoadDelayState::Invalidated => { + return if self.owns_exact_token(token, reason) { + DocumentLoadGateRelease::Invalidated + } else { + DocumentLoadGateRelease::NotOwned + }; + } + DocumentLoadDelayState::Retired => return DocumentLoadGateRelease::NotOwned, + DocumentLoadDelayState::Open => {} + } self.window_load.release(token, reason) } @@ -55,6 +94,14 @@ impl DocumentLifecycleBlockers { &self, token: DocumentLoadDelayTokenId, reason: DocumentLoadDelayReason, + ) -> bool { + self.state == DocumentLoadDelayState::Open && self.owns_exact_token(token, reason) + } + + fn owns_exact_token( + &self, + token: DocumentLoadDelayTokenId, + reason: DocumentLoadDelayReason, ) -> bool { if reason == DocumentLoadDelayReason::ParserDeferredScript { self.parser_deferred_scripts.contains(&token) @@ -68,6 +115,9 @@ impl DocumentLifecycleBlockers { } pub(super) fn has_reason(&self, reason: DocumentLoadDelayReason) -> bool { + if self.state != DocumentLoadDelayState::Open { + return false; + } if reason == DocumentLoadDelayReason::ParserDeferredScript { !self.parser_deferred_scripts.is_empty() } else { @@ -76,27 +126,43 @@ impl DocumentLifecycleBlockers { } pub(super) fn blocks_domcontentloaded(&self) -> bool { - !self.parser_deferred_scripts.is_empty() + self.state == DocumentLoadDelayState::Open && !self.parser_deferred_scripts.is_empty() } pub(super) fn blocks_window_load_directly(&self) -> bool { - self.window_load.is_blocked() + self.state == DocumentLoadDelayState::Open && self.window_load.is_blocked() } pub(super) fn release_all_document_script_delays(&mut self) -> usize { + if self.state != DocumentLoadDelayState::Open { + return 0; + } let parser_deferred = self.parser_deferred_scripts.len(); self.parser_deferred_scripts.clear(); parser_deferred + self.window_load.release_all_document_script_delays() } pub(super) fn clear_for_retirement(&mut self) { + self.state = DocumentLoadDelayState::Retired; self.parser_deferred_scripts.clear(); self.window_load.clear(); } + /// End all outstanding delays while their Document remains current. + /// Resource tasks may still finish, but no longer own a gate transition. + pub(super) fn invalidate_all(&mut self) { + if self.state != DocumentLoadDelayState::Retired { + self.state = DocumentLoadDelayState::Invalidated; + } + } + #[cfg(test)] pub(super) fn len(&self) -> usize { - self.parser_deferred_scripts.len() + self.window_load.len() + if self.state == DocumentLoadDelayState::Open { + self.parser_deferred_scripts.len() + self.window_load.len() + } else { + 0 + } } } @@ -116,11 +182,97 @@ mod tests { assert!(blockers.blocks_domcontentloaded()); assert!(blockers.blocks_window_load_directly()); - assert!(blockers.release(parser, DocumentLoadDelayReason::ParserDeferredScript)); + assert_eq!( + blockers.settle(parser, DocumentLoadDelayReason::ParserDeferredScript), + DocumentLoadDelaySettlement::Released + ); assert!(!blockers.blocks_domcontentloaded()); assert_eq!( blockers.release_window_load(window, DocumentLoadDelayReason::AsyncModuleScript), DocumentLoadGateRelease::BecameUnblocked ); } + + #[test] + fn invalidation_settles_every_resource_kind_without_a_new_gate_transition() { + let reasons = [ + DocumentLoadDelayReason::AsyncClassicScript, + DocumentLoadDelayReason::BlockingStylesheet, + DocumentLoadDelayReason::StylesheetSubresource, + DocumentLoadDelayReason::ParserDeferredScript, + DocumentLoadDelayReason::AsyncModuleScript, + DocumentLoadDelayReason::Image, + DocumentLoadDelayReason::Media, + DocumentLoadDelayReason::StyleLoadEvent, + DocumentLoadDelayReason::Navigation, + ]; + let mut blockers = DocumentLifecycleBlockers::default(); + for (index, reason) in reasons.iter().copied().enumerate() { + assert!(blockers.acquire(DocumentLoadDelayTokenId(index as u64), reason)); + } + assert!(blockers.blocks_domcontentloaded()); + assert!(blockers.blocks_window_load_directly()); + + blockers.invalidate_all(); + blockers.invalidate_all(); + assert!(!blockers.blocks_domcontentloaded()); + assert!(!blockers.blocks_window_load_directly()); + assert_eq!(blockers.len(), 0); + for (index, reason) in reasons.iter().copied().enumerate() { + let token = DocumentLoadDelayTokenId(index as u64); + assert!(!blockers.owns(token, reason)); + assert!(!blockers.acquire(token, reason)); + for _ in 0..2 { + assert_eq!( + blockers.settle(token, reason), + DocumentLoadDelaySettlement::Invalidated + ); + } + if reason.blocks_window_load_directly() { + assert_eq!( + blockers.release_window_load(token, reason), + DocumentLoadGateRelease::Invalidated + ); + } + } + assert!(!blockers.blocks_domcontentloaded()); + assert!(!blockers.blocks_window_load_directly()); + + blockers.clear_for_retirement(); + for (index, reason) in reasons.iter().copied().enumerate() { + assert!(!blockers.owns_any(DocumentLoadDelayTokenId(index as u64))); + assert_eq!( + blockers.settle(DocumentLoadDelayTokenId(index as u64), reason), + DocumentLoadDelaySettlement::NotOwned + ); + } + } + + #[test] + fn invalidation_does_not_authorize_unknown_wrong_reason_or_already_released_tokens() { + let mut blockers = DocumentLifecycleBlockers::default(); + let released = DocumentLoadDelayTokenId(1); + let outstanding = DocumentLoadDelayTokenId(2); + assert!(blockers.acquire(released, DocumentLoadDelayReason::StyleLoadEvent)); + assert!(blockers.acquire(outstanding, DocumentLoadDelayReason::Image)); + assert_eq!( + blockers.settle(released, DocumentLoadDelayReason::StyleLoadEvent), + DocumentLoadDelaySettlement::Released + ); + blockers.invalidate_all(); + for token in [released, outstanding, DocumentLoadDelayTokenId(3)] { + assert_eq!( + blockers.settle(token, DocumentLoadDelayReason::StyleLoadEvent), + DocumentLoadDelaySettlement::NotOwned + ); + } + assert_eq!( + blockers.release_window_load(outstanding, DocumentLoadDelayReason::StyleLoadEvent), + DocumentLoadGateRelease::NotOwned + ); + assert_eq!( + blockers.settle(outstanding, DocumentLoadDelayReason::Image), + DocumentLoadDelaySettlement::Invalidated + ); + } } diff --git a/moli-renderer-v8/src/frame_owner_model/lifecycle_tasks.rs b/moli-renderer-v8/src/frame_owner_model/lifecycle_tasks.rs index 6a624156a06..5e6494255c0 100644 --- a/moli-renderer-v8/src/frame_owner_model/lifecycle_tasks.rs +++ b/moli-renderer-v8/src/frame_owner_model/lifecycle_tasks.rs @@ -34,6 +34,8 @@ pub(crate) enum MainDocumentScriptLoadDelayRelease { /// `load` had already completed when the script was admitted, so the /// lease intentionally carried no gate token. AlreadyUnblocked, + /// The Document invalidated this exact lease before its terminal body. + Invalidated, /// The exact token was released, while another load blocker remains. StillBlocked, /// The exact token was the final entry in the Document load gate. @@ -41,7 +43,7 @@ pub(crate) enum MainDocumentScriptLoadDelayRelease { } impl MainDocumentScriptLoadDelayRelease { - pub(crate) const fn released(self) -> bool { + pub(crate) const fn settled(self) -> bool { !matches!(self, Self::NotOwned) } } diff --git a/moli-renderer-v8/src/frame_owner_model/load_event_gate.rs b/moli-renderer-v8/src/frame_owner_model/load_event_gate.rs index 2c680051a60..9fe8cb9eeb3 100644 --- a/moli-renderer-v8/src/frame_owner_model/load_event_gate.rs +++ b/moli-renderer-v8/src/frame_owner_model/load_event_gate.rs @@ -5,25 +5,60 @@ use super::records::{DocumentLoadDelayReason, DocumentLoadDelayTokenId}; /// Document-owned ledger for work that directly delays the Window `load` /// transition. /// +/// The enclosing lifecycle owns whether these identities still have blocking +/// authority; invalidation retains them only for authenticated late cleanup. +/// /// This is state, not a task source: it stores no executable payload, performs /// no wakeup, and knows nothing about script scheduling. Producers acquire an /// exact token before publishing work; the terminal owner releases that same /// token and uses the returned transition to reconsider lifecycle. #[derive(Debug, Default)] pub(super) struct DocumentLoadGate { - active: BTreeMap, + entries: BTreeMap, +} + +/// Settlement of an exact Document-owned load delay, independent of the +/// resource that acquired it and of the phase it used to block. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +pub(crate) enum DocumentLoadDelaySettlement { + /// The owner, token or reason does not match, or an active delay was + /// already released. + #[default] + NotOwned, + /// Admission occurred after the Document completed and acquired no delay. + NoDelayRequired, + /// This completion removed an active delay. + Released, + /// The Document already invalidated this exact delay. Later completions + /// are idempotent no-ops and cannot unblock or restart lifecycle work. + Invalidated, +} + +impl DocumentLoadDelaySettlement { + pub(crate) const fn settled(self) -> bool { + !matches!(self, Self::NotOwned) + } + + pub(crate) const fn released(self) -> bool { + matches!(self, Self::Released) + } } #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub(super) enum DocumentLoadGateRelease { NotOwned, + Invalidated, StillBlocked, BecameUnblocked, } impl DocumentLoadGateRelease { - pub(super) const fn released(self) -> bool { - !matches!(self, Self::NotOwned) + pub(super) const fn settlement(self) -> DocumentLoadDelaySettlement { + match self { + Self::NotOwned => DocumentLoadDelaySettlement::NotOwned, + Self::Invalidated => DocumentLoadDelaySettlement::Invalidated, + Self::StillBlocked | Self::BecameUnblocked => DocumentLoadDelaySettlement::Released, + } } } @@ -33,10 +68,10 @@ impl DocumentLoadGate { token: DocumentLoadDelayTokenId, reason: DocumentLoadDelayReason, ) -> bool { - if !reason.blocks_window_load_directly() || self.active.contains_key(&token) { + if !reason.blocks_window_load_directly() || self.entries.contains_key(&token) { return false; } - self.active.insert(token, reason); + self.entries.insert(token, reason); true } @@ -45,11 +80,11 @@ impl DocumentLoadGate { token: DocumentLoadDelayTokenId, expected_reason: DocumentLoadDelayReason, ) -> DocumentLoadGateRelease { - if self.active.get(&token) != Some(&expected_reason) { + if self.entries.get(&token) != Some(&expected_reason) { return DocumentLoadGateRelease::NotOwned; } - self.active.remove(&token); - if self.active.is_empty() { + self.entries.remove(&token); + if self.entries.is_empty() { DocumentLoadGateRelease::BecameUnblocked } else { DocumentLoadGateRelease::StillBlocked @@ -61,34 +96,35 @@ impl DocumentLoadGate { token: DocumentLoadDelayTokenId, reason: DocumentLoadDelayReason, ) -> bool { - self.active.get(&token) == Some(&reason) + self.entries.get(&token) == Some(&reason) } pub(super) fn owns_any(&self, token: DocumentLoadDelayTokenId) -> bool { - self.active.contains_key(&token) + self.entries.contains_key(&token) } pub(super) fn has_reason(&self, reason: DocumentLoadDelayReason) -> bool { - self.active.values().any(|candidate| *candidate == reason) + self.entries.values().any(|candidate| *candidate == reason) } pub(super) fn is_blocked(&self) -> bool { - !self.active.is_empty() + !self.entries.is_empty() } pub(super) fn clear(&mut self) { - self.active.clear(); + self.entries.clear(); } pub(super) fn release_all_document_script_delays(&mut self) -> usize { - let before = self.active.len(); - self.active.retain(|_, reason| !reason.is_document_script()); - before - self.active.len() + let before = self.entries.len(); + self.entries + .retain(|_, reason| !reason.is_document_script()); + before - self.entries.len() } #[cfg(test)] pub(super) fn len(&self) -> usize { - self.active.len() + self.entries.len() } } diff --git a/moli-renderer-v8/src/frame_owner_model/records.rs b/moli-renderer-v8/src/frame_owner_model/records.rs index 5bddcc9e242..258fc6ee4cf 100644 --- a/moli-renderer-v8/src/frame_owner_model/records.rs +++ b/moli-renderer-v8/src/frame_owner_model/records.rs @@ -11,7 +11,7 @@ use super::lifecycle_blockers::DocumentLifecycleBlockers; use super::load_delivery_tasks::{ FrameDocumentLoadDeliveryAdmissionId, FrameDocumentLoadDeliveryPhase, }; -use super::load_event_gate::DocumentLoadGateRelease; +use super::load_event_gate::{DocumentLoadDelaySettlement, DocumentLoadGateRelease}; #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub(crate) struct FrameId(pub(crate) String); @@ -869,7 +869,7 @@ impl DocumentLifecycleRecord { let previous_readiness = self.readiness?; let ready_state_changed = previous_readiness != DocumentReadinessState::Complete; - self.blockers.clear_for_retirement(); + self.blockers.invalidate_all(); self.incomplete_child_frames.clear(); self.parsing_delay_token = None; self.interactive_transition_token = None; @@ -898,7 +898,7 @@ impl DocumentLifecycleRecord { { return false; } - self.blockers.clear_for_retirement(); + self.blockers.invalidate_all(); self.parsing_delay_token = None; self.interactive_transition_token = None; self.domcontentloaded_transition_token = None; @@ -1215,12 +1215,12 @@ impl DocumentLifecycleRecord { self.blockers.acquire(token, reason) } - pub(super) fn release_load_delay( + pub(super) fn settle_load_delay( &mut self, token: DocumentLoadDelayTokenId, expected_reason: DocumentLoadDelayReason, - ) -> bool { - self.blockers.release(token, expected_reason) + ) -> DocumentLoadDelaySettlement { + self.blockers.settle(token, expected_reason) } pub(super) fn release_window_load_delay( @@ -1614,3 +1614,49 @@ pub(crate) struct FrameFunctionConstructorSource { pub(crate) parameters: Vec, pub(crate) body: String, } + +#[cfg(test)] +mod lifecycle_tests { + use super::*; + + #[test] + fn forced_completion_invalidates_delays_until_document_retirement() { + for kind in [ + DocumentLoadDeliveryKind::Main, + DocumentLoadDeliveryKind::Child, + ] { + for stopped in [false, true] { + let mut lifecycle = DocumentLifecycleRecord::loading( + kind, + DocumentLoadDelayTokenId(1), + DocumentLoadDelayTokenId(2), + ); + let token = DocumentLoadDelayTokenId(3); + assert!( + lifecycle.acquire_load_delay(token, DocumentLoadDelayReason::StyleLoadEvent) + ); + if stopped { + assert_eq!(lifecycle.stop_loading_without_load_event(), Some(true)); + assert_eq!(lifecycle.stop_loading_without_load_event(), Some(false)); + } else { + assert!(lifecycle.complete_initial_empty_document()); + } + assert!(lifecycle.is_complete()); + assert_eq!(lifecycle.load_delay_token_count(), 0); + assert!(!lifecycle.acquire_load_delay( + DocumentLoadDelayTokenId(4), + DocumentLoadDelayReason::Image + )); + assert_eq!( + lifecycle.settle_load_delay(token, DocumentLoadDelayReason::StyleLoadEvent), + DocumentLoadDelaySettlement::Invalidated + ); + lifecycle.retire(); + assert_eq!( + lifecycle.settle_load_delay(token, DocumentLoadDelayReason::StyleLoadEvent), + DocumentLoadDelaySettlement::NotOwned + ); + } + } + } +} diff --git a/moli-renderer-v8/src/frame_owner_model/store.rs b/moli-renderer-v8/src/frame_owner_model/store.rs index 87f1c252811..142f17fc211 100644 --- a/moli-renderer-v8/src/frame_owner_model/store.rs +++ b/moli-renderer-v8/src/frame_owner_model/store.rs @@ -12,7 +12,7 @@ use super::lifecycle_tasks::{ MainDocumentScriptLoadDelayLease, MainDocumentScriptLoadDelayRelease, MainDocumentStyleLoadEventBinding, StylesheetSubresourceLoadDelayBinding, }; -use super::load_event_gate::DocumentLoadGateRelease; +use super::load_event_gate::{DocumentLoadDelaySettlement, DocumentLoadGateRelease}; use super::module_clients::{ FrameDocumentModuleClientReservation, FrameDocumentModuleFetchClientStart, FrameDocumentModulepreloadLinkClient, @@ -2514,7 +2514,7 @@ impl FrameOwnerStore { token, DocumentLoadDelayReason::Navigation, ); - debug_assert!(released); + debug_assert!(released.released()); } Some(expected.owner()) } @@ -2787,6 +2787,7 @@ impl FrameOwnerStore { .release_window_load_delay(token, reason) { DocumentLoadGateRelease::NotOwned => MainDocumentScriptLoadDelayRelease::NotOwned, + DocumentLoadGateRelease::Invalidated => MainDocumentScriptLoadDelayRelease::Invalidated, DocumentLoadGateRelease::StillBlocked => { MainDocumentScriptLoadDelayRelease::StillBlocked } @@ -2841,12 +2842,12 @@ impl FrameOwnerStore { pub(crate) fn settle_main_style_load_event( &mut self, binding: MainDocumentStyleLoadEventBinding, - ) -> bool { + ) -> DocumentLoadDelaySettlement { if !self.main_style_load_event_is_current(binding) { - return false; + return DocumentLoadDelaySettlement::NotOwned; } let Some(token) = binding.load_delay_token() else { - return true; + return DocumentLoadDelaySettlement::NoDelayRequired; }; self.release_document_load_delay( binding.owner(), @@ -2923,12 +2924,12 @@ impl FrameOwnerStore { pub(crate) fn settle_stylesheet_subresource_load_delay( &mut self, binding: StylesheetSubresourceLoadDelayBinding, - ) -> bool { + ) -> DocumentLoadDelaySettlement { if !self.stylesheet_subresource_load_delay_is_current(binding) { - return false; + return DocumentLoadDelaySettlement::NotOwned; } let Some(token) = binding.load_delay_token() else { - return true; + return DocumentLoadDelaySettlement::NoDelayRequired; }; self.release_document_load_delay( binding.owner(), @@ -2973,12 +2974,12 @@ impl FrameOwnerStore { pub(crate) fn settle_main_image_load_delay( &mut self, binding: MainDocumentImageLoadDelayBinding, - ) -> bool { + ) -> DocumentLoadDelaySettlement { if !self.main_image_load_delay_is_current(binding) { - return false; + return DocumentLoadDelaySettlement::NotOwned; } let Some(token) = binding.load_delay_token() else { - return true; + return DocumentLoadDelaySettlement::NoDelayRequired; }; self.release_document_load_delay(binding.owner(), token, DocumentLoadDelayReason::Image) } @@ -3019,12 +3020,12 @@ impl FrameOwnerStore { pub(crate) fn settle_main_media_load_delay( &mut self, binding: MainDocumentMediaLoadDelayBinding, - ) -> bool { + ) -> DocumentLoadDelaySettlement { if !self.main_media_load_delay_is_current(binding) { - return false; + return DocumentLoadDelaySettlement::NotOwned; } let Some(token) = binding.load_delay_token() else { - return true; + return DocumentLoadDelaySettlement::NoDelayRequired; }; self.release_document_load_delay(binding.owner(), token, DocumentLoadDelayReason::Media) } @@ -3129,9 +3130,13 @@ impl FrameOwnerStore { pub(crate) fn settle_child_image_load_event_binding( &mut self, binding: FrameDocumentImageLoadEventBinding, - ) -> bool { + ) -> DocumentLoadDelaySettlement { let Some(token) = binding.load_delay_token() else { - return self.child_image_load_event_binding_is_current(binding); + return if self.child_image_load_event_binding_is_current(binding) { + DocumentLoadDelaySettlement::NoDelayRequired + } else { + DocumentLoadDelaySettlement::NotOwned + }; }; self.release_document_load_delay(binding.owner(), token, DocumentLoadDelayReason::Image) } @@ -3177,9 +3182,13 @@ impl FrameOwnerStore { pub(crate) fn settle_child_media_load_delay( &mut self, binding: FrameDocumentMediaLoadDelayBinding, - ) -> bool { + ) -> DocumentLoadDelaySettlement { let Some(token) = binding.load_delay_token() else { - return self.child_media_load_delay_is_current(binding); + return if self.child_media_load_delay_is_current(binding) { + DocumentLoadDelaySettlement::NoDelayRequired + } else { + DocumentLoadDelaySettlement::NotOwned + }; }; self.release_document_load_delay(binding.owner(), token, DocumentLoadDelayReason::Media) } @@ -3236,6 +3245,7 @@ impl FrameOwnerStore { token: DocumentLoadDelayTokenId, ) -> bool { self.release_document_load_delay(owner, token, DocumentLoadDelayReason::AsyncClassicScript) + .settled() } pub(crate) fn release_blocking_stylesheet_load_delay( @@ -3244,6 +3254,7 @@ impl FrameOwnerStore { token: DocumentLoadDelayTokenId, ) -> bool { self.release_document_load_delay(owner, token, DocumentLoadDelayReason::BlockingStylesheet) + .settled() } pub(crate) fn release_parser_deferred_script_load_delay( @@ -3256,6 +3267,7 @@ impl FrameOwnerStore { token, DocumentLoadDelayReason::ParserDeferredScript, ) + .settled() } pub(crate) fn release_async_module_script_load_delay( @@ -3264,6 +3276,7 @@ impl FrameOwnerStore { token: DocumentLoadDelayTokenId, ) -> bool { self.release_document_load_delay(owner, token, DocumentLoadDelayReason::AsyncModuleScript) + .settled() } fn release_document_load_delay( @@ -3271,14 +3284,12 @@ impl FrameOwnerStore { owner: FrameDocumentTaskOwner, token: DocumentLoadDelayTokenId, reason: DocumentLoadDelayReason, - ) -> bool { + ) -> DocumentLoadDelaySettlement { self.documents .get_mut(&owner.document_id) .filter(|document| document.local_window_id == owner.local_window_id) - .is_some_and(|document| { - document - .lifecycle_progress - .release_load_delay(token, reason) + .map_or(DocumentLoadDelaySettlement::NotOwned, |document| { + document.lifecycle_progress.settle_load_delay(token, reason) }) } diff --git a/moli-renderer-v8/src/frame_owner_model/store_tests.rs b/moli-renderer-v8/src/frame_owner_model/store_tests.rs index ed6692cec8d..ef3969f0f9d 100644 --- a/moli-renderer-v8/src/frame_owner_model/store_tests.rs +++ b/moli-renderer-v8/src/frame_owner_model/store_tests.rs @@ -755,6 +755,131 @@ fn main_async_script_delays_are_exact_and_replacement_owned() { ); } +#[test] +fn stopping_a_document_invalidates_resource_delays_by_exact_identity() { + let mut store = FrameOwnerStore::default(); + store.ensure_main_frame( + handle(1), + url("https://example.test/"), + url("https://example.test/"), + "https://example.test".to_owned(), + policy_container(), + policy_context(), + None, + ); + let snapshot = store.current_main_owner_snapshot().unwrap(); + let owner = FrameDocumentTaskOwner::new( + snapshot.scheduler_lane_id, + snapshot.local_window_id, + snapshot.document_id, + ); + let style = store + .accept_current_main_style_load_event(owner, handle(2)) + .unwrap(); + let image = store + .accept_current_main_image_load_delay(owner, handle(3)) + .unwrap(); + let media = store + .accept_current_main_media_load_delay(owner, handle(4)) + .unwrap(); + let stylesheet_resource = store + .accept_current_main_stylesheet_subresource_load_delay(owner) + .unwrap(); + let classic = store + .acquire_current_main_document_script_load_delay( + owner, + MainDocumentScriptLoadDelayKind::Classic, + ) + .unwrap(); + let module = store + .acquire_current_main_document_script_load_delay( + owner, + MainDocumentScriptLoadDelayKind::Module, + ) + .unwrap(); + + assert_eq!(store.stop_current_main_document_loading(owner), Some(true)); + assert_eq!(store.stop_current_main_document_loading(owner), Some(false)); + assert_eq!( + store.current_main_document_complete_transition_is_ready(owner), + Some(false) + ); + + let wrong_reason = + MainDocumentStyleLoadEventBinding::new(owner, handle(2), image.load_delay_token()); + let unknown = MainDocumentStyleLoadEventBinding::new( + owner, + handle(2), + Some(DocumentLoadDelayTokenId(u64::MAX)), + ); + assert_eq!( + store.settle_main_style_load_event(wrong_reason), + DocumentLoadDelaySettlement::NotOwned + ); + assert_eq!( + store.settle_main_style_load_event(unknown), + DocumentLoadDelaySettlement::NotOwned + ); + + for _ in 0..2 { + for settlement in [ + store.settle_main_style_load_event(style), + store.settle_main_image_load_delay(image), + store.settle_main_media_load_delay(media), + store.settle_stylesheet_subresource_load_delay(stylesheet_resource), + ] { + assert_eq!(settlement, DocumentLoadDelaySettlement::Invalidated); + assert!(!settlement.released()); + } + } + for lease in [classic, module] { + assert_eq!( + store.release_main_document_script_load_delay(lease), + MainDocumentScriptLoadDelayRelease::Invalidated + ); + } + assert_eq!( + store.current_main_document_has_async_script_load_delay(owner), + Some(false) + ); + assert_eq!( + store.current_main_document_complete_transition_is_ready(owner), + Some(false) + ); + + let post_stop = store + .accept_current_main_style_load_event(owner, handle(5)) + .unwrap(); + assert!(post_stop.load_delay_token().is_none()); + assert_eq!( + store.settle_main_style_load_event(post_stop), + DocumentLoadDelaySettlement::NoDelayRequired + ); + + let replacement = store + .replace_main_document( + handle(1), + url("https://example.test/new"), + url("https://example.test/new"), + ) + .unwrap(); + let new_style = store + .accept_current_main_style_load_event(replacement.current_owner(), handle(6)) + .unwrap(); + assert_eq!( + store.settle_main_style_load_event(style), + DocumentLoadDelaySettlement::NotOwned + ); + assert_eq!( + store.settle_main_image_load_delay(image), + DocumentLoadDelaySettlement::NotOwned + ); + assert_eq!( + store.settle_main_style_load_event(new_style), + DocumentLoadDelaySettlement::Released + ); +} + #[test] fn main_style_load_event_binding_delays_complete_until_event_settlement() { let mut store = FrameOwnerStore::default(); @@ -796,9 +921,9 @@ fn main_style_load_event_binding_delays_complete_until_event_settlement() { "the exact style event token must block complete" ); - assert!(store.settle_main_style_load_event(binding)); + assert!(store.settle_main_style_load_event(binding).settled()); assert!( - !store.settle_main_style_load_event(binding), + !store.settle_main_style_load_event(binding).settled(), "one style event binding must settle exactly once" ); assert_eq!( @@ -873,7 +998,7 @@ fn main_style_load_event_binding_cannot_settle_replacement_document() { assert!(!store.main_style_load_event_is_current(stale)); assert!( - !store.settle_main_style_load_event(stale), + !store.settle_main_style_load_event(stale).settled(), "stale style completion must not mutate replacement lifecycle" ); assert_eq!( @@ -923,7 +1048,7 @@ fn main_image_request_delay_is_element_owned_and_replacement_safe() { Some(false) ); - assert!(store.settle_main_image_load_delay(event)); + assert!(store.settle_main_image_load_delay(event).settled()); assert_eq!( store.current_main_document_complete_transition_is_ready(owner), Some(true), @@ -942,7 +1067,7 @@ fn main_image_request_delay_is_element_owned_and_replacement_safe() { .expect("main replacement"); assert!(!store.main_image_load_delay_is_current(stale)); assert!( - !store.settle_main_image_load_delay(stale), + !store.settle_main_image_load_delay(stale).settled(), "stale image event must not release replacement state" ); assert_eq!( @@ -992,13 +1117,21 @@ fn main_stylesheet_subresource_delays_are_exact_and_replacement_safe() { store.current_main_document_complete_transition_is_ready(owner), Some(false) ); - assert!(store.settle_stylesheet_subresource_load_delay(image)); + assert!( + store + .settle_stylesheet_subresource_load_delay(image) + .settled() + ); assert_eq!( store.current_main_document_complete_transition_is_ready(owner), Some(false), "the remaining CSS font token must keep complete blocked" ); - assert!(store.settle_stylesheet_subresource_load_delay(font)); + assert!( + store + .settle_stylesheet_subresource_load_delay(font) + .settled() + ); assert_eq!( store.current_main_document_complete_transition_is_ready(owner), Some(true) @@ -1015,7 +1148,11 @@ fn main_stylesheet_subresource_delays_are_exact_and_replacement_safe() { ) .expect("main replacement"); assert!(!store.stylesheet_subresource_load_delay_is_current(stale)); - assert!(!store.settle_stylesheet_subresource_load_delay(stale)); + assert!( + !store + .settle_stylesheet_subresource_load_delay(stale) + .settled() + ); assert_eq!( store.current_main_document_complete_transition_is_ready(replacement.current_owner()), Some(false) @@ -1062,7 +1199,7 @@ fn main_media_delay_is_element_owned_and_cannot_settle_replacement() { Some(false), "the media element must retain its load delay through first data" ); - assert!(store.settle_main_media_load_delay(binding)); + assert!(store.settle_main_media_load_delay(binding).settled()); assert_eq!( store.current_main_document_complete_transition_is_ready(owner), Some(true) @@ -1080,7 +1217,7 @@ fn main_media_delay_is_element_owned_and_cannot_settle_replacement() { .expect("main replacement"); assert!(!store.main_media_load_delay_is_current(stale)); assert!( - !store.settle_main_media_load_delay(stale), + !store.settle_main_media_load_delay(stale).settled(), "stale media completion must not release replacement state" ); assert_eq!( @@ -4562,9 +4699,9 @@ fn child_image_load_event_binding_delays_complete_and_retires_with_document() { "the exact image token must block complete" ); - assert!(store.settle_child_image_load_event_binding(image)); + assert!(store.settle_child_image_load_event_binding(image).settled()); assert!( - !store.settle_child_image_load_event_binding(image), + !store.settle_child_image_load_event_binding(image).settled(), "image terminal must consume its load-delay token exactly once" ); let complete = store @@ -4599,7 +4736,9 @@ fn child_image_load_event_binding_delays_complete_and_retires_with_document() { "replacement must stale the old image event owner" ); assert!( - !store.settle_child_image_load_event_binding(post_complete_image), + !store + .settle_child_image_load_event_binding(post_complete_image) + .settled(), "a stale image event must not settle against the replacement document" ); } @@ -4630,7 +4769,11 @@ fn child_stylesheet_subresource_delays_release_only_their_document() { .prepare_current_child_document_complete_transition(child_handle, owner) .is_none() ); - assert!(store.settle_stylesheet_subresource_load_delay(image)); + assert!( + store + .settle_stylesheet_subresource_load_delay(image) + .settled() + ); assert!( store .prepare_current_child_document_complete_transition(child_handle, owner) @@ -4654,7 +4797,9 @@ fn child_stylesheet_subresource_delays_release_only_their_document() { assert_eq!(transition.retired_owner(), Some(owner)); assert!(!store.stylesheet_subresource_load_delay_is_current(font)); assert!( - !store.settle_stylesheet_subresource_load_delay(font), + !store + .settle_stylesheet_subresource_load_delay(font) + .settled(), "stale CSS terminal must not release replacement lifecycle state" ); let replacement = transition.current_owner().expect("replacement owner"); @@ -4715,9 +4860,9 @@ fn child_media_load_delay_is_element_owned_and_cannot_settle_replacement() { "the exact media token must block complete" ); - assert!(store.settle_child_media_load_delay(media)); + assert!(store.settle_child_media_load_delay(media).settled()); assert!( - !store.settle_child_media_load_delay(media), + !store.settle_child_media_load_delay(media).settled(), "loadeddata must consume the media token exactly once" ); let complete = store @@ -4748,7 +4893,9 @@ fn child_media_load_delay_is_element_owned_and_cannot_settle_replacement() { "replacement must stale the old media owner" ); assert!( - !store.settle_child_media_load_delay(post_complete_media), + !store + .settle_child_media_load_delay(post_complete_media) + .settled(), "a stale media event must not settle against the replacement document" ); } diff --git a/moli-renderer-v8/src/native_bridge/context_host/host_environment.rs b/moli-renderer-v8/src/native_bridge/context_host/host_environment.rs index 42e4da3b45f..f9b20271d3c 100644 --- a/moli-renderer-v8/src/native_bridge/context_host/host_environment.rs +++ b/moli-renderer-v8/src/native_bridge/context_host/host_environment.rs @@ -1120,7 +1120,7 @@ impl PageScriptHost { owner = ?binding.owner(), element = ?binding.element(), load_delay_token = ?binding.load_delay_token(), - settled, + ?settled, "settled invalidated connected-style lease at CSSOM commit" ); } diff --git a/moli-renderer-v8/src/native_bridge/context_host/image_loads.rs b/moli-renderer-v8/src/native_bridge/context_host/image_loads.rs index f003f319032..544db08e45a 100644 --- a/moli-renderer-v8/src/native_bridge/context_host/image_loads.rs +++ b/moli-renderer-v8/src/native_bridge/context_host/image_loads.rs @@ -377,19 +377,19 @@ impl PageScriptHost { owner = ?binding.owner(), image = binding.element().index(), token = ?binding.load_delay_token(), - settled, + ?settled, "settled main image load-delay binding" ); - settled + settled.settled() } PendingImageLoadDelaySettlement::Child(binding) => { - if !self + let settled = self .frame_owner_store - .settle_child_image_load_event_binding(binding) - { + .settle_child_image_load_event_binding(binding); + if !settled.settled() { return false; } - if queue_lifecycle_followup && binding.load_delay_token().is_some() { + if queue_lifecycle_followup && settled.released() { let _ = self.queue_child_document_complete_lifecycle_if_ready_for_owner( binding.child_handle(), binding.owner(), diff --git a/moli-renderer-v8/src/native_bridge/context_host/main_document_lifecycle.rs b/moli-renderer-v8/src/native_bridge/context_host/main_document_lifecycle.rs index 0f9d6534c9a..14d34beaa06 100644 --- a/moli-renderer-v8/src/native_bridge/context_host/main_document_lifecycle.rs +++ b/moli-renderer-v8/src/native_bridge/context_host/main_document_lifecycle.rs @@ -1,11 +1,12 @@ use super::PageScriptHost; use crate::frame_owner_model::{ - DocumentLinkEventOwner, DocumentLoadDelayTokenId, FrameDocumentTaskOwner, - MainDocumentCompleteLifecycleAction, MainDocumentDomContentLoadedLifecycleAction, - MainDocumentImageLoadDelayBinding, MainDocumentInteractiveLifecycleAction, - MainDocumentLoadCompletionState, MainDocumentMediaLoadDelayBinding, - MainDocumentScriptLoadDelayKind, MainDocumentScriptLoadDelayLease, - MainDocumentScriptLoadDelayRelease, MainDocumentStyleLoadEventBinding, + DocumentLinkEventOwner, DocumentLoadDelaySettlement, DocumentLoadDelayTokenId, + FrameDocumentTaskOwner, MainDocumentCompleteLifecycleAction, + MainDocumentDomContentLoadedLifecycleAction, MainDocumentImageLoadDelayBinding, + MainDocumentInteractiveLifecycleAction, MainDocumentLoadCompletionState, + MainDocumentMediaLoadDelayBinding, MainDocumentScriptLoadDelayKind, + MainDocumentScriptLoadDelayLease, MainDocumentScriptLoadDelayRelease, + MainDocumentStyleLoadEventBinding, }; use crate::{ document_runtime::{ @@ -234,7 +235,7 @@ impl PageScriptHost { pub(crate) fn settle_main_style_load_event( &mut self, binding: MainDocumentStyleLoadEventBinding, - ) -> bool { + ) -> DocumentLoadDelaySettlement { self.frame_owner_store.settle_main_style_load_event(binding) } @@ -258,7 +259,7 @@ impl PageScriptHost { pub(crate) fn settle_main_image_load_delay( &mut self, binding: MainDocumentImageLoadDelayBinding, - ) -> bool { + ) -> DocumentLoadDelaySettlement { self.frame_owner_store.settle_main_image_load_delay(binding) } @@ -282,7 +283,7 @@ impl PageScriptHost { pub(crate) fn settle_main_media_load_delay( &mut self, binding: MainDocumentMediaLoadDelayBinding, - ) -> bool { + ) -> DocumentLoadDelaySettlement { self.frame_owner_store.settle_main_media_load_delay(binding) } diff --git a/moli-renderer-v8/src/native_bridge/context_host/media_loads.rs b/moli-renderer-v8/src/native_bridge/context_host/media_loads.rs index e98795b7797..dddcb5c9f21 100644 --- a/moli-renderer-v8/src/native_bridge/context_host/media_loads.rs +++ b/moli-renderer-v8/src/native_bridge/context_host/media_loads.rs @@ -286,10 +286,10 @@ impl PageScriptHost { media = media_handle.index(), sequence = id.get(), token = ?binding.load_delay_token(), - settled, + ?settled, "settled main media load-delay binding" ); - settled + settled.settled() } PendingMediaLoadDelaySettlement::Child(binding) => { self.settle_pending_child_media_load_delay(binding, true, Some(id)) @@ -391,7 +391,7 @@ impl PageScriptHost { PendingMediaLoadOwner::Main { load_delay: Some(binding), .. - } => self.settle_main_media_load_delay(binding), + } => self.settle_main_media_load_delay(binding).settled(), PendingMediaLoadOwner::Child { load_delay: Some(binding), .. @@ -425,16 +425,16 @@ impl PageScriptHost { media = binding.element().index(), sequence = sequence.map(MediaLoadSequenceId::get), token = ?binding.load_delay_token(), - settled, + ?settled, "settled child media load-delay binding" ); - if settled && queue_lifecycle_followup && binding.load_delay_token().is_some() { + if settled.released() && queue_lifecycle_followup { let _ = self.queue_child_document_complete_lifecycle_if_ready_for_owner( binding.child_handle(), binding.owner(), ); } - settled + settled.settled() } } diff --git a/moli-renderer-v8/src/native_bridge/context_host/stylesheet_subresource_loads.rs b/moli-renderer-v8/src/native_bridge/context_host/stylesheet_subresource_loads.rs index 1429f600add..cc14c537760 100644 --- a/moli-renderer-v8/src/native_bridge/context_host/stylesheet_subresource_loads.rs +++ b/moli-renderer-v8/src/native_bridge/context_host/stylesheet_subresource_loads.rs @@ -1,20 +1,11 @@ use super::PageScriptHost; use crate::{ document_runtime::DomHandle, - frame_owner_model::{FrameDocumentTaskOwner, StylesheetSubresourceLoadDelayBinding}, + frame_owner_model::{ + DocumentLoadDelaySettlement, FrameDocumentTaskOwner, StylesheetSubresourceLoadDelayBinding, + }, }; -#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] -pub(crate) struct StylesheetSubresourceLoadDelaySettlement { - settled: bool, -} - -impl StylesheetSubresourceLoadDelaySettlement { - pub(crate) fn settled(self) -> bool { - self.settled - } -} - impl PageScriptHost { pub(crate) fn accept_current_stylesheet_subresource_load_delay_for_document( &mut self, @@ -79,12 +70,11 @@ impl PageScriptHost { pub(crate) fn settle_stylesheet_subresource_load_delay( &mut self, binding: StylesheetSubresourceLoadDelayBinding, - ) -> StylesheetSubresourceLoadDelaySettlement { + ) -> DocumentLoadDelaySettlement { let settled = self .frame_owner_store .settle_stylesheet_subresource_load_delay(binding); - let queued_child_frame_task = if settled - && binding.load_delay_token().is_some() + let queued_child_frame_task = if settled.released() && let Some(child_handle) = binding.child_handle() { self.queue_child_document_complete_lifecycle_if_ready_for_owner( @@ -98,10 +88,10 @@ impl PageScriptHost { owner = ?binding.owner(), child_handle = ?binding.child_handle(), token = ?binding.load_delay_token(), - settled, + ?settled, queued_child_frame_task, "settled stylesheet subresource load delay" ); - StylesheetSubresourceLoadDelaySettlement { settled } + settled } } diff --git a/moli-renderer-v8/src/page_task_queue/stylesheet_task.rs b/moli-renderer-v8/src/page_task_queue/stylesheet_task.rs index 8c168fa846f..aead42bbf89 100644 --- a/moli-renderer-v8/src/page_task_queue/stylesheet_task.rs +++ b/moli-renderer-v8/src/page_task_queue/stylesheet_task.rs @@ -327,6 +327,9 @@ pub(crate) enum PageConnectedStyleLoadDelayEffect { /// The event task released the exact load-delay token captured when the /// connected style/link operation was admitted. ReleasedExactBinding, + /// The Document invalidated this exact delay before event settlement. + /// Completing the event performs no further load-gate transition. + InvalidatedExactBinding, /// Event dispatch synchronously replaced the binding's Document. /// /// Document replacement owns retirement of the old ledger. The selected diff --git a/moli-renderer-v8/src/runtime/page_vm/tests/stylesheet_task.rs b/moli-renderer-v8/src/runtime/page_vm/tests/stylesheet_task.rs index 031bad9ea77..d5844cd075b 100644 --- a/moli-renderer-v8/src/runtime/page_vm/tests/stylesheet_task.rs +++ b/moli-renderer-v8/src/runtime/page_vm/tests/stylesheet_task.rs @@ -1504,6 +1504,58 @@ document.head.appendChild(style); .expect("connected-style body/completion boundary test should run"); } +#[tokio::test(flavor = "current_thread")] +async fn connected_style_load_after_stop_loading_settles_without_load_event() { + run_page_vm_async_test(async move { + let loader = + crate::network::ResourceRequestClient::new(&FetchConfig::default()).expect("loader"); + let document_url = Url::parse("https://example.com/connected-style-after-stop").unwrap(); + let (mut page_vm, _resource_source, _owner_wake_rx) = + page_vm_with_bound_task_sources_and_owner_wake(&loader, document_url); + page_vm.vm_mut().eval( + r#" +globalThis.__afterStop = []; +addEventListener("load", () => __afterStop.push("window-load")); +const style = document.createElement("style"); +style.onload = () => __afterStop.push("style-load"); +style.textContent = "body { color: green; }"; +document.head.appendChild(style); +"queued" +"#, + )?; + page_vm + .vm_mut() + .prime_document_lifecycle_processing_and_record_stylesheet_network_results(); + let task = take_next_style_element_event_task_for_test(&mut page_vm) + .expect("one exact connected-style event task should be ready"); + + // Stop invalidates the delay without retiring the Document. The + // queued element event still runs and observes an invalidated handle. + page_vm.vm_mut().stop_current_main_document_loading()?; + assert_eq!(page_vm.vm_mut().eval("document.readyState")?, "complete"); + let body = page_vm.apply_selected_page_connected_style_event_turn(task)?; + assert_eq!( + body.action.target_effect, + PageConnectedStyleEventTargetEffect::DispatchedToCurrentOwner { + load_delay_effect: PageConnectedStyleLoadDelayEffect::InvalidatedExactBinding, + } + ); + page_vm + .finish_selected_page_networking_task( + PageNetworkingTurnAction::StyleElementEvent(body.action), + &loader, + ) + .await?; + assert_eq!( + page_vm.vm_mut().eval("__afterStop.join('|')")?, + "style-load" + ); + Ok::<_, anyhow::Error>(()) + }) + .await + .expect("connected-style load after stop test should run"); +} + #[tokio::test(flavor = "current_thread")] async fn connected_style_completion_syncs_a_microtask_created_child_after_checkpoint() { run_page_vm_async_test(async move { diff --git a/moli-renderer-v8/src/script_vm/main_document_post_parse_body.rs b/moli-renderer-v8/src/script_vm/main_document_post_parse_body.rs index 751b66d90eb..d83a6e80c71 100644 --- a/moli-renderer-v8/src/script_vm/main_document_post_parse_body.rs +++ b/moli-renderer-v8/src/script_vm/main_document_post_parse_body.rs @@ -158,7 +158,7 @@ impl ScriptVm { ._context_host .borrow_mut() .release_main_document_script_load_delay(binding); - if !release.released() { + if !release.settled() { tracing::warn!( ?owner, ?kind, diff --git a/moli-renderer-v8/src/script_vm/stylesheet_page_tasks.rs b/moli-renderer-v8/src/script_vm/stylesheet_page_tasks.rs index 0c4fdd86dd8..b79d0592f11 100644 --- a/moli-renderer-v8/src/script_vm/stylesheet_page_tasks.rs +++ b/moli-renderer-v8/src/script_vm/stylesheet_page_tasks.rs @@ -1,6 +1,7 @@ use super::ScriptVm; use crate::{ document_runtime::StylesheetImportCompletionAuthority, + frame_owner_model::DocumentLoadDelaySettlement, page_task_queue::{ PageConnectedStyleEventTargetEffect, PageConnectedStyleLoadDelayEffect, PageStylesheetNetworkingTargetEffect, RendererPageConnectedStyleEventTask, @@ -109,25 +110,32 @@ impl ScriptVm { ); return PageConnectedStyleLoadDelayEffect::ExactBindingRetiredWithDocument; } - let had_load_delay_token = binding.load_delay_token().is_some(); let settled = self ._context_host .borrow_mut() .settle_main_style_load_event(binding); assert!( - settled, - "a current connected style event must release its exact load-delay binding" + settled.settled(), + "a current connected style event must settle its exact load-delay binding" ); tracing::debug!( owner = ?binding.owner(), element = ?binding.element(), load_delay_token = ?binding.load_delay_token(), + ?settled, "settled main connected style load inside selected event body" ); - if had_load_delay_token { - PageConnectedStyleLoadDelayEffect::ReleasedExactBinding - } else { - PageConnectedStyleLoadDelayEffect::NoBindingRequired + match settled { + DocumentLoadDelaySettlement::NoDelayRequired => { + PageConnectedStyleLoadDelayEffect::NoBindingRequired + } + DocumentLoadDelaySettlement::Released => { + PageConnectedStyleLoadDelayEffect::ReleasedExactBinding + } + DocumentLoadDelaySettlement::Invalidated => { + PageConnectedStyleLoadDelayEffect::InvalidatedExactBinding + } + DocumentLoadDelaySettlement::NotOwned => unreachable!("settlement checked above"), } } } diff --git a/moli-renderer-v8/src/stylesheet_runtime/connected.rs b/moli-renderer-v8/src/stylesheet_runtime/connected.rs index c150f86bacc..ffaa37e64fa 100644 --- a/moli-renderer-v8/src/stylesheet_runtime/connected.rs +++ b/moli-renderer-v8/src/stylesheet_runtime/connected.rs @@ -572,11 +572,11 @@ impl DocumentRuntime { owner = ?binding.owner(), element = ?binding.element(), load_delay_token = ?binding.load_delay_token(), - settled, + ?settled, reason, "settled main connected style load before event posting" ); - settled + settled.settled() } fn settle_connected_style_load_admission(