feat: add owned typed arrays - #68
Draft
GrapeBaBa wants to merge 6 commits into
Draft
Conversation
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.
Summary
js.OwnedTypedArray(Element, array_type)and concreteOwned*ArrayaliasesElementagainst its N-API TypedArray kind at compile timeTypedArray.fromExternalunchanged frommainNoExternalBuffersAllowedunchanged; no copy fallbackAPI
fromOwnedSlicetakes an existing allocator-owned mutable slice without copying.fromSlicecreates an owned copy when that is what the caller needs.intoValuetakes*OwnedTypedArray. Once ownership transfers, it empties the source, so a normal deferreddeinitis safe. The allocator must remain valid until the ArrayBuffer finalizer runs.Ownership boundary
NoExternalBuffersAllowed,PendingException, orCannotRunJS: Node returns before finalizer registration, so restore ownership to the caller and propagate the original errordeiniton the local owner, which frees restored/untransferred data and is a no-op after transferThe heap finalizer context is the
OwnedTypedArrayitself, matching the boxed-owner model rather than duplicating ownership fields in a second context type.Node implementation reference for the ambiguous failure boundary:
Verification
zig build test:zapizig buildpnpm test:js— 119/119pnpm lint:jszig fmt --check src/js/typed_arrays.zig src/js/wrap_function.ziggit diff --check origin/mainSpec tests were intentionally not run.
The repository-wide
zig fmt --check srcstill reports the pre-existing formatting issue insrc/create_callback.zig; this PR does not modify that file.Coverage limitation
The JS tests exercise non-empty and zero-length
OwnedUint8Arrayvalues through the real Node addon boundary. They do not deterministically force GC to count finalizer invocations or injectNoExternalBuffersAllowed, pending/cannot-run, generic external-creation, or typed-array-view creation failures. No production test seam or compatibility branch was added for those cases.