ReviewOS

zig-utils/zig-js

ABI: implement readable-stream consumption and conversions

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

Parents: #140, #143 Profiles: #163, #164 Roadmap: #134

Implement the six pinned readable-stream consumption boundaries on top of a real Web Streams state machine. This is not a permission to accept an arbitrary array/iterator as a stream: the exported ABI must preserve locked, disturbed, cancellation, chunk, and Promise behavior.

Scope

  • Pin Home 7ed99c02, Bun 4982b91e, ReadableStream.cpp, generated builtin behavior, and exact source identities.
  • Implement realm-local ReadableStream, default reader, controller, queue, close/error/cancel, lock release, and disturbed state needed by the pinned consumers.
  • Consume synchronously and asynchronously enqueued chunks in order without invoking user code while engine/GC locks are held.
  • Implement ZigGlobalObject__readableStreamToArrayBuffer with exact byte concatenation, detached/view bounds, overflow, rejection, and Promise identity.
  • Implement ZigGlobalObject__readableStreamToBytes as the pinned Uint8Array result without an avoidable second payload copy.
  • Implement ZigGlobalObject__readableStreamToText with streaming UTF-8 decoding, split sequences, BOM/error behavior, and lone-surrogate safety.
  • Implement ZigGlobalObject__readableStreamToJSON through the engine JSON parser, with decode/parse failures delivered through the returned Promise.
  • Implement ZigGlobalObject__readableStreamToBlob with exact byte/type ownership and Blob integration.
  • Implement ZigGlobalObject__readableStreamToFormData for pinned multipart and URL-encoded content types, boundaries, filenames, binary values, duplicates, and malformed bodies.
  • Preserve locked/already-consumed/errored/cancelled streams, abrupt pull/cancel callbacks, empty bodies, mixed/invalid chunks, sibling realms, invalid encoded handles, and OOM/failure atomicity.
  • Add bounded Home/Bun Debug, ReleaseSafe, and TSan fixtures; refresh inventories, concise README counts, docs, and roadmap evidence.
  • Close only after the exact fixing main CI job is green.

No placeholder resolved Promise, eager whole-source shortcut, or host-only stream shape. All six exports must consume the same engine-native stream machinery that JavaScript observes.

9 days ago

Implementation is on main in three cohesive commits: 5244b82d (realm-local stream machinery and six C ABI consumers), 4ccbe6c8 (Home/Bun compiled consumers plus Debug/ReleaseSafe/TSan CI), and 4275f7c2 (exact contracts, audit validators, inventories, docs, and concise README counts). Local evidence is green across focused engine and 6/6-symbol external fixtures in Debug, ReleaseSafe, and TSan, with Home 439/471 and Bun 430/461. Closure remains gated on the exact 4275f7c2 main job.

9 days ago

Exact fixing-main CI is green, including the complete private-ABI boundary: https://github.com/zig-utils/zig-js/actions/runs/29785272707/job/88495394827

Sign in to comment on this issue.