mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:18:13 +00:00
LibJS: Implement await properly for async functions
Fixes #20275 ``` Summary: Diff Tests: +4 ✅ -4 ❌ Diff Tests: test/built-ins/Array/fromAsync/non-iterable-input-with-thenable -async-mapped-awaits-callback-result-once.js ❌ -> ✅ test/language/expressions/await/async-await-interleaved.js ❌ -> ✅ test/language/expressions/await/await-awaits-thenables-that- throw.js ❌ -> ✅ test/language/expressions/await/await-awaits-thenables.js ❌ -> ✅ ```
This commit is contained in:
parent
5003b1a421
commit
ae7a0c43a9
5 changed files with 175 additions and 69 deletions
|
@ -18,23 +18,27 @@ class AsyncFunctionDriverWrapper final : public Promise {
|
|||
JS_OBJECT(AsyncFunctionDriverWrapper, Promise);
|
||||
|
||||
public:
|
||||
enum class IsInitialExecution {
|
||||
No,
|
||||
Yes,
|
||||
};
|
||||
|
||||
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);
|
||||
void continue_async_execution(VM&, Value, bool is_successful, IsInitialExecution is_initial_execution = IsInitialExecution::No);
|
||||
|
||||
private:
|
||||
AsyncFunctionDriverWrapper(Realm&, NonnullGCPtr<GeneratorObject>, NonnullGCPtr<Promise> top_level_promise);
|
||||
ThrowCompletionOr<void> await(Value);
|
||||
|
||||
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;
|
||||
Optional<ExecutionContext> m_suspended_execution_context;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue