瀏覽代碼

LibWeb: Use a JS::NonnullGCPtr for DOMTokenList::m_associated_element

Both Element and DOMTokenList are GC-allocated objects so they can just
mark each other instead of using the old strong/weak pattern we use in
ref-counting ownership models.
Andreas Kling 2 年之前
父節點
當前提交
7d863174b3
共有 2 個文件被更改,包括 9 次插入1 次删除
  1. 6 0
      Userland/Libraries/LibWeb/DOM/DOMTokenList.cpp
  2. 3 1
      Userland/Libraries/LibWeb/DOM/DOMTokenList.h

+ 6 - 0
Userland/Libraries/LibWeb/DOM/DOMTokenList.cpp

@@ -68,6 +68,12 @@ DOMTokenList::DOMTokenList(Element const& associated_element, FlyString associat
     associated_attribute_changed(value);
 }
 
+void DOMTokenList::visit_edges(Cell::Visitor& visitor)
+{
+    Base::visit_edges(visitor);
+    visitor.visit(m_associated_element);
+}
+
 // https://dom.spec.whatwg.org/#ref-for-domtokenlist%E2%91%A0%E2%91%A1
 void DOMTokenList::associated_attribute_changed(StringView value)
 {

+ 3 - 1
Userland/Libraries/LibWeb/DOM/DOMTokenList.h

@@ -45,10 +45,12 @@ public:
 private:
     DOMTokenList(Element const& associated_element, FlyString associated_attribute);
 
+    virtual void visit_edges(Cell::Visitor&) override;
+
     WebIDL::ExceptionOr<void> validate_token(StringView token) const;
     void run_update_steps();
 
-    WeakPtr<Element> m_associated_element;
+    JS::NonnullGCPtr<Element> m_associated_element;
     FlyString m_associated_attribute;
     Vector<DeprecatedString> m_token_set;
 };