diff options
author | Andreas Kling <kling@serenityos.org> | 2021-10-03 16:03:45 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-10-03 16:42:34 +0200 |
commit | 6f0d7245d75be2e504133d6142900ff1490b82b8 (patch) | |
tree | 931f7e3741ac52e2cc59514b8c3e8be80dee7572 /Userland/Libraries/LibWeb | |
parent | bbfde63f79b62080ade37051fc11a61ca132184f (diff) | |
download | serenity-6f0d7245d75be2e504133d6142900ff1490b82b8.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r-- | Userland/Libraries/LibWeb/TreeNode.h | 5 |
1 files changed, 4 insertions, 1 deletions
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<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; } |