1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:37:36 +00:00

LibWeb: Implement AbortSignal.any()

This method takes a list of AbortSignals and returns an AbortSignal
that is aborted when any of the input signals is aborted.
This commit is contained in:
Tim Ledbetter 2024-03-10 18:50:30 +00:00 committed by Andreas Kling
parent 9eaae99da7
commit 7625d8a155
5 changed files with 198 additions and 1 deletions

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
* Copyright (c) 2024, Tim Ledbetter <timledbetter@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -46,6 +47,7 @@ public:
static WebIDL::ExceptionOr<JS::NonnullGCPtr<AbortSignal>> abort(JS::VM&, JS::Value reason);
static WebIDL::ExceptionOr<JS::NonnullGCPtr<AbortSignal>> timeout(JS::VM&, Web::WebIDL::UnsignedLongLong milliseconds);
static WebIDL::ExceptionOr<JS::NonnullGCPtr<AbortSignal>> any(JS::VM&, JS::Value signals);
private:
explicit AbortSignal(JS::Realm&);
@ -53,6 +55,16 @@ private:
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(JS::Cell::Visitor&) override;
static WebIDL::ExceptionOr<JS::NonnullGCPtr<AbortSignal>> create_dependent_abort_signal(JS::Realm&, Vector<JS::Handle<AbortSignal>> const&);
bool dependent() const { return m_dependent; }
void set_dependent(bool dependent) { m_dependent = dependent; }
Vector<JS::GCPtr<AbortSignal>> source_signals() const { return m_source_signals; }
void append_source_signal(JS::GCPtr<AbortSignal> source_signal) { m_source_signals.append(source_signal); }
void append_dependent_signal(JS::GCPtr<AbortSignal> dependent_signal) { m_dependent_signals.append(dependent_signal); }
// https://dom.spec.whatwg.org/#abortsignal-abort-reason
// An AbortSignal object has an associated abort reason, which is a JavaScript value. It is undefined unless specified otherwise.
JS::Value m_abort_reason { JS::js_undefined() };
@ -60,6 +72,18 @@ private:
// https://dom.spec.whatwg.org/#abortsignal-abort-algorithms
// FIXME: This should be a set.
Vector<JS::NonnullGCPtr<JS::HeapFunction<void()>>> m_abort_algorithms;
// https://dom.spec.whatwg.org/#abortsignal-source-signals
// An AbortSignal object has associated source signals (a weak set of AbortSignal objects that the object is dependent on for its aborted state), which is initially empty.
Vector<JS::GCPtr<AbortSignal>> m_source_signals;
// https://dom.spec.whatwg.org/#abortsignal-dependent-signals
// An AbortSignal object has associated dependent signals (a weak set of AbortSignal objects that are dependent on the object for their aborted state), which is initially empty.
Vector<JS::GCPtr<AbortSignal>> m_dependent_signals;
// https://dom.spec.whatwg.org/#abortsignal-dependent
// An AbortSignal object has a dependent (a boolean), which is initially false.
bool m_dependent { false };
};
}