mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:27:44 +00:00
LibWeb: Convert DOM::AbortSignal to use JS::SafeFunction
This protects the captured GC pointers automatically instead of manually.
This commit is contained in:
parent
67e396d931
commit
07e3bb729d
3 changed files with 6 additions and 5 deletions
|
@ -24,7 +24,7 @@ AbortSignal::AbortSignal(JS::Realm& realm)
|
|||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#abortsignal-add
|
||||
void AbortSignal::add_abort_algorithm(Function<void()> abort_algorithm)
|
||||
void AbortSignal::add_abort_algorithm(JS::SafeFunction<void()> abort_algorithm)
|
||||
{
|
||||
// 1. If signal is aborted, then return.
|
||||
if (aborted())
|
||||
|
|
|
@ -22,7 +22,7 @@ public:
|
|||
|
||||
virtual ~AbortSignal() override = default;
|
||||
|
||||
void add_abort_algorithm(Function<void()>);
|
||||
void add_abort_algorithm(JS::SafeFunction<void()>);
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-abortsignal-aborted
|
||||
// An AbortSignal object is aborted when its abort reason is not undefined.
|
||||
|
@ -49,7 +49,7 @@ private:
|
|||
|
||||
// https://dom.spec.whatwg.org/#abortsignal-abort-algorithms
|
||||
// FIXME: This should be a set.
|
||||
Vector<Function<void()>> m_abort_algorithms;
|
||||
Vector<JS::SafeFunction<void()>> m_abort_algorithms;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -170,9 +170,10 @@ void EventTarget::add_an_event_listener(DOMEventListener& listener)
|
|||
|
||||
// 5. If listener’s signal is not null, then add the following abort steps to it:
|
||||
if (listener.signal) {
|
||||
listener.signal->add_abort_algorithm([strong_event_target = JS::make_handle(*this), listener = JS::make_handle(&listener)]() mutable {
|
||||
// NOTE: `this` and `listener` are protected by AbortSignal using JS::SafeFunction.
|
||||
listener.signal->add_abort_algorithm([this, &listener]() mutable {
|
||||
// 1. Remove an event listener with eventTarget and listener.
|
||||
strong_event_target->remove_an_event_listener(*listener);
|
||||
remove_an_event_listener(listener);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue