mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-26 06:18:59 +00:00
This object is responsible for handling async functions in bytecode, and this commit fully rewrites it, now it does: * creates and keeps alive a top level promise, which callers can attach their `then` clauses * creates and clear a handle to itself, to assure that it does not get garbage collected * properly handles all possible ways a async function could halt and when possible continues the execution immediately
40 lines
1.2 KiB
C++
40 lines
1.2 KiB
C++
/*
|
|
* 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*);
|
|
|
|
virtual ~AsyncFunctionDriverWrapper() override = default;
|
|
void visit_edges(Cell::Visitor&) override;
|
|
|
|
void continue_async_execution(VM&, Value, bool is_successful);
|
|
|
|
private:
|
|
AsyncFunctionDriverWrapper(Realm&, NonnullGCPtr<GeneratorObject>, NonnullGCPtr<Promise> top_level_promise);
|
|
|
|
bool m_expect_promise { false };
|
|
NonnullGCPtr<GeneratorObject> m_generator_object;
|
|
NonnullGCPtr<NativeFunction> m_on_fulfillment;
|
|
NonnullGCPtr<NativeFunction> m_on_rejection;
|
|
NonnullGCPtr<Promise> m_top_level_promise;
|
|
GCPtr<Promise> m_current_promise { nullptr };
|
|
Handle<AsyncFunctionDriverWrapper> m_self_handle;
|
|
};
|
|
|
|
}
|