[pull] main from oven-sh:main

Merged
PU
4mo ago
+749-94

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.4)

Can you help keep this open source service alive? 💖 Please sponsor : )


Summary by cubic

Makes threadsafe FFI callbacks safe after VM teardown and adds VM-scoped wall-clock termination deadlines. Also standardizes i64/u64 Number conversions to be architecture-independent.

  • Threadsafe JSFFICallbacks: the entry thunk now targets a persistent FFI::ThreadsafeCallbackHandle instead of the GC cell. Late calls (after close() or VM/global destruction) are dropped and return 0; runThreadsafeInvocation exits early if the cell is gone. Threadsafe callbacks are rooted VM‑wide until closed and drained, and the handle (with thunk) is kept alive once an entrypoint was handed out to avoid UAF.
  • i64/u64 Number conversion: writeInt64Slot uses modular conversion via JSC::toInt64 and stores the low 64 bits, making behavior identical on x86‑64 and arm64; NaN/±∞ convert to 0. Pointer types keep using the CPU truncation (doubleToInt64). Tests and fuzzers were updated to cover the new edges.
  • Termination deadlines: new VM::addTerminationDeadline, VM::cancelTermination, and VM::hasPendingTermination, plus $vm.callWithTimeLimit(fn, ms) that withdraws its own termination and throws RangeError "timed out" on expiry. Nested limits re‑request termination for enclosing scopes. A new stress test validates semantics.

Migration

  • If an embedder accepts a threadsafe invocation but chooses not to run it, call FFI::retireThreadsafeInvocation (exported in BunFFI.h) to withdraw the pending count and unroot if needed.