diff options
author | Andreas Kling <kling@serenityos.org> | 2022-08-28 13:42:07 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-09-06 00:27:09 +0200 |
commit | 6f433c86564c24d47d520cb5bdcc2209d724ac96 (patch) | |
tree | 886a2f727782e466e99c61c628637872c1b7403f /Userland/Libraries/LibWeb/DOM/TreeWalker.h | |
parent | bb547ce1c4251e3689287eac845593398a379ca5 (diff) | |
download | serenity-6f433c86564c24d47d520cb5bdcc2209d724ac96.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibWeb/DOM/TreeWalker.h')
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/TreeWalker.h | 40 |
1 files changed, 18 insertions, 22 deletions
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<TreeWalker> create(Node& root, unsigned what_to_show, JS::GCPtr<NodeFilter>); - explicit TreeWalker(Node& root); virtual ~TreeWalker() override; - TreeWalker& impl() { return *this; } - - NonnullRefPtr<Node> current_node() const; + JS::NonnullGCPtr<Node> current_node() const; void set_current_node(Node&); - JS::ThrowCompletionOr<RefPtr<Node>> parent_node(); - JS::ThrowCompletionOr<RefPtr<Node>> first_child(); - JS::ThrowCompletionOr<RefPtr<Node>> last_child(); - JS::ThrowCompletionOr<RefPtr<Node>> previous_sibling(); - JS::ThrowCompletionOr<RefPtr<Node>> next_sibling(); - JS::ThrowCompletionOr<RefPtr<Node>> previous_node(); - JS::ThrowCompletionOr<RefPtr<Node>> next_node(); + JS::ThrowCompletionOr<JS::GCPtr<Node>> parent_node(); + JS::ThrowCompletionOr<JS::GCPtr<Node>> first_child(); + JS::ThrowCompletionOr<JS::GCPtr<Node>> last_child(); + JS::ThrowCompletionOr<JS::GCPtr<Node>> previous_sibling(); + JS::ThrowCompletionOr<JS::GCPtr<Node>> next_sibling(); + JS::ThrowCompletionOr<JS::GCPtr<Node>> previous_node(); + JS::ThrowCompletionOr<JS::GCPtr<Node>> next_node(); - NonnullRefPtr<Node> root() { return m_root; } + JS::NonnullGCPtr<Node> 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<RefPtr<Node>> traverse_children(ChildTraversalType); + JS::ThrowCompletionOr<JS::GCPtr<Node>> traverse_children(ChildTraversalType); enum class SiblingTraversalType { Next, Previous, }; - JS::ThrowCompletionOr<RefPtr<Node>> traverse_siblings(SiblingTraversalType); + JS::ThrowCompletionOr<JS::GCPtr<Node>> traverse_siblings(SiblingTraversalType); JS::ThrowCompletionOr<NodeFilter::Result> filter(Node&); // https://dom.spec.whatwg.org/#concept-traversal-root - NonnullRefPtr<DOM::Node> m_root; + JS::NonnullGCPtr<Node> m_root; // https://dom.spec.whatwg.org/#treewalker-current - NonnullRefPtr<DOM::Node> m_current; + JS::NonnullGCPtr<Node> 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<DOM::NodeFilter> m_filter; + JS::GCPtr<NodeFilter> 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) |