Skip to content

Add object and array wrapper APIs#45

Open
richerfu wants to merge 1 commit into
mainfrom
codex/object-array-wrapper-api
Open

Add object and array wrapper APIs#45
richerfu wants to merge 1 commit into
mainfrom
codex/object-array-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:37Z
  • 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.095 0.097 0.003 1.028x
primitive i32(i32, i32) 100000 0.128 0.134 0.005 1.041x
primitive bool(bool) 100000 0.11 0.114 0.003 1.031x
string len(string) 100000 0.143 0.146 0.003 1.017x
object read properties 100000 0.279 0.277 -0.001 0.995x
array sum(number[]) 100000 0.627 0.624 -0.003 0.995x
function call callback 100000 0.226 0.237 0.011 1.048x
class constructor 20000 0.957 5.072 4.115 5.299x
class getter 100000 0.182 0.182 0 0.999x
class setter 100000 0.365 0.346 -0.019 0.948x
class method 100000 0.194 0.199 0.004 1.023x
ArrayBuffer constructor 20000 0.274 0.337 0.062 1.227x
ArrayBuffer byteLength 100000 0.147 0.144 -0.003 0.979x
Buffer constructor 20000 0.911 0.737 -0.174 0.809x
Buffer length 100000 0.148 0.147 -0.001 0.996x
TypedArray Uint8Array constructor 20000 0.683 0.861 0.178 1.26x
TypedArray Uint8Array sum 100000 0.17 0.202 0.032 1.19x
DataView constructor 20000 0.384 0.393 0.009 1.023x
DataView byteLength 100000 0.146 0.182 0.036 1.248x

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds several wrapper APIs around existing N-API calls: a generic-keyed SetValue on Object plus propertyNames, isDate, dateValue, freeze, and seal, and on Array adds CreateWithLength, HasElement, and DeleteElement (each with a camelCase alias). Version-gated helpers use options.requireNapiVersion so they fail at compile time on unsupported N-API levels.

Changes:

  • New Object helpers for property enumeration, Date inspection, and freezing/sealing, plus a generic-key SetValue.
  • New Array helpers CreateWithLength, HasElement, and DeleteElement.
  • Both new files use options.requireNapiVersion to gate v5/v8-only features at comptime.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/napi/value/object.zig Adds SetValue, propertyNames, isDate, dateValue, freeze, seal, plus new Array / options imports.
src/napi/value/array.zig Adds CreateWithLength, HasElement, DeleteElement and their camelCase aliases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/napi/value/object.zig
Comment on lines +159 to +166
pub fn isDate(self: Object) bool {
comptime options.requireNapiVersion(.v5);

var result: bool = false;
const status = napi.napi_is_date(self.env, self.raw, &result);
if (status != napi.napi_ok) {
NapiError.last_error = NapiError.Error.withStatus(NapiError.Status.New(status));
return false;
Comment thread src/napi/value/object.zig
Comment on lines +106 to +117
pub fn SetValue(self: Object, key: anytype, value: anytype) !void {
const key_raw = try Napi.to_napi_value_auto(self.env, key, null);
const n_value = try Napi.to_napi_value_auto(self.env, value, null);
const status = napi.napi_set_property(self.env, self.raw, key_raw, n_value);
if (status != napi.napi_ok) {
return NapiError.Error.fromStatus(NapiError.Status.New(status));
}
}

pub fn setValue(self: Object, key: anytype, value: anytype) !void {
try self.SetValue(key, value);
}
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