From 6f433c86564c24d47d520cb5bdcc2209d724ac96 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 28 Aug 2022 13:42:07 +0200 Subject: LibWeb+LibJS: Make the EventTarget hierarchy (incl. DOM) GC-allocated This is a monster patch that turns all EventTargets into GC-allocated PlatformObjects. Their C++ wrapper classes are removed, and the LibJS garbage collector is now responsible for their lifetimes. There's a fair amount of hacks and band-aids in this patch, and we'll have a lot of cleanup to do after this. --- Userland/Libraries/LibWeb/DOM/TreeWalker.h | 40 ++++++++++++++---------------- 1 file changed, 18 insertions(+), 22 deletions(-) (limited to 'Userland/Libraries/LibWeb/DOM/TreeWalker.h') diff --git a/Userland/Libraries/LibWeb/DOM/TreeWalker.h b/Userland/Libraries/LibWeb/DOM/TreeWalker.h index 076c6511aa..e43f7c21f2 100644 --- a/Userland/Libraries/LibWeb/DOM/TreeWalker.h +++ b/Userland/Libraries/LibWeb/DOM/TreeWalker.h @@ -12,61 +12,60 @@ namespace Web::DOM { // https://dom.spec.whatwg.org/#treewalker class TreeWalker final : public Bindings::PlatformObject { - JS_OBJECT(TreeWalker, JS::Object); + WEB_PLATFORM_OBJECT(TreeWalker, JS::Object); public: static JS::NonnullGCPtr create(Node& root, unsigned what_to_show, JS::GCPtr); - explicit TreeWalker(Node& root); virtual ~TreeWalker() override; - TreeWalker& impl() { return *this; } - - NonnullRefPtr current_node() const; + JS::NonnullGCPtr current_node() const; void set_current_node(Node&); - JS::ThrowCompletionOr> parent_node(); - JS::ThrowCompletionOr> first_child(); - JS::ThrowCompletionOr> last_child(); - JS::ThrowCompletionOr> previous_sibling(); - JS::ThrowCompletionOr> next_sibling(); - JS::ThrowCompletionOr> previous_node(); - JS::ThrowCompletionOr> next_node(); + JS::ThrowCompletionOr> parent_node(); + JS::ThrowCompletionOr> first_child(); + JS::ThrowCompletionOr> last_child(); + JS::ThrowCompletionOr> previous_sibling(); + JS::ThrowCompletionOr> next_sibling(); + JS::ThrowCompletionOr> previous_node(); + JS::ThrowCompletionOr> next_node(); - NonnullRefPtr root() { return m_root; } + JS::NonnullGCPtr root() { return m_root; } NodeFilter* filter() { return m_filter.ptr(); } unsigned what_to_show() const { return m_what_to_show; } private: + explicit TreeWalker(Node& root); + virtual void visit_edges(Cell::Visitor&) override; enum class ChildTraversalType { First, Last, }; - JS::ThrowCompletionOr> traverse_children(ChildTraversalType); + JS::ThrowCompletionOr> traverse_children(ChildTraversalType); enum class SiblingTraversalType { Next, Previous, }; - JS::ThrowCompletionOr> traverse_siblings(SiblingTraversalType); + JS::ThrowCompletionOr> traverse_siblings(SiblingTraversalType); JS::ThrowCompletionOr filter(Node&); // https://dom.spec.whatwg.org/#concept-traversal-root - NonnullRefPtr m_root; + JS::NonnullGCPtr m_root; // https://dom.spec.whatwg.org/#treewalker-current - NonnullRefPtr m_current; + JS::NonnullGCPtr m_current; // https://dom.spec.whatwg.org/#concept-traversal-whattoshow unsigned m_what_to_show { 0 }; // https://dom.spec.whatwg.org/#concept-traversal-filter - JS::GCPtr m_filter; + JS::GCPtr m_filter; // https://dom.spec.whatwg.org/#concept-traversal-active bool m_active { false }; @@ -74,7 +73,4 @@ private: } -namespace Web::Bindings { -inline JS::Object* wrap(JS::Realm&, Web::DOM::TreeWalker& object) { return &object; } -using TreeWalkerWrapper = Web::DOM::TreeWalker; -} +WRAPPER_HACK(TreeWalker, Web::DOM) -- cgit v1.2.3