summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/DOM/EventTarget.cpp
diff options
context:
space:
mode:
authorJamie Mansfield <jmansfield@cadixdev.org>2022-03-20 20:17:57 +0000
committerAndreas Kling <kling@serenityos.org>2022-03-22 02:35:07 +0100
commit9b9d32dfb2a0ef5b8972a09489bc451fafbda390 (patch)
tree499941e67e494ad33c445d4d21c41d1af6601dfc /Userland/Libraries/LibWeb/DOM/EventTarget.cpp
parent27eb70cbba9269ada769a0ea94dd2fe688504c3f (diff)
downloadserenity-9b9d32dfb2a0ef5b8972a09489bc451fafbda390.zip
LibWeb: Fix crash when removing event listeners
Diffstat (limited to 'Userland/Libraries/LibWeb/DOM/EventTarget.cpp')
-rw-r--r--Userland/Libraries/LibWeb/DOM/EventTarget.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/EventTarget.cpp b/Userland/Libraries/LibWeb/DOM/EventTarget.cpp
index 021a5d7199..2a2e113a03 100644
--- a/Userland/Libraries/LibWeb/DOM/EventTarget.cpp
+++ b/Userland/Libraries/LibWeb/DOM/EventTarget.cpp
@@ -163,9 +163,16 @@ void EventTarget::remove_event_listener(FlyString const& type, RefPtr<IDLEventLi
// 2. If thisโ€™s event listener list contains an event listener whose type is type, callback is callback, and capture is capture,
// then remove an event listener with this and that event listener.
+ auto callbacks_match = [&](NonnullRefPtr<DOMEventListener>& entry) {
+ if (entry->callback.is_null() && callback.is_null())
+ return true;
+ if (entry->callback.is_null() || callback.is_null())
+ return false;
+ return entry->callback->callback().callback.cell() == callback->callback().callback.cell();
+ };
auto it = m_event_listener_list.find_if([&](auto& entry) {
return entry->type == type
- && entry->callback->callback().callback.cell() == callback->callback().callback.cell()
+ && callbacks_match(entry)
&& entry->capture == capture;
});
if (it != m_event_listener_list.end())