1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 20: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

@ -8,8 +8,8 @@
#include <AK/FlyString.h>
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/Bindings/WindowObject.h>
#include <LibWeb/DOM/EventTarget.h>
#include <LibWeb/HTML/Window.h>
namespace Web::DOM {
@ -20,7 +20,7 @@ struct EventInit {
};
class Event : public Bindings::PlatformObject {
JS_OBJECT(Event, Bindings::PlatformObject);
WEB_PLATFORM_OBJECT(Event, Bindings::PlatformObject);
public:
enum Phase : u16 {
@ -30,13 +30,14 @@ public:
BubblingPhase = 3,
};
using TouchTargetList = Vector<RefPtr<EventTarget>>;
// FIXME: These need explicit marking somehow.
using TouchTargetList = Vector<JS::GCPtr<EventTarget>>;
struct PathEntry {
RefPtr<EventTarget> invocation_target;
JS::GCPtr<EventTarget> invocation_target;
bool invocation_target_in_shadow_tree { false };
RefPtr<EventTarget> shadow_adjusted_target;
RefPtr<EventTarget> related_target;
JS::GCPtr<EventTarget> shadow_adjusted_target;
JS::GCPtr<EventTarget> related_target;
TouchTargetList touch_target_list;
bool root_of_closed_tree { false };
bool slot_in_closed_tree { false };
@ -45,28 +46,26 @@ public:
using Path = Vector<PathEntry>;
static JS::NonnullGCPtr<Event> create(Bindings::WindowObject&, FlyString const& event_name, EventInit const& event_init = {});
static JS::NonnullGCPtr<Event> create_with_global_object(Bindings::WindowObject&, FlyString const& event_name, EventInit const& event_init);
static JS::NonnullGCPtr<Event> create(HTML::Window&, FlyString const& event_name, EventInit const& event_init = {});
static JS::NonnullGCPtr<Event> create_with_global_object(HTML::Window&, FlyString const& event_name, EventInit const& event_init);
Event(Bindings::WindowObject&, FlyString const& type);
Event(Bindings::WindowObject&, FlyString const& type, EventInit const& event_init);
Event(HTML::Window&, FlyString const& type);
Event(HTML::Window&, FlyString const& type, EventInit const& event_init);
virtual ~Event() = default;
Event& impl() { return *this; }
double time_stamp() const;
FlyString const& type() const { return m_type; }
void set_type(StringView type) { m_type = type; }
RefPtr<EventTarget> target() const { return m_target; }
JS::GCPtr<EventTarget> target() const { return m_target; }
void set_target(EventTarget* target) { m_target = target; }
// NOTE: This is intended for the JS bindings.
RefPtr<EventTarget> src_element() const { return target(); }
JS::GCPtr<EventTarget> src_element() const { return target(); }
RefPtr<EventTarget> related_target() const { return m_related_target; }
JS::GCPtr<EventTarget> related_target() const { return m_related_target; }
void set_related_target(EventTarget* related_target) { m_related_target = related_target; }
bool should_stop_propagation() const { return m_stop_propagation; }
@ -96,7 +95,7 @@ public:
u16 event_phase() const { return m_phase; }
void set_phase(Phase phase) { m_phase = phase; }
RefPtr<EventTarget> current_target() const { return m_current_target; }
JS::GCPtr<EventTarget> current_target() const { return m_current_target; }
void set_current_target(EventTarget* current_target) { m_current_target = current_target; }
bool return_value() const { return !m_cancelled; }
@ -106,7 +105,7 @@ public:
set_cancelled_flag();
}
void append_to_path(EventTarget&, RefPtr<EventTarget>, RefPtr<EventTarget>, TouchTargetList&, bool);
void append_to_path(EventTarget&, JS::GCPtr<EventTarget>, JS::GCPtr<EventTarget>, TouchTargetList&, bool);
Path& path() { return m_path; }
Path const& path() const { return m_path; }
void clear_path() { m_path.clear(); }
@ -143,16 +142,16 @@ public:
void set_time_stamp(double time_stamp) { m_time_stamp = time_stamp; }
NonnullRefPtrVector<EventTarget> composed_path() const;
Vector<JS::Handle<EventTarget>> composed_path() const;
protected:
void initialize_event(String const&, bool, bool);
private:
FlyString m_type;
RefPtr<EventTarget> m_target;
RefPtr<EventTarget> m_related_target;
RefPtr<EventTarget> m_current_target;
JS::GCPtr<EventTarget> m_target;
JS::GCPtr<EventTarget> m_related_target;
JS::GCPtr<EventTarget> m_current_target;
Phase m_phase { None };
@ -179,7 +178,4 @@ private:
}
namespace Web::Bindings {
inline JS::Object* wrap(JS::Realm&, Web::DOM::Event& object) { return &object; }
using EventWrapper = Web::DOM::Event;
}
WRAPPER_HACK(Event, Web::DOM)