瀏覽代碼

LibWeb: Cache pseudo element layout nodes weakly on DOM::Element

Having the cache be strong created a reference cycle between DOM nodes
and their pseudo elements.
Andreas Kling 2 年之前
父節點
當前提交
8412206cb4
共有 2 個文件被更改,包括 4 次插入4 次删除
  1. 3 3
      Userland/Libraries/LibWeb/DOM/Element.cpp
  2. 1 1
      Userland/Libraries/LibWeb/DOM/Element.h

+ 3 - 3
Userland/Libraries/LibWeb/DOM/Element.cpp

@@ -711,17 +711,17 @@ void Element::children_changed()
 
 void Element::set_pseudo_element_node(Badge<Layout::TreeBuilder>, CSS::Selector::PseudoElement pseudo_element, RefPtr<Layout::Node> pseudo_element_node)
 {
-    m_pseudo_element_nodes[to_underlying(pseudo_element)] = move(pseudo_element_node);
+    m_pseudo_element_nodes[to_underlying(pseudo_element)] = pseudo_element_node->make_weak_ptr();
 }
 
 RefPtr<Layout::Node> Element::get_pseudo_element_node(CSS::Selector::PseudoElement pseudo_element) const
 {
-    return m_pseudo_element_nodes[to_underlying(pseudo_element)];
+    return m_pseudo_element_nodes[to_underlying(pseudo_element)].strong_ref();
 }
 
 void Element::clear_pseudo_element_nodes(Badge<Layout::TreeBuilder>)
 {
-    m_pseudo_element_nodes.fill(nullptr);
+    m_pseudo_element_nodes.fill({});
 }
 
 void Element::serialize_pseudo_elements_as_json(JsonArraySerializer<StringBuilder>& children_array) const

+ 1 - 1
Userland/Libraries/LibWeb/DOM/Element.h

@@ -188,7 +188,7 @@ private:
 
     Vector<FlyString> m_classes;
 
-    Array<RefPtr<Layout::Node>, CSS::Selector::PseudoElementCount> m_pseudo_element_nodes;
+    Array<WeakPtr<Layout::Node>, CSS::Selector::PseudoElementCount> m_pseudo_element_nodes;
 };
 
 template<>