ReviewOS

zig-utils/zig-js

Bridge: implement managed references, identity, and lifetime semantics

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

Parent: #138 Depends on: Objective-C inventory and core behavior children

Implement cycle-safe Objective-C/JavaScript ownership rather than relying on incidental NSObject or arena lifetime.

Acceptance:

  • Implement JSManagedValue factory/init/value behavior and conditional clearing after collection.
  • Implement JSVirtualMachine addManagedReference:withOwner: and removeManagedReference:withOwner: with exact owner/object pair semantics.
  • Make wrapper caches preserve Objective-C/JavaScript identity without creating permanent retain cycles.
  • Define VM/context/thread/autorelease ownership, teardown order, cross-VM rejection, and weak/strong transitions.
  • Add forced-GC, autorelease-pool, nested graph, duplicate add/remove, owner death, context death, and long-running leak/finalization tests.
  • Add fault-injection coverage for every bridge allocation/registration rollback path. Child issue:
  • #161 — collection epochs and arena reachability for conditional managed-value clearing
9 days ago

First managed-lifetime slice landed through e1de668. JSManagedValue now uses a real JavaScript WeakRef for object targets, keeps primitives directly, and JSVirtualMachine owner relations promote targets strongly without retaining owners. Focused ARC evidence covers primitive/object identity, owner add/remove, cross-VM rejection, weak-owner teardown, and no premature loss under the current VM-lifetime arena policy. All six managed-value/VM declarations are inventoried implemented; the issue remains open for arbitrary exported-wrapper identity, autorelease/VM teardown stress, and collecting-context-group evidence (current groups intentionally retain arena values until VM teardown).

9 days ago

Wrapper identity/lifetime evidence is now complete through e45bc02: Objective-C objects round-trip with pointer identity, JS object reads return canonical JSValue wrappers by strict equality even when raw C handle addresses differ, temporary VM/context/native graphs release at autorelease-pool teardown, weak owners are not retained, and cross-VM value/managed relations raise NSInvalidArgumentException. The pinned differential is 8/8 rows (bc1860c0e6e8d919). Wrapper-cache and ownership-definition acceptance boxes are checked; conditional collection, exact duplicate relation accounting, deeper stress/fault injection remain open.

9 days ago

Lifetime evidence advanced through bc4d89b and c38f621. Managed roots now live on their owners, so owner death deterministically releases the rooted JSValue graph; export method/prototype caches retain raw VM-lifetime handles instead of context-retaining JSValue wrappers. zig build test-objc-api-evidence passes 200 VM/context/autorelease teardown cycles, ASan+UBSan, and Apple leaks with 0 leaked bytes. Remaining scope is explicit: conditional mid-VM clearing cannot occur under the current VM-lifetime arena policy, and bridge allocation/registration rollback still needs fault injection.

9 days ago

Completed through f29ca38 with child #161 closed. Managed factories and conditional clearing, exact owner/object relations, identity caches, teardown and cross-VM rules, forced-GC/autorelease/nested/duplicate/owner-death/context-death stress, 200-cycle sanitizer/leak evidence, and deterministic rollback injection are all implemented and documented.

Sign in to comment on this issue.