mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
LibWeb: Update handling of "once" event listeners now that spec is fixed
https://github.com/whatwg/dom/issues/1323 was fixed, and the solution ended up slightly different from what we had, so let's follow the spec.
This commit is contained in:
committed by
Andreas Kling
parent
9f541c363d
commit
e28e4f6700
@@ -56,9 +56,9 @@ bool EventDispatcher::inner_invoke(Event& event, Vector<GC::Root<DOM::DOMEventLi
|
|||||||
if (phase == Event::Phase::BubblingPhase && listener->capture)
|
if (phase == Event::Phase::BubblingPhase && listener->capture)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// 5. If listener’s once is true, then remove listener from event’s currentTarget attribute value’s event listener list.
|
// 5. If listener’s once is true, then remove an event listener given event’s currentTarget attribute value and listener.
|
||||||
if (listener->once)
|
if (listener->once)
|
||||||
event.current_target()->remove_from_event_listener_list(*listener);
|
event.current_target()->remove_an_event_listener(*listener);
|
||||||
|
|
||||||
// 6. Let global be listener callback’s associated Realm’s global object.
|
// 6. Let global be listener callback’s associated Realm’s global object.
|
||||||
auto& callback = listener->callback->callback();
|
auto& callback = listener->callback->callback();
|
||||||
|
|||||||
@@ -249,17 +249,6 @@ void EventTarget::remove_an_event_listener(DOMEventListener& listener)
|
|||||||
m_data->event_listener_list.remove_first_matching([&](auto& entry) { return entry.ptr() == &listener; });
|
m_data->event_listener_list.remove_first_matching([&](auto& entry) { return entry.ptr() == &listener; });
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventTarget::remove_from_event_listener_list(DOMEventListener& listener)
|
|
||||||
{
|
|
||||||
if (!m_data)
|
|
||||||
return;
|
|
||||||
m_data->event_listener_list.remove_first_matching([&](auto& entry) { return entry.ptr() == &listener; });
|
|
||||||
|
|
||||||
// FIXME: Update this when the spec is updated.
|
|
||||||
// Spec bug: https://github.com/whatwg/dom/issues/1323
|
|
||||||
listener.removed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-eventtarget-dispatchevent
|
// https://dom.spec.whatwg.org/#dom-eventtarget-dispatchevent
|
||||||
WebIDL::ExceptionOr<bool> EventTarget::dispatch_event_binding(Event& event)
|
WebIDL::ExceptionOr<bool> EventTarget::dispatch_event_binding(Event& event)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ public:
|
|||||||
|
|
||||||
void add_an_event_listener(DOMEventListener&);
|
void add_an_event_listener(DOMEventListener&);
|
||||||
void remove_an_event_listener(DOMEventListener&);
|
void remove_an_event_listener(DOMEventListener&);
|
||||||
void remove_from_event_listener_list(DOMEventListener&);
|
|
||||||
|
|
||||||
Vector<GC::Root<DOMEventListener>> event_listener_list();
|
Vector<GC::Root<DOMEventListener>> event_listener_list();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user