/src/serenity/Userland/Libraries/LibJS/Runtime/PromiseReaction.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <AK/Forward.h> |
10 | | #include <LibJS/Forward.h> |
11 | | #include <LibJS/Heap/Cell.h> |
12 | | #include <LibJS/Runtime/JobCallback.h> |
13 | | |
14 | | namespace JS { |
15 | | |
16 | | // 27.2.1.2 PromiseReaction Records, https://tc39.es/ecma262/#sec-promisereaction-records |
17 | | class PromiseReaction final : public Cell { |
18 | | JS_CELL(PromiseReaction, Cell); |
19 | | JS_DECLARE_ALLOCATOR(PromiseReaction); |
20 | | |
21 | | public: |
22 | | enum class Type { |
23 | | Fulfill, |
24 | | Reject, |
25 | | }; |
26 | | |
27 | | static NonnullGCPtr<PromiseReaction> create(VM& vm, Type type, GCPtr<PromiseCapability> capability, JS::GCPtr<JobCallback> handler); |
28 | | |
29 | | virtual ~PromiseReaction() = default; |
30 | | |
31 | 0 | Type type() const { return m_type; } |
32 | 0 | GCPtr<PromiseCapability> capability() const { return m_capability; } |
33 | | |
34 | 0 | JS::GCPtr<JobCallback> handler() { return m_handler; } |
35 | 0 | JS::GCPtr<JobCallback const> handler() const { return m_handler; } |
36 | | |
37 | | private: |
38 | | PromiseReaction(Type type, GCPtr<PromiseCapability> capability, JS::GCPtr<JobCallback> handler); |
39 | | |
40 | | virtual void visit_edges(Visitor&) override; |
41 | | |
42 | | Type m_type; |
43 | | GCPtr<PromiseCapability> m_capability; |
44 | | JS::GCPtr<JobCallback> m_handler; |
45 | | }; |
46 | | |
47 | | } |