2021-11-10 21:16:07 +00:00
|
|
|
/*
|
|
|
|
* 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);
|
2024-11-14 15:01:23 +00:00
|
|
|
GC_DECLARE_ALLOCATOR(AsyncFunctionDriverWrapper);
|
2021-11-10 21:16:07 +00:00
|
|
|
|
|
|
|
public:
|
2023-08-09 21:12:07 +00:00
|
|
|
enum class IsInitialExecution {
|
|
|
|
No,
|
|
|
|
Yes,
|
|
|
|
};
|
|
|
|
|
2024-11-14 15:01:23 +00:00
|
|
|
[[nodiscard]] static GC::Ref<Promise> create(Realm&, GeneratorObject*);
|
2021-11-10 21:16:07 +00:00
|
|
|
|
2022-03-14 16:25:06 +00:00
|
|
|
virtual ~AsyncFunctionDriverWrapper() override = default;
|
2021-11-10 21:16:07 +00:00
|
|
|
void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
2023-08-09 21:12:07 +00:00
|
|
|
void continue_async_execution(VM&, Value, bool is_successful, IsInitialExecution is_initial_execution = IsInitialExecution::No);
|
2021-11-10 21:16:07 +00:00
|
|
|
|
|
|
|
private:
|
2024-11-14 15:01:23 +00:00
|
|
|
AsyncFunctionDriverWrapper(Realm&, GC::Ref<GeneratorObject>, GC::Ref<Promise> top_level_promise);
|
2023-08-09 21:12:07 +00:00
|
|
|
ThrowCompletionOr<void> await(Value);
|
2022-12-25 16:16:02 +00:00
|
|
|
|
2024-11-14 15:01:23 +00:00
|
|
|
GC::Ref<GeneratorObject> m_generator_object;
|
|
|
|
GC::Ref<Promise> m_top_level_promise;
|
|
|
|
GC::Ptr<Promise> m_current_promise { nullptr };
|
2023-11-27 15:45:45 +00:00
|
|
|
OwnPtr<ExecutionContext> m_suspended_execution_context;
|
2021-11-10 21:16:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|