LibWeb/DOM: Create NodeIterator in document's realm

This commit is contained in:
Shannon Booth 2025-01-10 15:57:42 +13:00 committed by Sam Atkins
parent 80e8313880
commit 84f22cb6b3
Notes: github-actions[bot] 2025-01-10 08:10:02 +00:00
4 changed files with 10 additions and 11 deletions

View file

@ -3336,7 +3336,7 @@ WebIDL::ExceptionOr<Document::PrefixAndTagName> Document::validate_qualified_nam
// https://dom.spec.whatwg.org/#dom-document-createnodeiterator
GC::Ref<NodeIterator> Document::create_node_iterator(Node& root, unsigned what_to_show, GC::Ptr<NodeFilter> filter)
{
return NodeIterator::create(root, what_to_show, filter).release_value_but_fixme_should_propagate_errors();
return NodeIterator::create(realm(), root, what_to_show, filter).release_value_but_fixme_should_propagate_errors();
}
// https://dom.spec.whatwg.org/#dom-document-createtreewalker

View file

@ -14,8 +14,8 @@ namespace Web::DOM {
GC_DEFINE_ALLOCATOR(NodeIterator);
NodeIterator::NodeIterator(Node& root)
: PlatformObject(root.realm())
NodeIterator::NodeIterator(JS::Realm& realm, Node& root)
: PlatformObject(realm)
, m_root(root)
, m_reference({ root })
{
@ -48,13 +48,12 @@ void NodeIterator::visit_edges(Cell::Visitor& visitor)
}
// https://dom.spec.whatwg.org/#dom-document-createnodeiterator
WebIDL::ExceptionOr<GC::Ref<NodeIterator>> NodeIterator::create(Node& root, unsigned what_to_show, GC::Ptr<NodeFilter> filter)
WebIDL::ExceptionOr<GC::Ref<NodeIterator>> NodeIterator::create(JS::Realm& realm, Node& root, unsigned what_to_show, GC::Ptr<NodeFilter> filter)
{
// 1. Let iterator be a new NodeIterator object.
// 2. Set iterators root and iterators reference to root.
// 3. Set iterators pointer before reference to true.
auto& realm = root.realm();
auto iterator = realm.create<NodeIterator>(root);
auto iterator = realm.create<NodeIterator>(realm, root);
// 4. Set iterators whatToShow to whatToShow.
iterator->m_what_to_show = what_to_show;

View file

@ -17,7 +17,7 @@ class NodeIterator final : public Bindings::PlatformObject {
GC_DECLARE_ALLOCATOR(NodeIterator);
public:
static WebIDL::ExceptionOr<GC::Ref<NodeIterator>> create(Node& root, unsigned what_to_show, GC::Ptr<NodeFilter>);
static WebIDL::ExceptionOr<GC::Ref<NodeIterator>> create(JS::Realm& realm, Node& root, unsigned what_to_show, GC::Ptr<NodeFilter>);
virtual ~NodeIterator() override;
@ -36,7 +36,7 @@ public:
void run_pre_removing_steps(Node&);
private:
explicit NodeIterator(Node& root);
explicit NodeIterator(JS::Realm&, Node& root);
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;

View file

@ -2,8 +2,8 @@ Harness status: OK
Found 33 tests
28 Pass
5 Fail
29 Pass
4 Fail
Pass querySelectorAll
Pass createElement
Pass createElementNS
@ -15,7 +15,7 @@ Pass createAttribute
Pass createAttributeNS
Pass createEvent
Pass createRange
Fail createNodeIterator
Pass createNodeIterator
Fail createTreeWalker
Pass Request
Pass Response