1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:27:45 +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

@ -8,31 +8,31 @@
#include <AK/TypeCasts.h>
#include <LibWeb/Bindings/EventPrototype.h>
#include <LibWeb/Bindings/WindowObject.h>
#include <LibWeb/DOM/Event.h>
#include <LibWeb/DOM/Node.h>
#include <LibWeb/DOM/ShadowRoot.h>
#include <LibWeb/HTML/Window.h>
namespace Web::DOM {
JS::NonnullGCPtr<Event> Event::create(Bindings::WindowObject& window_object, FlyString const& event_name, EventInit const& event_init)
JS::NonnullGCPtr<Event> Event::create(HTML::Window& window_object, FlyString const& event_name, EventInit const& event_init)
{
return *window_object.heap().allocate<Event>(window_object.realm(), window_object, event_name, event_init);
}
JS::NonnullGCPtr<Event> Event::create_with_global_object(Bindings::WindowObject& window_object, FlyString const& event_name, EventInit const& event_init)
JS::NonnullGCPtr<Event> Event::create_with_global_object(HTML::Window& window_object, FlyString const& event_name, EventInit const& event_init)
{
return create(window_object, event_name, event_init);
}
Event::Event(Bindings::WindowObject& window_object, FlyString const& type)
Event::Event(HTML::Window& window_object, FlyString const& type)
: PlatformObject(window_object.ensure_web_prototype<Bindings::EventPrototype>("Event"))
, m_type(type)
, m_initialized(true)
{
}
Event::Event(Bindings::WindowObject& window_object, FlyString const& type, EventInit const& event_init)
Event::Event(HTML::Window& window_object, FlyString const& type, EventInit const& event_init)
: PlatformObject(window_object.ensure_web_prototype<Bindings::EventPrototype>("Event"))
, m_type(type)
, m_bubbles(event_init.bubbles)
@ -43,7 +43,7 @@ Event::Event(Bindings::WindowObject& window_object, FlyString const& type, Event
}
// https://dom.spec.whatwg.org/#concept-event-path-append
void Event::append_to_path(EventTarget& invocation_target, RefPtr<EventTarget> shadow_adjusted_target, RefPtr<EventTarget> related_target, TouchTargetList& touch_targets, bool slot_in_closed_tree)
void Event::append_to_path(EventTarget& invocation_target, JS::GCPtr<EventTarget> shadow_adjusted_target, JS::GCPtr<EventTarget> related_target, TouchTargetList& touch_targets, bool slot_in_closed_tree)
{
// 1. Let invocationTargetInShadowTree be false.
bool invocation_target_in_shadow_tree = false;
@ -120,10 +120,10 @@ double Event::time_stamp() const
}
// https://dom.spec.whatwg.org/#dom-event-composedpath
NonnullRefPtrVector<EventTarget> Event::composed_path() const
Vector<JS::Handle<EventTarget>> Event::composed_path() const
{
// 1. Let composedPath be an empty list.
NonnullRefPtrVector<EventTarget> composed_path;
Vector<JS::Handle<EventTarget>> composed_path;
// 2. Let path be thiss path. (NOTE: Not necessary)
@ -136,7 +136,7 @@ NonnullRefPtrVector<EventTarget> Event::composed_path() const
// 5. Append currentTarget to composedPath.
// NOTE: If path is not empty, then the event is being dispatched and will have a currentTarget.
VERIFY(m_current_target);
composed_path.append(*m_current_target);
composed_path.append(const_cast<EventTarget*>(m_current_target.ptr()));
// 6. Let currentTargetIndex be 0.
size_t current_target_index = 0;
@ -182,7 +182,7 @@ NonnullRefPtrVector<EventTarget> Event::composed_path() const
// 2. If currentHiddenLevel is less than or equal to maxHiddenLevel, then prepend path[index]'s invocation target to composedPath.
if (current_hidden_level <= max_hidden_level) {
VERIFY(path_entry.invocation_target);
composed_path.prepend(*path_entry.invocation_target);
composed_path.prepend(const_cast<EventTarget*>(path_entry.invocation_target.ptr()));
}
// 3. If path[index]'s slot-in-closed-tree is true, then:
@ -214,7 +214,7 @@ NonnullRefPtrVector<EventTarget> Event::composed_path() const
// 2. If currentHiddenLevel is less than or equal to maxHiddenLevel, then append path[index]'s invocation target to composedPath.
if (current_hidden_level <= max_hidden_level) {
VERIFY(path_entry.invocation_target);
composed_path.append(*path_entry.invocation_target);
composed_path.append(const_cast<EventTarget*>(path_entry.invocation_target.ptr()));
}
// 3. If path[index]'s root-of-closed-tree is true, then: