LibWeb: Add DOM tree version counter

This patch adds a u64 version counter to DOM::Document that increments
whenever the tree structure changes (via node insertion or removal),
or an element attribute is changed somehow.

This will be used as a crude invalidation mechanism for HTMLCollection
to cache its elements.
This commit is contained in:
Andreas Kling 2024-03-19 15:39:45 +01:00
commit cf60f52a78
Notes: sideshowbarker 2024-07-16 22:16:50 +09:00
3 changed files with 15 additions and 0 deletions

View file

@ -97,6 +97,11 @@ public:
static WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> construct_impl(JS::Realm&);
virtual ~Document() override;
// AD-HOC: This number increments whenever a node is added or removed from the document, or an element attribute changes.
// It can be used as a crude invalidation mechanism for caches that depend on the DOM structure.
u64 dom_tree_version() const { return m_dom_tree_version; }
void bump_dom_tree_version() { ++m_dom_tree_version; }
WebIDL::ExceptionOr<void> populate_with_html_head_and_body();
JS::GCPtr<Selection::Selection> get_selection() const;
@ -846,6 +851,8 @@ private:
mutable JS::GCPtr<WebIDL::ObservableArray> m_adopted_style_sheets;
Vector<JS::NonnullGCPtr<DOM::ShadowRoot>> m_shadow_roots;
u64 m_dom_tree_version { 0 };
};
template<>