/src/serenity/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <LibJS/Bytecode/Interpreter.h> |
10 | | #include <LibJS/Runtime/ECMAScriptFunctionObject.h> |
11 | | #include <LibJS/Runtime/GeneratorObject.h> |
12 | | #include <LibJS/Runtime/Object.h> |
13 | | #include <LibJS/Runtime/Promise.h> |
14 | | |
15 | | namespace JS { |
16 | | |
17 | | class AsyncFunctionDriverWrapper final : public Promise { |
18 | | JS_OBJECT(AsyncFunctionDriverWrapper, Promise); |
19 | | JS_DECLARE_ALLOCATOR(AsyncFunctionDriverWrapper); |
20 | | |
21 | | public: |
22 | | enum class IsInitialExecution { |
23 | | No, |
24 | | Yes, |
25 | | }; |
26 | | |
27 | | [[nodiscard]] static NonnullGCPtr<Promise> create(Realm&, GeneratorObject*); |
28 | | |
29 | 0 | virtual ~AsyncFunctionDriverWrapper() override = default; |
30 | | void visit_edges(Cell::Visitor&) override; |
31 | | |
32 | | void continue_async_execution(VM&, Value, bool is_successful, IsInitialExecution is_initial_execution = IsInitialExecution::No); |
33 | | |
34 | | private: |
35 | | AsyncFunctionDriverWrapper(Realm&, NonnullGCPtr<GeneratorObject>, NonnullGCPtr<Promise> top_level_promise); |
36 | | ThrowCompletionOr<void> await(Value); |
37 | | |
38 | | NonnullGCPtr<GeneratorObject> m_generator_object; |
39 | | NonnullGCPtr<Promise> m_top_level_promise; |
40 | | GCPtr<Promise> m_current_promise { nullptr }; |
41 | | OwnPtr<ExecutionContext> m_suspended_execution_context; |
42 | | }; |
43 | | |
44 | | } |