/* * Copyright (c) 2021, Luke Wilde * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include namespace Web::DOM { AbortSignal::AbortSignal(Document& document) : EventTarget(static_cast(document)) { } AbortSignal::~AbortSignal() { } JS::Object* AbortSignal::create_wrapper(JS::GlobalObject& global_object) { return wrap(global_object, *this); } // https://dom.spec.whatwg.org/#abortsignal-add void AbortSignal::add_abort_algorithm(Function abort_algorithm) { if (m_aborted) return; m_abort_algorithms.append(move(abort_algorithm)); } // https://dom.spec.whatwg.org/#abortsignal-signal-abort void AbortSignal::signal_abort() { if (m_aborted) return; m_aborted = true; for (auto& algorithm : m_abort_algorithms) algorithm(); m_abort_algorithms.clear(); dispatch_event(Event::create(HTML::EventNames::abort)); } }