summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/PromiseReaction.h
blob: def919763752c79a6e881d52dabc20519c01bbe6 (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
/*
 * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/Forward.h>
#include <LibJS/Forward.h>
#include <LibJS/Heap/Cell.h>
#include <LibJS/Runtime/JobCallback.h>

namespace JS {

// 27.2.1.2 PromiseReaction Records, https://tc39.es/ecma262/#sec-promisereaction-records
class PromiseReaction final : public Cell {
    JS_CELL(PromiseReaction, Cell);

public:
    enum class Type {
        Fulfill,
        Reject,
    };

    static NonnullGCPtr<PromiseReaction> create(VM& vm, Type type, GCPtr<PromiseCapability> capability, Optional<JobCallback> handler);

    virtual ~PromiseReaction() = default;

    Type type() const { return m_type; }
    GCPtr<PromiseCapability> capability() const { return m_capability; }

    Optional<JobCallback>& handler() { return m_handler; }
    Optional<JobCallback> const& handler() const { return m_handler; }

private:
    PromiseReaction(Type type, GCPtr<PromiseCapability> capability, Optional<JobCallback> handler);

    virtual void visit_edges(Visitor&) override;

    Type m_type;
    GCPtr<PromiseCapability> m_capability;
    Optional<JobCallback> m_handler;
};

}