diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index 3e5e356324f..b50382e01ab 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -505,7 +505,6 @@ void Document::visit_edges(Cell::Visitor& visitor) visitor.visit(m_document_observers); visitor.visit(m_pending_scroll_event_targets); visitor.visit(m_pending_scrollend_event_targets); - visitor.visit(m_intersection_observers); visitor.visit(m_resize_observers); visitor.visit(m_shared_resource_requests); @@ -4037,7 +4036,14 @@ void Document::run_the_update_intersection_observations_steps(HighResolutionTime // 1. Let observer list be a list of all IntersectionObservers whose root is in the DOM tree of document. // For the top-level browsing context, this includes implicit root observers. // 2. For each observer in observer list: - for (auto& observer : m_intersection_observers) { + + // NOTE: We make a copy of the intersection observers list to avoid modifying it while iterating. + JS::MarkedVector> intersection_observers(heap()); + intersection_observers.ensure_capacity(m_intersection_observers.size()); + for (auto& observer : m_intersection_observers) + intersection_observers.append(observer); + + for (auto& observer : intersection_observers) { // 1. Let rootBounds be observer’s root intersection rectangle. auto root_bounds = observer->root_intersection_rectangle(); diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h index 88a10bb5f59..74cd011e886 100644 --- a/Libraries/LibWeb/DOM/Document.h +++ b/Libraries/LibWeb/DOM/Document.h @@ -939,8 +939,8 @@ private: JS::GCPtr m_visual_viewport; - // NOTE: Not in the spec per say, but Document must be able to access all IntersectionObservers whose root is in the document. - OrderedHashTable> m_intersection_observers; + // NOTE: Not in the spec per se, but Document must be able to access all IntersectionObservers whose root is in the document. + IGNORE_GC OrderedHashTable> m_intersection_observers; // https://www.w3.org/TR/intersection-observer/#document-intersectionobservertaskqueued // Each document has an IntersectionObserverTaskQueued flag which is initialized to false.