summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/DOM/Document.cpp2
-rw-r--r--Userland/Libraries/LibWeb/DOM/Document.h2
-rw-r--r--Userland/Libraries/LibWeb/DOM/TreeWalker.cpp33
-rw-r--r--Userland/Libraries/LibWeb/DOM/TreeWalker.h27
-rw-r--r--Userland/Libraries/LibWeb/DOM/TreeWalker.idl2
-rw-r--r--Userland/Libraries/LibWeb/Forward.h1
-rw-r--r--Userland/Libraries/LibWeb/idl_files.cmake2
7 files changed, 40 insertions, 29 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp
index 584da3cdb4..95d189f44b 100644
--- a/Userland/Libraries/LibWeb/DOM/Document.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Document.cpp
@@ -1750,7 +1750,7 @@ JS::NonnullGCPtr<NodeIterator> Document::create_node_iterator(Node& root, unsign
}
// https://dom.spec.whatwg.org/#dom-document-createtreewalker
-NonnullRefPtr<TreeWalker> Document::create_tree_walker(Node& root, unsigned what_to_show, NodeFilter* filter)
+JS::NonnullGCPtr<TreeWalker> Document::create_tree_walker(Node& root, unsigned what_to_show, JS::GCPtr<NodeFilter> filter)
{
return TreeWalker::create(root, what_to_show, filter);
}
diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h
index 1d64a4c4fd..6222698bf3 100644
--- a/Userland/Libraries/LibWeb/DOM/Document.h
+++ b/Userland/Libraries/LibWeb/DOM/Document.h
@@ -351,7 +351,7 @@ public:
static ExceptionOr<PrefixAndTagName> validate_qualified_name(String const& qualified_name);
JS::NonnullGCPtr<NodeIterator> create_node_iterator(Node& root, unsigned what_to_show, JS::GCPtr<NodeFilter>);
- NonnullRefPtr<TreeWalker> create_tree_walker(Node& root, unsigned what_to_show, NodeFilter*);
+ JS::NonnullGCPtr<TreeWalker> create_tree_walker(Node& root, unsigned what_to_show, JS::GCPtr<NodeFilter>);
void register_node_iterator(Badge<NodeIterator>, NodeIterator&);
void unregister_node_iterator(Badge<NodeIterator>, NodeIterator&);
diff --git a/Userland/Libraries/LibWeb/DOM/TreeWalker.cpp b/Userland/Libraries/LibWeb/DOM/TreeWalker.cpp
index e63c2e67a5..88f88af449 100644
--- a/Userland/Libraries/LibWeb/DOM/TreeWalker.cpp
+++ b/Userland/Libraries/LibWeb/DOM/TreeWalker.cpp
@@ -8,6 +8,7 @@
#include <LibWeb/Bindings/IDLAbstractOperations.h>
#include <LibWeb/Bindings/NodeWrapper.h>
#include <LibWeb/Bindings/NodeWrapperFactory.h>
+#include <LibWeb/Bindings/TreeWalkerPrototype.h>
#include <LibWeb/Bindings/Wrapper.h>
#include <LibWeb/DOM/DOMException.h>
#include <LibWeb/DOM/Node.h>
@@ -17,26 +18,36 @@
namespace Web::DOM {
TreeWalker::TreeWalker(Node& root)
- : m_root(root)
+ : PlatformObject(root.document().preferred_window_object().ensure_web_prototype<Bindings::TreeWalkerPrototype>("TreeWalker"))
+ , m_root(root)
, m_current(root)
{
}
+TreeWalker::~TreeWalker() = default;
+
+void TreeWalker::visit_edges(Cell::Visitor& visitor)
+{
+ Base::visit_edges(visitor);
+ visitor.visit(m_filter.ptr());
+}
+
// https://dom.spec.whatwg.org/#dom-document-createtreewalker
-NonnullRefPtr<TreeWalker> TreeWalker::create(Node& root, unsigned what_to_show, NodeFilter* filter)
+JS::NonnullGCPtr<TreeWalker> TreeWalker::create(Node& root, unsigned what_to_show, JS::GCPtr<NodeFilter> filter)
{
// 1. Let walker be a new TreeWalker object.
// 2. Set walker’s root and walker’s current to root.
- auto walker = adopt_ref(*new TreeWalker(root));
+ auto& window_object = root.document().preferred_window_object();
+ auto* walker = window_object.heap().allocate<TreeWalker>(window_object.realm(), root);
// 3. Set walker’s whatToShow to whatToShow.
walker->m_what_to_show = what_to_show;
// 4. Set walker’s filter to filter.
- walker->m_filter = JS::make_handle(filter);
+ walker->m_filter = filter;
// 5. Return walker.
- return walker;
+ return *walker;
}
// https://dom.spec.whatwg.org/#dom-treewalker-currentnode
@@ -220,13 +231,9 @@ JS::ThrowCompletionOr<RefPtr<Node>> TreeWalker::next_node()
// https://dom.spec.whatwg.org/#concept-node-filter
JS::ThrowCompletionOr<NodeFilter::Result> TreeWalker::filter(Node& node)
{
- VERIFY(wrapper());
- auto& vm = wrapper()->vm();
- auto& realm = *vm.current_realm();
-
// 1. If traverser’s active flag is set, then throw an "InvalidStateError" DOMException.
if (m_active)
- return JS::throw_completion(wrap(realm, InvalidStateError::create("NodeIterator is already active")));
+ return JS::throw_completion(wrap(shape().realm(), InvalidStateError::create("NodeIterator is already active")));
// 2. Let n be node’s nodeType attribute value − 1.
auto n = node.node_type() - 1;
@@ -236,7 +243,7 @@ JS::ThrowCompletionOr<NodeFilter::Result> TreeWalker::filter(Node& node)
return NodeFilter::FILTER_SKIP;
// 4. If traverser’s filter is null, then return FILTER_ACCEPT.
- if (!m_filter.cell())
+ if (!m_filter)
return NodeFilter::FILTER_ACCEPT;
// 5. Set traverser’s active flag.
@@ -244,7 +251,7 @@ JS::ThrowCompletionOr<NodeFilter::Result> TreeWalker::filter(Node& node)
// 6. Let result be the return value of call a user object’s operation with traverser’s filter, "acceptNode", and « node ».
// If this throws an exception, then unset traverser’s active flag and rethrow the exception.
- auto result = Bindings::IDL::call_user_object_operation(m_filter->callback(), "acceptNode", {}, wrap(realm, node));
+ auto result = Bindings::IDL::call_user_object_operation(m_filter->callback(), "acceptNode", {}, wrap(shape().realm(), node));
if (result.is_abrupt()) {
m_active = false;
return result;
@@ -254,7 +261,7 @@ JS::ThrowCompletionOr<NodeFilter::Result> TreeWalker::filter(Node& node)
m_active = false;
// 8. Return result.
- auto result_value = TRY(result.value()->to_i32(vm));
+ auto result_value = TRY(result.value()->to_i32(vm()));
return static_cast<NodeFilter::Result>(result_value);
}
diff --git a/Userland/Libraries/LibWeb/DOM/TreeWalker.h b/Userland/Libraries/LibWeb/DOM/TreeWalker.h
index 7c4c322dce..076c6511aa 100644
--- a/Userland/Libraries/LibWeb/DOM/TreeWalker.h
+++ b/Userland/Libraries/LibWeb/DOM/TreeWalker.h
@@ -6,21 +6,21 @@
#pragma once
-#include <AK/RefCounted.h>
-#include <LibWeb/Bindings/Wrappable.h>
#include <LibWeb/DOM/NodeFilter.h>
namespace Web::DOM {
// https://dom.spec.whatwg.org/#treewalker
-class TreeWalker
- : public RefCounted<TreeWalker>
- , public Bindings::Wrappable {
+class TreeWalker final : public Bindings::PlatformObject {
+ JS_OBJECT(TreeWalker, JS::Object);
+
public:
- using WrapperType = Bindings::TreeWalkerWrapper;
+ static JS::NonnullGCPtr<TreeWalker> create(Node& root, unsigned what_to_show, JS::GCPtr<NodeFilter>);
+
+ explicit TreeWalker(Node& root);
+ virtual ~TreeWalker() override;
- static NonnullRefPtr<TreeWalker> create(Node& root, unsigned what_to_show, NodeFilter*);
- virtual ~TreeWalker() override = default;
+ TreeWalker& impl() { return *this; }
NonnullRefPtr<Node> current_node() const;
void set_current_node(Node&);
@@ -35,12 +35,12 @@ public:
NonnullRefPtr<Node> root() { return m_root; }
- NodeFilter* filter() { return m_filter.cell(); }
+ NodeFilter* filter() { return m_filter.ptr(); }
unsigned what_to_show() const { return m_what_to_show; }
private:
- TreeWalker(Node& root);
+ virtual void visit_edges(Cell::Visitor&) override;
enum class ChildTraversalType {
First,
@@ -66,10 +66,15 @@ private:
unsigned m_what_to_show { 0 };
// https://dom.spec.whatwg.org/#concept-traversal-filter
- JS::Handle<DOM::NodeFilter> m_filter;
+ JS::GCPtr<DOM::NodeFilter> m_filter;
// https://dom.spec.whatwg.org/#concept-traversal-active
bool m_active { false };
};
}
+
+namespace Web::Bindings {
+inline JS::Object* wrap(JS::Realm&, Web::DOM::TreeWalker& object) { return &object; }
+using TreeWalkerWrapper = Web::DOM::TreeWalker;
+}
diff --git a/Userland/Libraries/LibWeb/DOM/TreeWalker.idl b/Userland/Libraries/LibWeb/DOM/TreeWalker.idl
index 780f2aa1b1..d4b9e03dd3 100644
--- a/Userland/Libraries/LibWeb/DOM/TreeWalker.idl
+++ b/Userland/Libraries/LibWeb/DOM/TreeWalker.idl
@@ -1,7 +1,7 @@
#import <DOM/Node.idl>
#import <DOM/NodeFilter.idl>
-[Exposed=Window]
+[Exposed=Window, NoInstanceWrapper]
interface TreeWalker {
[SameObject] readonly attribute Node root;
diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h
index 992dbc4ab1..b9d6356790 100644
--- a/Userland/Libraries/LibWeb/Forward.h
+++ b/Userland/Libraries/LibWeb/Forward.h
@@ -604,7 +604,6 @@ class TextDecoderWrapper;
class TextEncoderWrapper;
class TextMetricsWrapper;
class TextWrapper;
-class TreeWalkerWrapper;
class UIEventWrapper;
class URLConstructor;
class URLPrototype;
diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake
index e0aa7cd047..42bc5a9ca9 100644
--- a/Userland/Libraries/LibWeb/idl_files.cmake
+++ b/Userland/Libraries/LibWeb/idl_files.cmake
@@ -49,7 +49,7 @@ libweb_js_wrapper(DOM/Range)
libweb_js_wrapper(DOM/ShadowRoot)
libweb_js_wrapper(DOM/StaticRange)
libweb_js_wrapper(DOM/Text)
-libweb_js_wrapper(DOM/TreeWalker)
+libweb_js_wrapper(DOM/TreeWalker NO_INSTANCE)
libweb_js_wrapper(DOMParsing/XMLSerializer)
libweb_js_wrapper(Encoding/TextDecoder)
libweb_js_wrapper(Encoding/TextEncoder)