Implements issue 3mhn3pphkyd2f
Changes #
Bytecode #
- New
Awaitopcode (0x82) — saves async function state and returns to the driver is_asyncflag on bytecodeFunctionstruct
Compiler #
- Async function declarations, expressions, and methods set
is_asyncon compiled function await exprcompiles to Await opcode- Async arrow functions set
is_asyncon inner function for await (let x of iter)parsed and compiled with@@asyncIterator
VM #
- Async functions create an internal generator + result promise
drive_async_step()runs the generator and resolves/rejects the promisesetup_async_resume()wires up promise reactions for await resumethrow_into_generator()handles rejected await (throws into try/catch)- Exception handlers saved/restored across yield/await suspension points
- Async generator wrapper with
next(),return(),@@asyncIterator __async_resume__detection in both Call opcode andcall_function
Tests #
16 unit tests covering:
- Async function returns promise, resolves with return value
awaiton resolved/rejected promisesawaiton non-promise values- Multiple sequential awaits
- try/catch around rejected await
- Throw inside async function rejects promise
- Async arrow functions (expression and concise body)
- Await on chained promises
- Async closures
- Async object methods
- Async generators
for await...ofparsing