2021-11-11 00:46:07 +03:30
|
|
|
/*
|
|
|
|
* 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 {
|
|
|
|
|
2025-07-19 10:41:08 -07:00
|
|
|
class AsyncFunctionDriverWrapper final : public Promise {
|
2021-11-11 00:46:07 +03:30
|
|
|
JS_OBJECT(AsyncFunctionDriverWrapper, Promise);
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DECLARE_ALLOCATOR(AsyncFunctionDriverWrapper);
|
2021-11-11 00:46:07 +03:30
|
|
|
|
|
|
|
public:
|
2024-11-15 04:01:23 +13:00
|
|
|
[[nodiscard]] static GC::Ref<Promise> create(Realm&, GeneratorObject*);
|
2021-11-11 00:46:07 +03:30
|
|
|
|
2022-03-14 10:25:06 -06:00
|
|
|
virtual ~AsyncFunctionDriverWrapper() override = default;
|
2021-11-11 00:46:07 +03:30
|
|
|
void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
2025-01-22 18:59:37 +13:00
|
|
|
void continue_async_execution(VM&, Value, bool is_successful);
|
2021-11-11 00:46:07 +03:30
|
|
|
|
|
|
|
private:
|
2024-11-15 04:01:23 +13:00
|
|
|
AsyncFunctionDriverWrapper(Realm&, GC::Ref<GeneratorObject>, GC::Ref<Promise> top_level_promise);
|
2023-08-09 22:12:07 +01:00
|
|
|
ThrowCompletionOr<void> await(Value);
|
2022-12-25 17:16:02 +01:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<GeneratorObject> m_generator_object;
|
|
|
|
GC::Ref<Promise> m_top_level_promise;
|
|
|
|
GC::Ptr<Promise> m_current_promise { nullptr };
|
2023-11-27 16:45:45 +01:00
|
|
|
OwnPtr<ExecutionContext> m_suspended_execution_context;
|
2025-05-09 04:57:02 +03:00
|
|
|
|
|
|
|
GC::Ptr<NativeFunction> m_on_fulfilled;
|
|
|
|
GC::Ptr<NativeFunction> m_on_rejected;
|
2021-11-11 00:46:07 +03:30
|
|
|
};
|
|
|
|
|
|
|
|
}
|