mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:57:35 +00:00
LibJS: Overhaul AsyncFunctionDriverWrapper to make it actually work
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
This commit is contained in:
parent
de514f29ad
commit
4c2b4c1a27
2 changed files with 106 additions and 37 deletions
|
@ -23,14 +23,18 @@ public:
|
|||
virtual ~AsyncFunctionDriverWrapper() override = default;
|
||||
void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
ThrowCompletionOr<Value> react_to_async_task_completion(VM&, Value, bool is_successful);
|
||||
void continue_async_execution(VM&, Value, bool is_successful);
|
||||
|
||||
private:
|
||||
AsyncFunctionDriverWrapper(Realm&, GeneratorObject*);
|
||||
AsyncFunctionDriverWrapper(Realm&, NonnullGCPtr<GeneratorObject>, NonnullGCPtr<Promise> top_level_promise);
|
||||
|
||||
GeneratorObject* m_generator_object { nullptr };
|
||||
NativeFunction* m_on_fulfillment { nullptr };
|
||||
NativeFunction* m_on_rejection { nullptr };
|
||||
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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue