LibWeb: Make a copy of Document's DocumentObserver set when iterating

The observer callbacks can do all kinds of things, so let's not be in
the middle of iterating the set in case someone decides to mutate it.

Fixes a crash when loading https://lichess.org/
This commit is contained in:
Andreas Kling 2023-06-26 11:22:12 +02:00
parent 6fb670c1c2
commit 17ba47558c
Notes: sideshowbarker 2024-07-17 05:21:12 +09:00

View file

@ -1752,7 +1752,8 @@ void Document::completely_finish_loading()
});
}
for (auto& document_observer : m_document_observers) {
auto observers_to_notify = m_document_observers.values();
for (auto& document_observer : observers_to_notify) {
if (document_observer->document_fully_loaded)
document_observer->document_fully_loaded();
}
@ -2627,7 +2628,8 @@ void Document::did_stop_being_active_document_in_browsing_context(Badge<HTML::Br
{
tear_down_layout_tree();
for (auto& document_observer : m_document_observers) {
auto observers_to_notify = m_document_observers.values();
for (auto& document_observer : observers_to_notify) {
if (document_observer->document_became_inactive)
document_observer->document_became_inactive();
}