2021-09-02 02:12:49 +01:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
2022-09-25 16:15:49 -06:00
|
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
2021-09-02 02:12:49 +01:00
|
|
|
|
#include <LibWeb/DOM/AbortController.h>
|
|
|
|
|
#include <LibWeb/DOM/AbortSignal.h>
|
|
|
|
|
|
|
|
|
|
namespace Web::DOM {
|
|
|
|
|
|
2022-09-25 16:15:49 -06:00
|
|
|
|
JS::NonnullGCPtr<AbortController> AbortController::construct_impl(JS::Realm& realm)
|
2022-09-02 14:59:27 +02:00
|
|
|
|
{
|
2022-09-25 16:15:49 -06:00
|
|
|
|
auto signal = AbortSignal::construct_impl(realm);
|
2023-01-28 13:39:44 -05:00
|
|
|
|
return realm.heap().allocate<AbortController>(realm, realm, move(signal)).release_allocated_value_but_fixme_should_propagate_errors();
|
2022-09-02 14:59:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-02 02:12:49 +01:00
|
|
|
|
// https://dom.spec.whatwg.org/#dom-abortcontroller-abortcontroller
|
2022-09-25 16:15:49 -06:00
|
|
|
|
AbortController::AbortController(JS::Realm& realm, JS::NonnullGCPtr<AbortSignal> signal)
|
|
|
|
|
: PlatformObject(realm)
|
2022-09-02 14:59:27 +02:00
|
|
|
|
, m_signal(move(signal))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AbortController::~AbortController() = default;
|
|
|
|
|
|
2023-01-28 12:33:35 -05:00
|
|
|
|
JS::ThrowCompletionOr<void> AbortController::initialize(JS::Realm& realm)
|
2023-01-10 06:28:20 -05:00
|
|
|
|
{
|
2023-01-28 12:33:35 -05:00
|
|
|
|
MUST_OR_THROW_OOM(Base::initialize(realm));
|
2023-01-10 06:28:20 -05:00
|
|
|
|
set_prototype(&Bindings::ensure_web_prototype<Bindings::AbortControllerPrototype>(realm, "AbortController"));
|
2023-01-28 12:33:35 -05:00
|
|
|
|
|
|
|
|
|
return {};
|
2023-01-10 06:28:20 -05:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-02 14:59:27 +02:00
|
|
|
|
void AbortController::visit_edges(Cell::Visitor& visitor)
|
2021-09-02 02:12:49 +01:00
|
|
|
|
{
|
2022-09-02 14:59:27 +02:00
|
|
|
|
Base::visit_edges(visitor);
|
|
|
|
|
visitor.visit(m_signal.ptr());
|
2021-09-02 02:12:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// https://dom.spec.whatwg.org/#dom-abortcontroller-abort
|
2021-12-10 20:05:12 +00:00
|
|
|
|
void AbortController::abort(JS::Value reason)
|
2021-09-02 02:12:49 +01:00
|
|
|
|
{
|
2021-12-10 20:05:12 +00:00
|
|
|
|
// The abort(reason) method steps are to signal abort on this’s signal with reason if it is given.
|
|
|
|
|
m_signal->signal_abort(reason);
|
2021-09-02 02:12:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|