/* * Copyright (c) 2021, Luke Wilde * Copyright (c) 2024, Tim Ledbetter * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include namespace Web::DOM { // https://dom.spec.whatwg.org/#abortsignal class AbortSignal final : public EventTarget { WEB_PLATFORM_OBJECT(AbortSignal, EventTarget); JS_DECLARE_ALLOCATOR(AbortSignal); public: static WebIDL::ExceptionOr> construct_impl(JS::Realm&); virtual ~AbortSignal() override = default; void add_abort_algorithm(Function); // https://dom.spec.whatwg.org/#dom-abortsignal-aborted // An AbortSignal object is aborted when its abort reason is not undefined. bool aborted() const { return !m_abort_reason.is_undefined(); } void signal_abort(JS::Value reason); void set_onabort(WebIDL::CallbackType*); WebIDL::CallbackType* onabort(); // https://dom.spec.whatwg.org/#dom-abortsignal-reason JS::Value reason() const { return m_abort_reason; } void set_reason(JS::Value reason) { m_abort_reason = reason; } JS::ThrowCompletionOr throw_if_aborted() const; static WebIDL::ExceptionOr> abort(JS::VM&, JS::Value reason); static WebIDL::ExceptionOr> timeout(JS::VM&, Web::WebIDL::UnsignedLongLong milliseconds); static WebIDL::ExceptionOr> any(JS::VM&, Vector> const&); static WebIDL::ExceptionOr> create_dependent_abort_signal(JS::Realm&, Vector> const&); private: explicit AbortSignal(JS::Realm&); virtual void initialize(JS::Realm&) override; virtual void visit_edges(JS::Cell::Visitor&) override; bool dependent() const { return m_dependent; } void set_dependent(bool dependent) { m_dependent = dependent; } Vector> source_signals() const { return m_source_signals; } void append_source_signal(JS::GCPtr source_signal) { m_source_signals.append(source_signal); } void append_dependent_signal(JS::GCPtr 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() }; // https://dom.spec.whatwg.org/#abortsignal-abort-algorithms // FIXME: This should be a set. Vector>> 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> 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> 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 }; }; }