From 6f433c86564c24d47d520cb5bdcc2209d724ac96 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 28 Aug 2022 13:42:07 +0200 Subject: 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. --- Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp | 39 +++++++++++------------ 1 file changed, 18 insertions(+), 21 deletions(-) (limited to 'Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp') diff --git a/Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp b/Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp index 5112681d92..19a9bb9da3 100644 --- a/Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp +++ b/Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp @@ -8,10 +8,7 @@ #include #include #include -#include -#include #include -#include #include #include #include @@ -93,8 +90,8 @@ bool EventDispatcher::inner_invoke(Event& event, Vector(global)) { - auto& bindings_window_global = verify_cast(global); + if (is(global)) { + auto& bindings_window_global = verify_cast(global); auto& window_impl = bindings_window_global.impl(); // 1. Set currentEvent to global’s current event. @@ -111,8 +108,8 @@ bool EventDispatcher::inner_invoke(Event& event, Vector(global)) { - auto& bindings_window_global = verify_cast(global); + if (is(global)) { + auto& bindings_window_global = verify_cast(global); auto& window_impl = bindings_window_global.impl(); window_impl.set_current_event(current_event); } @@ -146,17 +143,17 @@ bool EventDispatcher::inner_invoke(Event& event, Vector target, Event& event, bool legacy_target_override) +bool EventDispatcher::dispatch(JS::NonnullGCPtr target, Event& event, bool legacy_target_override) { // 1. Set event’s dispatch flag. event.set_dispatched(true); // 2. Let targetOverride be target, if legacy target override flag is not given, and target’s associated Document otherwise. [HTML] // NOTE: legacy target override flag is only used by HTML and only when target is a Window object. - RefPtr target_override; + JS::GCPtr target_override; if (!legacy_target_override) { target_override = target; } else { - target_override = verify_cast(*target).associated_document(); + target_override = &verify_cast(*target).associated_document(); } // 3. Let activationTarget be null. - RefPtr activation_target; + JS::GCPtr activation_target; // 4. Let relatedTarget be the result of retargeting event’s relatedTarget against target. - RefPtr related_target = retarget(event.related_target(), target); + JS::GCPtr related_target = retarget(event.related_target(), target); bool clear_targets = false; // 5. If target is not relatedTarget or target is event’s relatedTarget, then: @@ -285,12 +282,12 @@ bool EventDispatcher::dispatch(NonnullRefPtr target, Event& event, } // 7. Otherwise, if parent is relatedTarget, then set parent to null. - else if (related_target == parent) { + else if (related_target.ptr() == parent) { parent = nullptr; } // 8. Otherwise, set target to parent and then: else { - target = *parent; + target = parent; // 1. If isActivationEvent is true, activationTarget is null, and target has activation behavior, then set activationTarget to target. if (is_activation_event && !activation_target && target->activation_behavior) @@ -311,7 +308,7 @@ bool EventDispatcher::dispatch(NonnullRefPtr target, Event& event, // 10. Let clearTargetsStruct be the last struct in event’s path whose shadow-adjusted target is non-null. auto clear_targets_struct = event.path().last_matching([](auto& entry) { - return !entry.shadow_adjusted_target.is_null(); + return entry.shadow_adjusted_target; }); VERIFY(clear_targets_struct.has_value()); -- cgit v1.2.3