summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.h
blob: 4942ed2e314875131d50d10985a33d2dfe9ed2eb (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
/*
 * Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <LibJS/Bytecode/Interpreter.h>
#include <LibJS/Runtime/ECMAScriptFunctionObject.h>
#include <LibJS/Runtime/GeneratorObject.h>
#include <LibJS/Runtime/Object.h>
#include <LibJS/Runtime/Promise.h>

namespace JS {

class AsyncFunctionDriverWrapper final : public Promise {
    JS_OBJECT(AsyncFunctionDriverWrapper, Promise);

public:
    static ThrowCompletionOr<Value> create(Realm&, GeneratorObject*);
    explicit AsyncFunctionDriverWrapper(Realm&, GeneratorObject*);

    virtual ~AsyncFunctionDriverWrapper() override = default;
    void visit_edges(Cell::Visitor&) override;

    ThrowCompletionOr<Value> react_to_async_task_completion(VM&, GlobalObject&, Value, bool is_successful);

private:
    GeneratorObject* m_generator_object { nullptr };
    NativeFunction* m_on_fulfillment { nullptr };
    NativeFunction* m_on_rejection { nullptr };
};

}