mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:07:36 +00:00
LibWeb: Weakly store NamedNodeMap's & Attribute's associated Element
This is similar to how Gecko avoids a reference cycle, where both the NamedNodeMap and Attribute would otherwise store a strong reference to their associated Element. Gecko manually clears stored raw references when an Element is destroyed, whereas we use weak references to do so automatically. Attribute's ownerElement getter and setter are moved out of line to avoid an #include cycle between Element and Attribute.
This commit is contained in:
parent
356d5821e7
commit
b67f6daf05
4 changed files with 35 additions and 8 deletions
|
@ -7,6 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/FlyString.h>
|
||||
#include <AK/WeakPtr.h>
|
||||
#include <LibWeb/DOM/Node.h>
|
||||
#include <LibWeb/QualifiedName.h>
|
||||
|
||||
|
@ -31,8 +32,8 @@ public:
|
|||
String const& value() const { return m_value; }
|
||||
void set_value(String value) { m_value = move(value); }
|
||||
|
||||
Element const* owner_element() const { return m_owner_element; }
|
||||
void set_owner_element(Element const* owner_element) { m_owner_element = owner_element; }
|
||||
Element const* owner_element() const;
|
||||
void set_owner_element(Element const* owner_element);
|
||||
|
||||
// Always returns true: https://dom.spec.whatwg.org/#dom-attr-specified
|
||||
constexpr bool specified() const { return true; }
|
||||
|
@ -42,7 +43,7 @@ private:
|
|||
|
||||
QualifiedName m_qualified_name;
|
||||
String m_value;
|
||||
Element const* m_owner_element { nullptr };
|
||||
WeakPtr<Element> m_owner_element;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue