Skip to content

fix(napi): receive raw pointer out parameters#57

Open
GrapeBaBa wants to merge 4 commits into
mainfrom
fix/napi-out-parameters-v2
Open

fix(napi): receive raw pointer out parameters#57
GrapeBaBa wants to merge 4 commits into
mainfrom
fix/napi-out-parameters-v2

Conversation

@GrapeBaBa

@GrapeBaBa GrapeBaBa commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Motivation

Node-API returns several values through pointer-sized C out parameters. The previous bindings passed addresses of higher-level Zig struct or wrapper storage to some of these APIs, so Node-API wrote raw pointer or handle bits into the wrong fields instead of a correctly typed raw slot. This could corrupt returned Node version data and TypedArray or DataView backing ArrayBuffer wrappers. Receiving the exact C values first, then copying or wrapping them only after a successful call, preserves both the C ABI and the Zig wrapper invariants. Unsupported TypedArray tags must likewise become a normal conversion error rather than an enum-conversion trap.

Summary

  • receive the Node version pointer through its own raw out slot before copying the version structure
  • receive TypedArray and DataView backing ArrayBuffer handles as raw napi_value values
  • construct Value wrappers only after successful Node-API calls
  • report unsupported Node-API TypedArray element types as UnsupportedTypedarrayType instead of trapping during enum conversion

@GrapeBaBa
GrapeBaBa marked this pull request as ready for review July 20, 2026 12:33
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.

1 participant