2021-09-01 22:12:49 -03:00
|
|
|
|
/*
|
|
|
|
|
|
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
|
|
|
|
|
|
*
|
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2026-04-18 05:54:06 -03:00
|
|
|
|
#include <LibWeb/Bindings/AbortController.h>
|
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 {
|
|
|
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
|
GC_DEFINE_ALLOCATOR(AbortController);
|
2023-11-19 15:47:52 -03:00
|
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
|
WebIDL::ExceptionOr<GC::Ref<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));
|
2024-11-13 13:50:17 -03:00
|
|
|
|
return realm.create<AbortController>(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
|
2024-11-14 12:01:23 -03:00
|
|
|
|
AbortController::AbortController(JS::Realm& realm, GC::Ref<AbortSignal> signal)
|
2022-09-25 19:15:49 -03:00
|
|
|
|
: 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
|
|
|
|
{
|
2024-03-16 09:13:08 -03:00
|
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(AbortController);
|
2025-04-20 11:22:57 -03:00
|
|
|
|
Base::initialize(realm);
|
2023-01-10 08:28:20 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
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);
|
2023-11-19 00:18:00 -03:00
|
|
|
|
visitor.visit(m_signal);
|
2021-09-01 22:12:49 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// https://dom.spec.whatwg.org/#dom-abortcontroller-abort
|
2026-05-20 15:58:46 -03:00
|
|
|
|
void AbortController::abort(Optional<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.
|
2026-05-20 15:58:46 -03:00
|
|
|
|
m_signal->signal_abort(reason.value_or(JS::js_undefined()));
|
2021-09-01 22:12:49 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|