Node.js runtime support for native core#1046
Open
simonklee wants to merge 4 commits into
Open
Conversation
e49d3bf to
47da404
Compare
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adapt the FFI and worker layers so the native Zig core runs on Node.js