Add ArrayBuffer detach and Uint8ClampedArray wrappers#46
Open
richerfu wants to merge 1 commit into
Open
Conversation
zig-napi ArkVM benchmark
|
There was a problem hiding this comment.
Pull request overview
This PR expands the Node-API wrapper surface by adding support for detaching ArrayBuffers (Node-API v7+) and introducing a Uint8ClampedArray typed array wrapper variant.
Changes:
- Add
ArrayBuffer.detach()andArrayBuffer.isDetached()wrappers guarded by a Node-API v7 compile-time requirement. - Introduce
TypedArrayWithRawTypeto support non-default typed array “raw types” for a given element type. - Export
Uint8ClampedArraythrough the publicsrc/napi.zigAPI.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/napi/wrapper/typedarray.zig |
Adds a raw-typedarray override path and a Uint8ClampedArray wrapper. |
src/napi/wrapper/arraybuffer.zig |
Adds Node-API v7 ArrayBuffer detach + detached-state queries. |
src/napi.zig |
Re-exports Uint8ClampedArray from the typed array wrapper module. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+249
to
+257
| /// Detach the ArrayBuffer. | ||
| pub fn detach(self: ArrayBuffer) !void { | ||
| comptime options.requireNapiVersion(.v7); | ||
|
|
||
| const status = napi.napi_detach_arraybuffer(self.env, self.raw); | ||
| if (status != napi.napi_ok) { | ||
| return NapiError.Error.fromStatus(NapiError.Status.New(status)); | ||
| } | ||
| } |
Comment on lines
203
to
206
| pub const Int8Array = TypedArray(i8); | ||
| pub const Uint8Array = TypedArray(u8); | ||
| pub const Uint8ClampedArray = TypedArrayWithRawType(u8, napi.napi_uint8_clamped_array); | ||
| pub const Int16Array = TypedArray(i16); |
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.
No description provided.