diff --git a/Userland/Libraries/LibWeb/DOM/DocumentFragment.h b/Userland/Libraries/LibWeb/DOM/DocumentFragment.h index 7a0ef4fa71..5b208500ab 100644 --- a/Userland/Libraries/LibWeb/DOM/DocumentFragment.h +++ b/Userland/Libraries/LibWeb/DOM/DocumentFragment.h @@ -26,13 +26,14 @@ public: virtual FlyString node_name() const override { return "#document-fragment"; } - RefPtr host() { return m_host; } - const RefPtr host() const { return m_host; } + Element* host() { return m_host; } + Element const* host() const { return m_host; } void set_host(Element& host) { m_host = host; } private: - RefPtr m_host; + // https://dom.spec.whatwg.org/#concept-documentfragment-host + WeakPtr m_host; }; } diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index b1eb86a63d..5f65d4a29a 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -701,7 +701,14 @@ u16 Node::compare_document_position(RefPtr other) // https://dom.spec.whatwg.org/#concept-tree-host-including-inclusive-ancestor bool Node::is_host_including_inclusive_ancestor_of(const Node& other) const { - return is_inclusive_ancestor_of(other) || (is(other.root()) && verify_cast(other.root()).host() && is_inclusive_ancestor_of(*verify_cast(other.root()).host().ptr())); + if (is_inclusive_ancestor_of(other)) + return true; + if (is(other.root()) + && static_cast(other.root()).host() + && is_inclusive_ancestor_of(*static_cast(other.root()).host())) { + return true; + } + return false; } // https://dom.spec.whatwg.org/#dom-node-ownerdocument