Skip to content

Commit a4cea0d

Browse files
committed
doc: clarify use of Uint8Array for n-api
`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. PR-URL: nodejs/node#48742 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Gabriel Schulhof <gabrielschulhof@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent a28f870 commit a4cea0d

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

graal-nodejs/doc/api/n-api.md

+15-6
Original file line numberDiff line numberDiff line change
@@ -3066,13 +3066,18 @@ napi_status napi_get_buffer_info(napi_env env,
30663066
```
30673067

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

30743075
Returns `napi_ok` if the API succeeded.
30753076

3077+
This method returns the identical `data` and `byte_length` as
3078+
[`napi_get_typedarray_info`][]. And `napi_get_typedarray_info` accepts a
3079+
`node::Buffer` (a Uint8Array) as the value too.
3080+
30763081
This API is used to retrieve the underlying data buffer of a `node::Buffer`
30773082
and its length.
30783083

@@ -3823,12 +3828,14 @@ napi_status napi_is_buffer(napi_env env, napi_value value, bool* result)
38233828

38243829
* `[in] env`: The environment that the API is invoked under.
38253830
* `[in] value`: The JavaScript value to check.
3826-
* `[out] result`: Whether the given `napi_value` represents a `node::Buffer`
3827-
object.
3831+
* `[out] result`: Whether the given `napi_value` represents a `node::Buffer` or
3832+
`Uint8Array` object.
38283833

38293834
Returns `napi_ok` if the API succeeded.
38303835

3831-
This API checks if the `Object` passed in is a buffer.
3836+
This API checks if the `Object` passed in is a buffer or Uint8Array.
3837+
[`napi_is_typedarray`][] should be preferred if the caller needs to check if the
3838+
value is a Uint8Array.
38323839

38333840
### `napi_is_date`
38343841

@@ -6498,11 +6505,13 @@ the add-on's file name during loading.
64986505
[`napi_get_last_error_info`]: #napi_get_last_error_info
64996506
[`napi_get_property`]: #napi_get_property
65006507
[`napi_get_reference_value`]: #napi_get_reference_value
6508+
[`napi_get_typedarray_info`]: #napi_get_typedarray_info
65016509
[`napi_get_value_external`]: #napi_get_value_external
65026510
[`napi_has_property`]: #napi_has_property
65036511
[`napi_instanceof`]: #napi_instanceof
65046512
[`napi_is_error`]: #napi_is_error
65056513
[`napi_is_exception_pending`]: #napi_is_exception_pending
6514+
[`napi_is_typedarray`]: #napi_is_typedarray
65066515
[`napi_make_callback`]: #napi_make_callback
65076516
[`napi_open_callback_scope`]: #napi_open_callback_scope
65086517
[`napi_open_escapable_handle_scope`]: #napi_open_escapable_handle_scope

0 commit comments

Comments
 (0)