Implement async functions and the await expression.
Scope#
Async Functions#
async functiondeclarations and expressionsasyncarrow functions:async () => { ... }asyncmethod definitions in objects and classes- Async functions always return a Promise
- Return value wraps in Promise.resolve()
- Thrown exception wraps in Promise.reject()
Await Expression#
await expr— pause async function until promise settles- If awaited value is fulfilled, resume with fulfillment value
- If awaited value is rejected, throw rejection reason
- Awaiting non-promise values: wrap in Promise.resolve first
- Proper microtask scheduling (await is a microtask boundary)
Async Iteration#
async function*(async generator functions)for await...ofloop- Async iterators:
{ next() → Promise<{ value, done }> } Symbol.asyncIterator
Integration#
- Async functions build on the Promise and generator infrastructure
- The VM must support suspending and resuming execution across await points
- Microtask queue integration: await resumes via microtask
Acceptance Criteria#
- Async functions return Promises
- await pauses execution until promise settles
- await with fulfilled promise resumes with value
- await with rejected promise throws
- Multiple awaits in sequence work correctly
- Async arrow functions work
- try/catch in async functions catches rejected awaits
- Async generators yield promises
- for await...of consumes async iterables
- Proper microtask ordering with await
- Unit tests for all async patterns
Phase 10 — JavaScript Engine (issue 15a of 15). Depends on: JS Promise, JS iterators/generators.