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.
This commit is contained in:
Andreas Kling 2021-10-03 16:03:45 +02:00
parent bbfde63f79
commit 6f0d7245d7
Notes: sideshowbarker 2024-07-18 03:08:53 +09:00

View file

@ -20,7 +20,10 @@ public:
void ref()
{
VERIFY(!m_in_removed_last_ref);
VERIFY(m_ref_count);
if constexpr (!IsBaseOf<DOM::Node, T>) {
// 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;
}