Skip to content

Add ArrayBuffer detach and Uint8ClampedArray wrappers#46

Open
richerfu wants to merge 1 commit into
mainfrom
codex/arraybuffer-typedarray-wrapper-api
Open

Add ArrayBuffer detach and Uint8ClampedArray wrappers#46
richerfu wants to merge 1 commit into
mainfrom
codex/arraybuffer-typedarray-wrapper-api

Conversation

@richerfu

Copy link
Copy Markdown
Contributor

No description provided.

@github-actions

Copy link
Copy Markdown

zig-napi ArkVM benchmark

  • Generated: 2026-05-28T02:49:53Z
  • Status: ZIG_NAPI_BENCHMARK_RESULT status=ok
module api content iterations native C N-API avg (us) zig-napi avg (us) diff (us) ratio
global function void(*)() 100000 0.109 0.111 0.003 1.026x
primitive i32(i32, i32) 100000 0.135 0.139 0.004 1.026x
primitive bool(bool) 100000 0.13 0.133 0.002 1.019x
string len(string) 100000 0.159 0.158 -0.001 0.992x
object read properties 100000 0.333 0.331 -0.002 0.995x
array sum(number[]) 100000 0.618 0.613 -0.006 0.991x
function call callback 100000 0.269 0.282 0.013 1.05x
class constructor 20000 0.992 4.569 3.576 4.604x
class getter 100000 0.235 0.228 -0.007 0.97x
class setter 100000 0.432 0.423 -0.009 0.978x
class method 100000 0.249 0.242 -0.007 0.972x
ArrayBuffer constructor 20000 0.324 0.379 0.055 1.169x
ArrayBuffer byteLength 100000 0.159 0.16 0.002 1.012x
Buffer constructor 20000 0.943 0.784 -0.159 0.831x
Buffer length 100000 0.166 0.165 -0.001 0.994x
TypedArray Uint8Array constructor 20000 0.706 0.879 0.173 1.245x
TypedArray Uint8Array sum 100000 0.195 0.222 0.027 1.139x
DataView constructor 20000 0.425 0.452 0.027 1.064x
DataView byteLength 100000 0.155 0.196 0.041 1.261x

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() and ArrayBuffer.isDetached() wrappers guarded by a Node-API v7 compile-time requirement.
  • Introduce TypedArrayWithRawType to support non-default typed array “raw types” for a given element type.
  • Export Uint8ClampedArray through the public src/napi.zig API.

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);
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.

2 participants