Skip to content

Commit

Permalink
doc: clarify use of Uint8Array for n-api
Browse files Browse the repository at this point in the history
`napi_get_buffer_info` always supported receiving `Uint8Array` as a
`value` argument because `node::Buffer` is a subclass of `Uint8Array`
and the underlying V8 APIs don't distinguish between two. With this
change we mark both types as supported by the API so that the user code
doesn't have to unknowingly use oficially unsupported type of the
`value` argument.
  • Loading branch information
indutny committed Jul 12, 2023
1 parent 0e9138d commit d664cf3
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions doc/api/n-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3122,9 +3122,10 @@ napi_status napi_get_buffer_info(napi_env env,
```

* `[in] env`: The environment that the API is invoked under.
* `[in] value`: `napi_value` representing the `node::Buffer` being queried.
* `[out] data`: The underlying data buffer of the `node::Buffer`.
If length is `0`, this may be `NULL` or any other pointer value.
* `[in] value`: `napi_value` representing the `node::Buffer` or `Uint8Array`
being queried.
* `[out] data`: The underlying data buffer of the `node::Buffer` or
`Uint8Array`. If length is `0`, this may be `NULL` or any other pointer value.
* `[out] length`: Length in bytes of the underlying data buffer.

Returns `napi_ok` if the API succeeded.
Expand Down Expand Up @@ -3879,8 +3880,8 @@ napi_status napi_is_buffer(napi_env env, napi_value value, bool* result)

* `[in] env`: The environment that the API is invoked under.
* `[in] value`: The JavaScript value to check.
* `[out] result`: Whether the given `napi_value` represents a `node::Buffer`
object.
* `[out] result`: Whether the given `napi_value` represents a `node::Buffer` or
`Uint8Array` object.

Returns `napi_ok` if the API succeeded.

Expand Down

0 comments on commit d664cf3

Please sign in to comment.