瀏覽代碼

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 年之前
父節點
當前提交
17ba47558c
共有 1 個文件被更改,包括 4 次插入2 次删除
  1. 4 2
      Userland/Libraries/LibWeb/DOM/Document.cpp

+ 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)
             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();
     }