we (web engine): Experimental web browser project to understand the limits of Claude

JS Async functions and await #104

open opened by pierrelf.com

Implement async functions and the await expression.

Scope#

Async Functions#

  • async function declarations and expressions
  • async arrow functions: async () => { ... }
  • async method 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...of loop
  • 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.

sign up or login to add to the discussion
Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:meotu43t6usg4qdwzenk4s2t/sh.tangled.repo.issue/3mhn3pphkyd2f