From 59d46af9466e8370b5ec6ccb60fc6e6fda043750 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 28 May 2025 11:20:05 +0200 Subject: [PATCH] LibWeb: Iterate safely in update_animations_and_send_events() Make copies of the animation timeline list and animations to dispatch events at before iterating over them. This ensures that they can't be modified during iteration. --- Libraries/LibWeb/DOM/Document.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index 87b56b1c328..37e82b77712 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -5240,7 +5240,9 @@ void Document::update_animations_and_send_events(Optional const& timesta // updated. // - Queueing animation events for any such animations. m_last_animation_frame_timestamp = timestamp; - for (auto const& timeline : m_associated_animation_timelines) + + auto timelines_to_update = GC::RootVector { heap(), m_associated_animation_timelines.values() }; + for (auto const& timeline : timelines_to_update) timeline->set_current_time(timestamp); // 2. Remove replaced animations for doc. @@ -5296,8 +5298,9 @@ void Document::update_animations_and_send_events(Optional const& timesta for (auto const& event : events_to_dispatch) event.target->dispatch_event(event.event); - for (auto& timeline : m_associated_animation_timelines) { - for (auto& animation : timeline->associated_animations()) + for (auto& timeline : timelines_to_update) { + auto animations_to_dispatch = GC::RootVector { heap(), timeline->associated_animations().values() }; + for (auto& animation : animations_to_dispatch) dispatch_events_for_animation_if_necessary(animation); } }