ReviewOS

zig-utils/zig-js

ABI: exact JSGlobalObject owning-VM query

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

Parent: #140 Tracked by: #134, #163, #164

Implement the pinned JSC__JSGlobalObject__bunVM export: the exact owning-VM query every consumer realm funnels through (bunVM(), bunVMUnsafe(), tryBunVM(), bunVMConcurrently()). The declaration is byte-identical in the pinned Home JSGlobalObject.zig (revision 7ed99c02) and the Bun core inventory; the pinned Bun C++ bridge returns the VirtualMachine registered in the VM's WebCore client data.

Acceptance

  • Pin the exact declaration extern fn JSC__JSGlobalObject__bunVM(*JSGlobalObject) *VM.
  • Return the one VM identity that owns the selected realm — the same pointer zig-js already publishes through JSC__JSGlobalObject__vm and consumes in every JSC__VM__* export, since zig-js's context group is both the JSC VM and the embedding VM.
  • Sibling realms in one context group resolve to the identical VM pointer; a foreign context group resolves to a different VM; an invalid handle returns null rather than a stale or fabricated pointer.
  • Cover identity, sibling-sharing, foreign-group distinction, and null-handle behavior in the generated compile-link-runtime fixture.
  • Mark the export implemented in both inventories with zero unclassified entries, and update the README/private-ABI counts and evidence.

Design constraint

This is a pure ownership query: it must not allocate, attach, or create any VM state, and it must not disturb a pending VM exception.

Evidence

Completed on main in runtime commit 731e218f with README/private-ABI evidence in 95bc0ceb.

  • The export returns the realm's context-group VM pointer, exactly the identity JSC__JSGlobalObject__vm publishes and every JSC__VM__* boundary consumes; zig-js's context group is both the JSC VM and the embedding VM, so the two Bun-side pointers coincide by architecture.
  • Fixture coverage: non-null identity with JSC__JSGlobalObject__vm on the primary realm, identical pointer from a sibling realm in the same group, distinct identity for a foreign context group, foreign identity matching its own vm, and null for a null handle.
  • Generated Home consumer: 281/281 symbols linked; runtime matrix passed.
  • Home inventory: 279/431 implemented, 152 pending, zero unclassified.
  • Bun core inventory: 271/421 implemented, 150 pending, zero unclassified.
  • Public/private export audit: 117 public functions complete, 287 classified private profile exports.
  • Focused c_api unit shard: 148 passed, 0 skipped, 0 failed, 0 leaked; public C and Home public ABI fixtures green (50/50).
  • The committed 1,540-sample benchmark matrix remains current because this allocation-free query is outside its workloads.

Sign in to comment on this issue.