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
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

@ -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;