LibWeb: Guard MediaQueryList event listener removal against null

A recently imported WPT test has a subtest that effectively does the
following:

    const mql = window.matchMedia("");
    mql.removeListener(null);
This commit is contained in:
Timothy Flynn 2024-11-13 08:19:53 -05:00 committed by Andreas Kling
parent 213155ad7d
commit 3e5476c9e0
Notes: github-actions[bot] 2024-11-13 14:00:10 +00:00

View file

@ -99,7 +99,8 @@ void MediaQueryList::remove_listener(JS::GCPtr<DOM::IDLEventListener> listener)
// 1. Remove an event listener from the associated list of event listeners, whose type is change, callback is listener, and capture is false.
// NOTE: While the spec doesn't technically use remove_event_listener and instead manipulates the list directly, every major engine uses remove_event_listener.
// This means if an event listener removes another event listener that comes after it, the removed event listener will not be invoked.
remove_event_listener_without_options(HTML::EventNames::change, *listener);
if (listener)
remove_event_listener_without_options(HTML::EventNames::change, *listener);
}
void MediaQueryList::set_onchange(WebIDL::CallbackType* event_handler)