Skip to content

Add Wrap#43

Merged
richerfu merged 1 commit into
mainfrom
feat-wrap
May 27, 2026
Merged

Add Wrap#43
richerfu merged 1 commit into
mainfrom
feat-wrap

Conversation

@richerfu
Copy link
Copy Markdown
Contributor

No description provided.

@github-actions
Copy link
Copy Markdown

zig-napi ArkVM benchmark

  • Generated: 2026-05-27T08:45:32Z
  • 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.105 0.125 0.02 1.192x
primitive i32(i32, i32) 100000 0.137 0.142 0.004 1.032x
primitive bool(bool) 100000 0.129 0.133 0.004 1.029x
string len(string) 100000 0.16 0.158 -0.002 0.988x
object read properties 100000 0.323 0.33 0.007 1.022x
array sum(number[]) 100000 0.62 0.617 -0.003 0.995x
function call callback 100000 0.271 0.286 0.016 1.058x
class constructor 20000 0.971 4.5 3.529 4.634x
class getter 100000 0.21 0.28 0.07 1.332x
class setter 100000 0.47 0.375 -0.095 0.798x
class method 100000 0.221 0.236 0.016 1.071x
ArrayBuffer constructor 20000 0.315 0.475 0.16 1.507x
ArrayBuffer byteLength 100000 0.155 0.159 0.004 1.028x
Buffer constructor 20000 0.993 0.79 -0.203 0.795x
Buffer length 100000 0.161 0.169 0.009 1.054x
TypedArray Uint8Array constructor 20000 0.709 0.866 0.157 1.221x
TypedArray Uint8Array sum 100000 0.191 0.219 0.028 1.145x
DataView constructor 20000 0.417 0.444 0.027 1.065x
DataView byteLength 100000 0.154 0.19 0.036 1.238x

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 a native wrap/unwrap utility that lets Zig code attach typed payloads to JS objects via napi_wrap, with type-tagged headers, optional napi_adjust_external_memory integration, and methods exposed on Env and Object.

Changes:

  • New src/napi/wrapper/native_wrap.zig implementing wrap/unwrap/unwrapConst/dropWrapped/matches with a magic-tagged header and finalizer.
  • Expose wrap APIs on Object (PascalCase + camelCase variants) and Env, and re-export the module as napi.NativeWrap.
  • Add Zig test bindings and an AVA spec covering create/get/mutate/drop, wrong-type errors, unwrap of non-wrapped object, and finalizer deinit counting.

Reviewed changes

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

Show a summary per file
File Description
src/napi/wrapper/native_wrap.zig Core implementation of tagged native wrap/unwrap with finalizer and memory adjustment.
src/napi/value/object.zig Adds wrap/unwrap/dropWrapped/matchesWrapped methods (and PascalCase aliases) on Object.
src/napi/env.zig Adds env-level wrap/unwrap helpers with an objectRaw shim for any value exposing raw.
src/napi.zig Re-exports native_wrap as napi.NativeWrap.
node-test/napi/src/values.zig Test payload types and bindings exercising wrap, unwrap, mutate, drop, and deinit count.
node-test/napi/src/lib.zig Exports the new bindings.
node-test/napi/tests/values.spec.js AVA test verifying wrap roundtrip, type mismatch errors, and finalizer counting.

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

@richerfu richerfu merged commit d5d786c into main May 27, 2026
24 checks passed
@richerfu richerfu deleted the feat-wrap branch May 27, 2026 08:59
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