mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 08:57:47 +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:
parent
bb547ce1c4
commit
6f433c8656
445 changed files with 4797 additions and 4268 deletions
|
@ -12,61 +12,60 @@ namespace Web::DOM {
|
|||
|
||||
// https://dom.spec.whatwg.org/#treewalker
|
||||
class TreeWalker final : public Bindings::PlatformObject {
|
||||
JS_OBJECT(TreeWalker, JS::Object);
|
||||
WEB_PLATFORM_OBJECT(TreeWalker, JS::Object);
|
||||
|
||||
public:
|
||||
static JS::NonnullGCPtr<TreeWalker> create(Node& root, unsigned what_to_show, JS::GCPtr<NodeFilter>);
|
||||
|
||||
explicit TreeWalker(Node& root);
|
||||
virtual ~TreeWalker() override;
|
||||
|
||||
TreeWalker& impl() { return *this; }
|
||||
|
||||
NonnullRefPtr<Node> current_node() const;
|
||||
JS::NonnullGCPtr<Node> current_node() const;
|
||||
void set_current_node(Node&);
|
||||
|
||||
JS::ThrowCompletionOr<RefPtr<Node>> parent_node();
|
||||
JS::ThrowCompletionOr<RefPtr<Node>> first_child();
|
||||
JS::ThrowCompletionOr<RefPtr<Node>> last_child();
|
||||
JS::ThrowCompletionOr<RefPtr<Node>> previous_sibling();
|
||||
JS::ThrowCompletionOr<RefPtr<Node>> next_sibling();
|
||||
JS::ThrowCompletionOr<RefPtr<Node>> previous_node();
|
||||
JS::ThrowCompletionOr<RefPtr<Node>> next_node();
|
||||
JS::ThrowCompletionOr<JS::GCPtr<Node>> parent_node();
|
||||
JS::ThrowCompletionOr<JS::GCPtr<Node>> first_child();
|
||||
JS::ThrowCompletionOr<JS::GCPtr<Node>> last_child();
|
||||
JS::ThrowCompletionOr<JS::GCPtr<Node>> previous_sibling();
|
||||
JS::ThrowCompletionOr<JS::GCPtr<Node>> next_sibling();
|
||||
JS::ThrowCompletionOr<JS::GCPtr<Node>> previous_node();
|
||||
JS::ThrowCompletionOr<JS::GCPtr<Node>> next_node();
|
||||
|
||||
NonnullRefPtr<Node> root() { return m_root; }
|
||||
JS::NonnullGCPtr<Node> root() { return m_root; }
|
||||
|
||||
NodeFilter* filter() { return m_filter.ptr(); }
|
||||
|
||||
unsigned what_to_show() const { return m_what_to_show; }
|
||||
|
||||
private:
|
||||
explicit TreeWalker(Node& root);
|
||||
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
enum class ChildTraversalType {
|
||||
First,
|
||||
Last,
|
||||
};
|
||||
JS::ThrowCompletionOr<RefPtr<Node>> traverse_children(ChildTraversalType);
|
||||
JS::ThrowCompletionOr<JS::GCPtr<Node>> traverse_children(ChildTraversalType);
|
||||
|
||||
enum class SiblingTraversalType {
|
||||
Next,
|
||||
Previous,
|
||||
};
|
||||
JS::ThrowCompletionOr<RefPtr<Node>> traverse_siblings(SiblingTraversalType);
|
||||
JS::ThrowCompletionOr<JS::GCPtr<Node>> traverse_siblings(SiblingTraversalType);
|
||||
|
||||
JS::ThrowCompletionOr<NodeFilter::Result> filter(Node&);
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-traversal-root
|
||||
NonnullRefPtr<DOM::Node> m_root;
|
||||
JS::NonnullGCPtr<Node> m_root;
|
||||
|
||||
// https://dom.spec.whatwg.org/#treewalker-current
|
||||
NonnullRefPtr<DOM::Node> m_current;
|
||||
JS::NonnullGCPtr<Node> m_current;
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-traversal-whattoshow
|
||||
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 };
|
||||
|
@ -74,7 +73,4 @@ private:
|
|||
|
||||
}
|
||||
|
||||
namespace Web::Bindings {
|
||||
inline JS::Object* wrap(JS::Realm&, Web::DOM::TreeWalker& object) { return &object; }
|
||||
using TreeWalkerWrapper = Web::DOM::TreeWalker;
|
||||
}
|
||||
WRAPPER_HACK(TreeWalker, Web::DOM)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue