From 6f0d7245d75be2e504133d6142900ff1490b82b8 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 3 Oct 2021 16:03:45 +0200 Subject: [PATCH] LibWeb: Allow Document::ref() when ref-count is zero DOM::Document has some special lifetime rules to support the DOM lifetime semantics expected on the web. Any DOM node will keep its document alive as well, even after the document's ref-count has reached zero. This is achieved by the Document::m_referencing_node_count counter. Because of this mechanism, we can't VERIFY(m_ref_count) in TreeNode where T may be a DOM::Document. --- Userland/Libraries/LibWeb/TreeNode.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/TreeNode.h b/Userland/Libraries/LibWeb/TreeNode.h index 15948e7318..2a8da45b8d 100644 --- a/Userland/Libraries/LibWeb/TreeNode.h +++ b/Userland/Libraries/LibWeb/TreeNode.h @@ -20,7 +20,10 @@ public: void ref() { VERIFY(!m_in_removed_last_ref); - VERIFY(m_ref_count); + if constexpr (!IsBaseOf) { + // NOTE: DOM::Document is allowed to survive with 0 ref count, if one of its descendant nodes are alive. + VERIFY(m_ref_count); + } ++m_ref_count; }