1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:07:34 +00:00

LibWeb: Make NodeList GC-allocated

This commit is contained in:
Andreas Kling 2022-09-01 16:30:26 +02:00
parent 8f4ea4e308
commit 48e0066371
16 changed files with 128 additions and 57 deletions

View file

@ -1,23 +1,39 @@
/*
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/DOM/LiveNodeList.h>
#include <LibWeb/DOM/Node.h>
#include <LibWeb/HTML/Window.h>
namespace Web::DOM {
LiveNodeList::LiveNodeList(Node& root, Function<bool(Node const&)> filter)
: m_root(JS::make_handle(root))
JS::NonnullGCPtr<NodeList> LiveNodeList::create(HTML::Window& window, Node& root, Function<bool(Node const&)> filter)
{
return *window.heap().allocate<LiveNodeList>(window.realm(), window, root, move(filter));
}
LiveNodeList::LiveNodeList(HTML::Window& window, Node& root, Function<bool(Node const&)> filter)
: NodeList(window)
, m_root(root)
, m_filter(move(filter))
{
}
LiveNodeList::~LiveNodeList() = default;
void LiveNodeList::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_root.ptr());
}
JS::MarkedVector<Node*> LiveNodeList::collection() const
{
JS::MarkedVector<Node*> nodes(m_root->heap());
JS::MarkedVector<Node*> nodes(heap());
m_root->for_each_in_inclusive_subtree([&](auto& node) {
if (m_filter(node))
nodes.append(const_cast<Node*>(&node));