mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 09:57:34 +00:00
LibWeb: Use JS::HeapFunction for AbortSignal callback
This commit is contained in:
parent
baf37af09c
commit
67aa86b5b6
2 changed files with 8 additions and 5 deletions
|
@ -29,14 +29,14 @@ void AbortSignal::initialize(JS::Realm& realm)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#abortsignal-add
|
// https://dom.spec.whatwg.org/#abortsignal-add
|
||||||
void AbortSignal::add_abort_algorithm(JS::SafeFunction<void()> abort_algorithm)
|
void AbortSignal::add_abort_algorithm(Function<void()> abort_algorithm)
|
||||||
{
|
{
|
||||||
// 1. If signal is aborted, then return.
|
// 1. If signal is aborted, then return.
|
||||||
if (aborted())
|
if (aborted())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// 2. Append algorithm to signal’s abort algorithms.
|
// 2. Append algorithm to signal’s abort algorithms.
|
||||||
m_abort_algorithms.append(move(abort_algorithm));
|
m_abort_algorithms.append(JS::create_heap_function(vm().heap(), move(abort_algorithm)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#abortsignal-signal-abort
|
// https://dom.spec.whatwg.org/#abortsignal-signal-abort
|
||||||
|
@ -54,7 +54,7 @@ void AbortSignal::signal_abort(JS::Value reason)
|
||||||
|
|
||||||
// 3. For each algorithm in signal’s abort algorithms: run algorithm.
|
// 3. For each algorithm in signal’s abort algorithms: run algorithm.
|
||||||
for (auto& algorithm : m_abort_algorithms)
|
for (auto& algorithm : m_abort_algorithms)
|
||||||
algorithm();
|
algorithm->function()();
|
||||||
|
|
||||||
// 4. Empty signal’s abort algorithms.
|
// 4. Empty signal’s abort algorithms.
|
||||||
m_abort_algorithms.clear();
|
m_abort_algorithms.clear();
|
||||||
|
@ -87,6 +87,8 @@ void AbortSignal::visit_edges(JS::Cell::Visitor& visitor)
|
||||||
{
|
{
|
||||||
Base::visit_edges(visitor);
|
Base::visit_edges(visitor);
|
||||||
visitor.visit(m_abort_reason);
|
visitor.visit(m_abort_reason);
|
||||||
|
for (auto& algorithm : m_abort_algorithms)
|
||||||
|
visitor.visit(algorithm);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#abortsignal-follow
|
// https://dom.spec.whatwg.org/#abortsignal-follow
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include <AK/RefCounted.h>
|
#include <AK/RefCounted.h>
|
||||||
#include <AK/Weakable.h>
|
#include <AK/Weakable.h>
|
||||||
|
#include <LibJS/Heap/HeapFunction.h>
|
||||||
#include <LibWeb/DOM/EventTarget.h>
|
#include <LibWeb/DOM/EventTarget.h>
|
||||||
#include <LibWeb/Forward.h>
|
#include <LibWeb/Forward.h>
|
||||||
|
|
||||||
|
@ -22,7 +23,7 @@ public:
|
||||||
|
|
||||||
virtual ~AbortSignal() override = default;
|
virtual ~AbortSignal() override = default;
|
||||||
|
|
||||||
void add_abort_algorithm(JS::SafeFunction<void()>);
|
void add_abort_algorithm(Function<void()>);
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-abortsignal-aborted
|
// https://dom.spec.whatwg.org/#dom-abortsignal-aborted
|
||||||
// An AbortSignal object is aborted when its abort reason is not undefined.
|
// An AbortSignal object is aborted when its abort reason is not undefined.
|
||||||
|
@ -52,7 +53,7 @@ private:
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#abortsignal-abort-algorithms
|
// https://dom.spec.whatwg.org/#abortsignal-abort-algorithms
|
||||||
// FIXME: This should be a set.
|
// FIXME: This should be a set.
|
||||||
Vector<JS::SafeFunction<void()>> m_abort_algorithms;
|
Vector<JS::NonnullGCPtr<JS::HeapFunction<void()>>> m_abort_algorithms;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue