2021-09-02 02:12:49 +01:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <LibWeb/DOM/AbortController.h>
|
|
|
|
|
#include <LibWeb/DOM/AbortSignal.h>
|
|
|
|
|
|
|
|
|
|
namespace Web::DOM {
|
|
|
|
|
|
2022-09-02 14:59:27 +02:00
|
|
|
|
JS::NonnullGCPtr<AbortController> AbortController::create_with_global_object(HTML::Window& window)
|
|
|
|
|
{
|
|
|
|
|
auto signal = AbortSignal::create_with_global_object(window);
|
|
|
|
|
return *window.heap().allocate<AbortController>(window.realm(), window, move(signal));
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-02 02:12:49 +01:00
|
|
|
|
// https://dom.spec.whatwg.org/#dom-abortcontroller-abortcontroller
|
2022-09-02 14:59:27 +02:00
|
|
|
|
AbortController::AbortController(HTML::Window& window, JS::NonnullGCPtr<AbortSignal> signal)
|
|
|
|
|
: PlatformObject(window.realm())
|
|
|
|
|
, m_signal(move(signal))
|
|
|
|
|
{
|
2022-09-03 18:43:24 +02:00
|
|
|
|
set_prototype(&window.cached_web_prototype("AbortController"));
|
2022-09-02 14:59:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AbortController::~AbortController() = default;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|