Browse Source

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/
Andreas Kling 2 năm trước cách đây
mục cha
commit
17ba47558c

+ 4 - 2
Userland/Libraries/LibWeb/DOM/Document.cpp

@@ -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)
         if (document_observer->document_fully_loaded)
             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();
     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)
         if (document_observer->document_became_inactive)
             document_observer->document_became_inactive();
             document_observer->document_became_inactive();
     }
     }