fix(napi): normalize empty view data pointers#56
Open
GrapeBaBa wants to merge 6 commits into
Open
Conversation
# Conflicts: # examples/js_dsl/mod.test.ts # examples/js_dsl/mod.zig
GrapeBaBa
changed the base branch from
fix/napi-out-parameters
to
fix/napi-out-parameters-v2
July 20, 2026 12:09
GrapeBaBa
marked this pull request as ready for review
July 20, 2026 14:26
nazarhussain
approved these changes
Jul 22, 2026
nazarhussain
left a comment
Contributor
There was a problem hiding this comment.
Worth mentioning the CI does not run on this PR as it's target the main branch only. But I run the tests locally and all works fine.
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.
Motivation
Node-API permits ArrayBuffer, Buffer, TypedArray, and DataView data out parameters to be
NULLor an arbitrary pointer when the reported length is zero. This commonly occurs for empty and detached values. The previous binding received those results into non-null[*]u8storage, so a valid Node-API result could create a zero-length Zig slice whose pointer violates the slice type invariant. Normalizing this case at the binding boundary keeps the public slice API safe, while the TypedArray zero-length branch avoids applying element-alignment casts to an empty byte-slice sentinel.Summary
void*data out parameters as nullable Zig pointers