Skip to content

Commit

Permalink
doc: improve N-API string-to-native doc
Browse files Browse the repository at this point in the history
Mention null termination handling in the string size accounting and
string truncation.

PR-URL: nodejs#35322
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michael Dawson <midawson@redhat.com>
  • Loading branch information
Gabriel Schulhof authored and joesepi committed Oct 22, 2020
1 parent 25eb4c0 commit d566668
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions doc/api/n-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3080,9 +3080,10 @@ napi_status napi_get_value_string_latin1(napi_env env,
* `[in] env`: The environment that the API is invoked under.
* `[in] value`: `napi_value` representing JavaScript string.
* `[in] buf`: Buffer to write the ISO-8859-1-encoded string into. If `NULL` is
passed in, the length of the string (in bytes) is returned.
passed in, the length of the string in bytes and excluding the null terminator
is returned in `result`.
* `[in] bufsize`: Size of the destination buffer. When this value is
insufficient, the returned string will be truncated.
insufficient, the returned string will be truncated and null-terminated.
* `[out] result`: Number of bytes copied into the buffer, excluding the null
terminator.
Expand All @@ -3109,9 +3110,10 @@ napi_status napi_get_value_string_utf8(napi_env env,
* `[in] env`: The environment that the API is invoked under.
* `[in] value`: `napi_value` representing JavaScript string.
* `[in] buf`: Buffer to write the UTF8-encoded string into. If `NULL` is passed
in, the length of the string (in bytes) is returned.
in, the length of the string in bytes and excluding the null terminator is
returned in `result`.
* `[in] bufsize`: Size of the destination buffer. When this value is
insufficient, the returned string will be truncated.
insufficient, the returned string will be truncated and null-terminated.
* `[out] result`: Number of bytes copied into the buffer, excluding the null
terminator.

Expand All @@ -3137,9 +3139,10 @@ napi_status napi_get_value_string_utf16(napi_env env,
* `[in] env`: The environment that the API is invoked under.
* `[in] value`: `napi_value` representing JavaScript string.
* `[in] buf`: Buffer to write the UTF16-LE-encoded string into. If `NULL` is
passed in, the length of the string (in 2-byte code units) is returned.
passed in, the length of the string in 2-byte code units and excluding the
null terminator is returned.
* `[in] bufsize`: Size of the destination buffer. When this value is
insufficient, the returned string will be truncated.
insufficient, the returned string will be truncated and null-terminated.
* `[out] result`: Number of 2-byte code units copied into the buffer, excluding
the null terminator.
Expand Down

0 comments on commit d566668

Please sign in to comment.