2021-09-01 22:12:49 -03:00
|
|
|
|
/*
|
|
|
|
|
|
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
|
|
|
|
|
|
*
|
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2022-09-25 19:15:49 -03:00
|
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
2021-09-01 22:12:49 -03:00
|
|
|
|
#include <LibWeb/DOM/AbortController.h>
|
|
|
|
|
|
#include <LibWeb/DOM/AbortSignal.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace Web::DOM {
|
|
|
|
|
|
|
2023-02-14 16:45:54 -03:00
|
|
|
|
WebIDL::ExceptionOr<JS::NonnullGCPtr<AbortController>> AbortController::construct_impl(JS::Realm& realm)
|
2022-09-02 09:59:27 -03:00
|
|
|
|
{
|
2023-02-14 17:02:46 -03:00
|
|
|
|
auto signal = TRY(AbortSignal::construct_impl(realm));
|
2023-08-13 08:05:26 -03:00
|
|
|
|
return realm.heap().allocate<AbortController>(realm, realm, move(signal));
|
2022-09-02 09:59:27 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-09-01 22:12:49 -03:00
|
|
|
|
// https://dom.spec.whatwg.org/#dom-abortcontroller-abortcontroller
|
2022-09-25 19:15:49 -03:00
|
|
|
|
AbortController::AbortController(JS::Realm& realm, JS::NonnullGCPtr<AbortSignal> signal)
|
|
|
|
|
|
: PlatformObject(realm)
|
2022-09-02 09:59:27 -03:00
|
|
|
|
, m_signal(move(signal))
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AbortController::~AbortController() = default;
|
|
|
|
|
|
|
2023-08-07 03:41:28 -03:00
|
|
|
|
void AbortController::initialize(JS::Realm& realm)
|
2023-01-10 08:28:20 -03:00
|
|
|
|
{
|
2023-08-07 03:41:28 -03:00
|
|
|
|
Base::initialize(realm);
|
2023-01-10 08:28:20 -03:00
|
|
|
|
set_prototype(&Bindings::ensure_web_prototype<Bindings::AbortControllerPrototype>(realm, "AbortController"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-02 09:59:27 -03:00
|
|
|
|
void AbortController::visit_edges(Cell::Visitor& visitor)
|
2021-09-01 22:12:49 -03:00
|
|
|
|
{
|
2022-09-02 09:59:27 -03:00
|
|
|
|
Base::visit_edges(visitor);
|
|
|
|
|
|
visitor.visit(m_signal.ptr());
|
2021-09-01 22:12:49 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// https://dom.spec.whatwg.org/#dom-abortcontroller-abort
|
2021-12-10 17:05:12 -03:00
|
|
|
|
void AbortController::abort(JS::Value reason)
|
2021-09-01 22:12:49 -03:00
|
|
|
|
{
|
2021-12-10 17:05:12 -03: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-01 22:12:49 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|