Skip to content

Commit

Permalink
LibWeb: Guard MediaQueryList event listener removal against null
Browse files Browse the repository at this point in the history
A recently imported WPT test has a subtest that effectively does the
following:

    const mql = window.matchMedia("");
    mql.removeListener(null);

(cherry picked from commit 3e5476c9e09055104fc64d294da39aa1bfccac09)
  • Loading branch information
trflynn89 authored and nico committed Nov 14, 2024
1 parent 0a9c220 commit ba539d6
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Userland/Libraries/LibWeb/CSS/MediaQueryList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,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)
Expand Down

0 comments on commit ba539d6

Please sign in to comment.