2021-09-02 02:12:49 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/RefCounted.h>
|
|
|
|
|
#include <AK/Weakable.h>
|
2023-09-25 18:45:20 +02:00
|
|
|
#include <LibJS/Heap/HeapFunction.h>
|
2021-09-02 02:12:49 +01:00
|
|
|
#include <LibWeb/DOM/EventTarget.h>
|
|
|
|
|
#include <LibWeb/Forward.h>
|
|
|
|
|
|
|
|
|
|
namespace Web::DOM {
|
|
|
|
|
|
|
|
|
|
// https://dom.spec.whatwg.org/#abortsignal
|
2022-08-28 13:42:07 +02:00
|
|
|
class AbortSignal final : public EventTarget {
|
|
|
|
|
WEB_PLATFORM_OBJECT(AbortSignal, EventTarget);
|
2023-11-19 19:47:52 +01:00
|
|
|
JS_DECLARE_ALLOCATOR(AbortSignal);
|
2021-09-02 02:12:49 +01:00
|
|
|
|
2022-08-28 13:42:07 +02:00
|
|
|
public:
|
2023-02-14 21:02:46 +01:00
|
|
|
static WebIDL::ExceptionOr<JS::NonnullGCPtr<AbortSignal>> construct_impl(JS::Realm&);
|
2021-09-02 02:12:49 +01:00
|
|
|
|
2022-03-14 13:21:51 -06:00
|
|
|
virtual ~AbortSignal() override = default;
|
2021-09-02 02:12:49 +01:00
|
|
|
|
2023-09-25 18:45:20 +02:00
|
|
|
void add_abort_algorithm(Function<void()>);
|
2021-09-02 02:12:49 +01:00
|
|
|
|
|
|
|
|
// https://dom.spec.whatwg.org/#dom-abortsignal-aborted
|
2021-12-10 20:05:12 +00:00
|
|
|
// An AbortSignal object is aborted when its abort reason is not undefined.
|
|
|
|
|
bool aborted() const { return !m_abort_reason.is_undefined(); }
|
2021-09-02 02:12:49 +01:00
|
|
|
|
2021-12-10 20:05:12 +00:00
|
|
|
void signal_abort(JS::Value reason);
|
2021-09-02 02:12:49 +01:00
|
|
|
|
2022-09-24 16:02:41 +01:00
|
|
|
void set_onabort(WebIDL::CallbackType*);
|
|
|
|
|
WebIDL::CallbackType* onabort();
|
2021-10-01 01:09:11 +01:00
|
|
|
|
2021-12-10 20:05:12 +00:00
|
|
|
// https://dom.spec.whatwg.org/#dom-abortsignal-reason
|
|
|
|
|
JS::Value reason() const { return m_abort_reason; }
|
|
|
|
|
|
2021-12-10 19:48:51 +00:00
|
|
|
JS::ThrowCompletionOr<void> throw_if_aborted() const;
|
|
|
|
|
|
2022-10-26 18:15:46 +01:00
|
|
|
void follow(JS::NonnullGCPtr<AbortSignal> parent_signal);
|
|
|
|
|
|
2021-09-02 02:12:49 +01:00
|
|
|
private:
|
2022-09-25 16:15:49 -06:00
|
|
|
explicit AbortSignal(JS::Realm&);
|
2022-08-28 13:42:07 +02:00
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2022-08-28 13:42:07 +02:00
|
|
|
virtual void visit_edges(JS::Cell::Visitor&) override;
|
2021-09-02 02:12:49 +01:00
|
|
|
|
2021-12-10 20:05:12 +00:00
|
|
|
// 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() };
|
2021-09-02 02:12:49 +01:00
|
|
|
|
|
|
|
|
// https://dom.spec.whatwg.org/#abortsignal-abort-algorithms
|
|
|
|
|
// FIXME: This should be a set.
|
2023-09-25 18:45:20 +02:00
|
|
|
Vector<JS::NonnullGCPtr<JS::HeapFunction<void()>>> m_abort_algorithms;
|
2021-09-02 02:12:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|