Implements issue 3mhn3oxz6dq2k — JS Promise and microtask queue.
Summary #
- Promise constructor: Defined via JS preamble so the executor callback runs as bytecode (not limited to native-only callbacks). Executor runs synchronously, with resolve/reject closures that call native
__Promise_resolve/__Promise_rejecthelpers. - Promise.prototype.then/catch/finally: Register reaction handlers on pending promises or enqueue microtasks immediately for already-settled promises. Returns chained promises for proper chain propagation.
- Promise.resolve/reject: Static methods to create pre-settled promises.
- Promise.all/allSettled/race/any: Combinators for working with arrays of promises.
- Microtask queue: Thread-local queue (
Vec<Microtask>) drained after eachvm.execute()call. Each microtask calls a handler function and resolves/rejects the chained promise with the result. - VM.call_function: New method to invoke GC-managed functions (both native and bytecode) from outside the normal execution loop. Saves/restores frame state for bytecode calls.
- Promise.prototype as GC root: Stored on the
Vmstruct (like other prototypes) to prevent garbage collection. - Removed Promise from test262 unsupported features list.
Test plan #
- 29 new integration tests covering:
- Promise.resolve/reject with then/catch handlers
- Constructor with executor (resolve, reject, synchronous execution)
- Then chaining (value propagation through chain)
- Catch returns to then chain (error recovery)
- Error propagation (throw in then handler goes to catch)
- Finally handler (fulfilled and rejected paths)
- Promise.all (empty, resolved, rejects on first failure, non-promise values)
- Promise.race (first wins, reject wins, non-promise values)
- Promise.any (first fulfilled, all rejected)
- Identity passthrough (then with no handler)
- Catch passthrough (doesn't intercept fulfillment)
- Double resolve ignored
- Executor throw rejects
- Multiple then on same promise
- All workspace tests pass (471 JS tests including 29 new Promise tests)
cargo clippy --workspace -- -D warningscleancargo fmt --all --checkclean