Skip to content

Commit 9b9d32d

Browse files
jamierocksawesomekling
authored andcommitted
LibWeb: Fix crash when removing event listeners
1 parent 27eb70c commit 9b9d32d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Userland/Libraries/LibWeb/DOM/EventTarget.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,16 @@ void EventTarget::remove_event_listener(FlyString const& type, RefPtr<IDLEventLi
163163

164164
// 2. If this’s event listener list contains an event listener whose type is type, callback is callback, and capture is capture,
165165
// then remove an event listener with this and that event listener.
166+
auto callbacks_match = [&](NonnullRefPtr<DOMEventListener>& entry) {
167+
if (entry->callback.is_null() && callback.is_null())
168+
return true;
169+
if (entry->callback.is_null() || callback.is_null())
170+
return false;
171+
return entry->callback->callback().callback.cell() == callback->callback().callback.cell();
172+
};
166173
auto it = m_event_listener_list.find_if([&](auto& entry) {
167174
return entry->type == type
168-
&& entry->callback->callback().callback.cell() == callback->callback().callback.cell()
175+
&& callbacks_match(entry)
169176
&& entry->capture == capture;
170177
});
171178
if (it != m_event_listener_list.end())

0 commit comments

Comments
 (0)