summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/DOM/AbortSignal.cpp
blob: 9f7bcecdd32b1e0a77ffab9eb830f210e64295dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 * Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <LibWeb/Bindings/AbortSignalWrapper.h>
#include <LibWeb/DOM/AbortSignal.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/EventDispatcher.h>

namespace Web::DOM {

AbortSignal::AbortSignal(Document& document)
    : EventTarget(static_cast<Bindings::ScriptExecutionContext&>(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<void()> 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));
}

}