/* * Copyright (c) 2021, Ali Mohammad Pur * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include namespace JS { class AsyncFunctionDriverWrapper final : public Promise { JS_OBJECT(AsyncFunctionDriverWrapper, Promise); JS_DECLARE_ALLOCATOR(AsyncFunctionDriverWrapper); public: enum class IsInitialExecution { No, Yes, }; [[nodiscard]] static NonnullGCPtr create(Realm&, GeneratorObject*); virtual ~AsyncFunctionDriverWrapper() override = default; void visit_edges(Cell::Visitor&) override; void continue_async_execution(VM&, Value, bool is_successful, IsInitialExecution is_initial_execution = IsInitialExecution::No); private: AsyncFunctionDriverWrapper(Realm&, NonnullGCPtr, NonnullGCPtr top_level_promise); ThrowCompletionOr await(Value); NonnullGCPtr m_generator_object; NonnullGCPtr m_top_level_promise; GCPtr m_current_promise { nullptr }; Handle m_self_handle; OwnPtr m_suspended_execution_context; }; }