LibWeb: Don't visit registered document observers from Document

`DocumentObserver` register itself in Document` from constructor and
unregister itself from `finalize()`. The problem is that `finalize()`
won't be invoked for as long as `DocumentObserver` is visited by
`Document`. By not visiting registered observers from `Document` we
move this responsibility to object that allocated observer, which is
always exactly what we want, e.g. once `SVGUseElement` that uses
observer is gone, observer won't be visited anymore which will lead to
`finalize()` being called.
This commit is contained in:
Aliaksandr Kalenik 2025-07-29 23:34:58 +02:00 committed by Andreas Kling
commit 52b4f2a40a
Notes: github-actions[bot] 2025-07-29 22:56:31 +00:00
2 changed files with 3 additions and 2 deletions

View file

@ -581,7 +581,6 @@ void Document::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_scripts_to_execute_in_order_as_soon_as_possible);
visitor.visit(m_scripts_to_execute_as_soon_as_possible);
visitor.visit(m_node_iterators);
visitor.visit(m_document_observers);
visitor.visit(m_document_observers_being_notified);
visitor.visit(m_pending_scroll_event_targets);
visitor.visit(m_pending_scrollend_event_targets);

View file

@ -1081,7 +1081,9 @@ private:
HashTable<GC::Ptr<NodeIterator>> m_node_iterators;
HashTable<GC::Ref<DocumentObserver>> m_document_observers;
// Document should not visit DocumentObserver to avoid leaks.
// It's responsibility of object that requires DocumentObserver to keep it alive.
HashTable<GC::RawRef<DocumentObserver>> m_document_observers;
Vector<GC::Ref<DocumentObserver>> m_document_observers_being_notified;
// https://html.spec.whatwg.org/multipage/dom.html#is-initial-about:blank