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

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.
This commit is contained in:
Andreas Kling 2022-08-28 13:42:07 +02:00
parent bb547ce1c4
commit 6f433c8656
445 changed files with 4797 additions and 4268 deletions

View file

@ -13,31 +13,30 @@ namespace Web::DOM {
// https://dom.spec.whatwg.org/#nodeiterator
class NodeIterator final : public Bindings::PlatformObject {
JS_OBJECT(NodeIterator, Bindings::PlatformObject);
WEB_PLATFORM_OBJECT(NodeIterator, Bindings::PlatformObject);
public:
static JS::NonnullGCPtr<NodeIterator> create(Node& root, unsigned what_to_show, JS::GCPtr<NodeFilter>);
NodeIterator(Node& root);
virtual ~NodeIterator() override;
NodeIterator& impl() { return *this; }
NonnullRefPtr<Node> root() { return m_root; }
NonnullRefPtr<Node> reference_node() { return m_reference.node; }
JS::NonnullGCPtr<Node> root() { return m_root; }
JS::NonnullGCPtr<Node> reference_node() { return m_reference.node; }
bool pointer_before_reference_node() const { return m_reference.is_before_node; }
unsigned what_to_show() const { return m_what_to_show; }
NodeFilter* filter() { return m_filter.ptr(); }
JS::ThrowCompletionOr<RefPtr<Node>> next_node();
JS::ThrowCompletionOr<RefPtr<Node>> previous_node();
JS::ThrowCompletionOr<JS::GCPtr<Node>> next_node();
JS::ThrowCompletionOr<JS::GCPtr<Node>> previous_node();
void detach();
void run_pre_removing_steps(Node&);
private:
explicit NodeIterator(Node& root);
virtual void visit_edges(Cell::Visitor&) override;
enum class Direction {
@ -45,15 +44,15 @@ private:
Previous,
};
JS::ThrowCompletionOr<RefPtr<Node>> traverse(Direction);
JS::ThrowCompletionOr<JS::GCPtr<Node>> traverse(Direction);
JS::ThrowCompletionOr<NodeFilter::Result> filter(Node&);
// https://dom.spec.whatwg.org/#concept-traversal-root
NonnullRefPtr<DOM::Node> m_root;
JS::NonnullGCPtr<Node> m_root;
struct NodePointer {
NonnullRefPtr<DOM::Node> node;
JS::NonnullGCPtr<Node> node;
// https://dom.spec.whatwg.org/#nodeiterator-pointer-before-reference
bool is_before_node { true };
@ -72,7 +71,7 @@ private:
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 };
@ -80,7 +79,4 @@ private:
}
namespace Web::Bindings {
inline JS::Object* wrap(JS::Realm&, Web::DOM::NodeIterator& object) { return &object; }
using NodeIteratorWrapper = Web::DOM::NodeIterator;
}
WRAPPER_HACK(NodeIterator, Web::DOM)