ReviewOS

zig-utils/zig-js

Implement private async-context call ABI

#373
Closed chris opened this 9 days ago ·
9 days ago

Parent: #134

Implements the coherent async-context call boundary shared by the pinned Home and Bun inventories. This is a child of the private ABI coverage work tracked by #140, #163, and #164.

Scope

  • AsyncContextFrame__withAsyncContextIfNeeded
  • Bun__JSValue__isAsyncContextFrame
  • Bun__JSValue__call

Bake__getAsyncLocalStorage is intentionally out of scope: upstream exposes a separately stored Bake/dev-server ALS instance, not the currently active async-context value captured by these wrappers.

Acceptance

  • Add a realm-local active async-context value as a precise traced and relocated GC root.
  • Represent an AsyncContextFrame as a branded, non-callable object with strong callback and captured-context edges.
  • Return callbacks unchanged when no context is active and avoid double-wrapping existing frames.
  • Invoke plain callbacks and wrapped callbacks with exact argument ordering and global-this fallback for an empty receiver.
  • Install the captured context for the dynamic extent of the call and restore the prior context before normal return or exception publication.
  • Reject invalid/foreign handles without crossing VM ownership boundaries.
  • Cover brand, capture, nested restoration, throw restoration, GC retention/relocation, and compiled Home/Bun consumer signatures.
  • Refresh generated ABI inventories and coverage documentation, batch Debug/ReleaseSafe verification, then close this issue only after the pushed main commit is green.
9 days ago

Implemented and pushed directly to main in df79596 (feat(abi): implement async context calls (#373)).

Delivered:

  • AsyncContextFrame__withAsyncContextIfNeeded, Bun__JSValue__isAsyncContextFrame, and Bun__JSValue__call
  • realm-local precisely traced/relocated active async-context root
  • branded null-prototype non-callable frame with strong callback/context edges
  • exact inactive identity, no double wrapping, encoded argument order, empty-receiver global fallback, same-VM validation, and restoration before normal return or throw publication
  • insertion barriers plus a temporary root for the displaced context across callback-triggered GC
  • compiled Home and Bun consumer evidence and refreshed pinned inventories/docs

Verification (Debug and ReleaseSafe):

  • focused async-context engine tests: 3/3 passed, 0 leaked
  • relocation-focused engine tests: 25/25 passed, 0 leaked
  • Home private consumer: 352/352 linked and runtime matrix passed
  • Bun private C-API extension consumer passed
  • C/API inventory audit passed

Coverage is now Home 365/471 (106 pending) and Bun 357/461 (104 pending). Bake__getAsyncLocalStorage remains intentionally separate because upstream stores a distinct Bake/dev-server ALS instance.

Sign in to comment on this issue.