ReviewOS

zig-utils/zig-js

ABI: add owned structured-serialization slices and round-trip

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

Parents: #140, #163, #164 Pinned reference: Bun 4982b91e src/jsc/bindings/Serialization.cpp; Home 7ed99c02 JSValue.zig

Implement the shared private serialization slice on top of zig-js's existing failure-atomic structured-clone wire format.

Acceptance:

  • Implement exact 24-byte {bytes,size,handle} return layout for Bun__serializeJSValue.
  • Keep the returned byte span stable and independently owned until Bun__SerializedScriptSlice__free.
  • Release retained SharedArrayBuffer manifest references and bytes exactly once; define null/stale-handle behavior safely.
  • Publish DataCloneError/OOM through the VM-shared pending-exception channel and return a zero external slice.
  • Implement the companion Bun__JSValue__deserialize boundary with malformed-input diagnostics and same-VM output ownership.
  • Specify/test forCrossProcessTransfer and forStorage flags instead of silently ignoring unsupported semantics.
  • Cover primitives, cycles/identity, typed data, SharedArrayBuffer lifetime, uncloneable values, malformed bytes, cross-VM rejection, and allocation failure.
  • Add compiled consumer coverage, regenerate both inventories, and update #140/#163/#164 totals.
9 days ago

Pinned-source audit complete. The reference returns exactly {const u8 *bytes, size_t size, SerializedScriptValue *value} and leaks one ref released by deref(). zig-js already has a failure-atomic, context-independent framed serializer plus releaseSerialized, so ordinary values/cycles/typed data can reuse it without a second codec.

The non-trivial gate is flag fidelity: the current wire uses process-local opaque tokens to retain SharedArrayBuffer storage. forStorage and forCrossProcessTransfer therefore cannot simply be ignored or declared complete until storage rejection/representation and true cross-process shared-memory transport are specified. The handle implementation also needs a synchronized live-handle registry so duplicate/stale frees are harmless without dereferencing freed memory.

9 days ago

Implemented on main by a40ec46: exact 24-byte owned {bytes,size,handle} layout, opaque monotonic ownership tokens with idempotent stale/duplicate frees, structured-clone round trips (cycles, aliases, typed data, default process-local SAB), portable-flag SAB rejection, pending exceptions, malformed/cross-VM/uncloneable/OOM handling, and focused GC/ABA/flag coverage. Focused unit matrix passed 3/3 with no leaks; both pinned ABI audits passed. Inventories now count Home 319/431 and Bun 310/421 private symbols implemented at this commit. Full CI is running at https://github.com/zig-utils/zig-js/actions/runs/29698929044; I will close after it is fully green.

9 days ago

Acceptance complete. Full CI run https://github.com/zig-utils/zig-js/actions/runs/29698929044 finished successfully across all 40 jobs, including all four no-GIL TSan corpus shards, lifecycle/mid-script fuzzing, unit/TSan shards, configured test262, WebAssembly profiles, docs, and benchmark-harness validation. Closing against main commit a40ec46.

Sign in to comment on this issue.