Skip to content

Node.js runtime support for native core#1046

Open
simonklee wants to merge 4 commits into
mainfrom
debun-next
Open

Node.js runtime support for native core#1046
simonklee wants to merge 4 commits into
mainfrom
debun-next

Conversation

@simonklee
Copy link
Copy Markdown
Member

Adapt the FFI and worker layers so the native Zig core runs on Node.js

@simonklee simonklee changed the base branch from main to debun-urls May 11, 2026 08:54
@simonklee simonklee changed the base branch from debun-urls to main May 11, 2026 13:28
@simonklee simonklee force-pushed the debun-next branch 7 times, most recently from e49d3bf to 47da404 Compare May 18, 2026 06:58
simonklee added 4 commits May 18, 2026 11:38
Node's node:ffi has no usize, and Bun returns usize values as BigInt,
forcing per-call coercion in the binding layer. Empty Uint8Arrays
also cross to Zig as null pointers, which the old non-optional slice
parameters could not safely accept. Replace usize length arguments
with u32 and make slice pointers optional with explicit zero-length
and null guards. This drops the BigInt round-trips and lines up the
ABI for the Node.
Switch native log and event callback length parameters from usize to
u32 so the JS bridge receives plain numbers on both Bun and Node FFI
backends and avoids per-call BigInt conversion. Arena byte counts
move to u64 and route through a safe-integer guard since the value
can legitimately exceed u32.

Pointer-typed arguments (Pointer, ArrayBuffer, ArrayBufferView, null)
now normalize at the Node symbol boundary, and toArrayBuffer offsets
are validated up front. Callers no longer need to wrap every buffer
in ptr() to satisfy Node's stricter FFI surface.
Decouple the tree-sitter worker from runtime-specific globals so it can
construct and communicate on Node, Bun, and other Worker-capable hosts
through a single seam. The platform layer now owns main-thread worker
construction (including a node:worker_threads shim) and worker-side
message bridging, with a shared typed protocol on both ends.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant