diff options
author | Andreas Kling <kling@serenityos.org> | 2022-08-28 13:42:07 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-09-06 00:27:09 +0200 |
commit | 6f433c86564c24d47d520cb5bdcc2209d724ac96 (patch) | |
tree | 886a2f727782e466e99c61c628637872c1b7403f /Userland/Libraries/LibWeb/DOM/Event.cpp | |
parent | bb547ce1c4251e3689287eac845593398a379ca5 (diff) | |
download | serenity-6f433c86564c24d47d520cb5bdcc2209d724ac96.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibWeb/DOM/Event.cpp')
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Event.cpp | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Event.cpp b/Userland/Libraries/LibWeb/DOM/Event.cpp index 5ccba65e31..024fa0104f 100644 --- a/Userland/Libraries/LibWeb/DOM/Event.cpp +++ b/Userland/Libraries/LibWeb/DOM/Event.cpp @@ -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 thisโs 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: |