Skip to content

Commit 0c67f21

Browse files
mhdawsonMylesBorins
authored andcommittedApr 16, 2018
doc: update to use NAPI_AUTO_LENGTH
Update so that doc says to use NAPI_AUTO_LENGTH instead of -1 to indicate null terminate string. Backport-PR-URL: #19447 PR-URL: #16187 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 5c2bba0 commit 0c67f21

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed
 

‎doc/api/n-api.md

+16-15
Original file line numberDiff line numberDiff line change
@@ -551,10 +551,11 @@ NAPI_NO_RETURN void napi_fatal_error(const char* location,
551551
```
552552

553553
- `[in] location`: Optional location at which the error occurred.
554-
- `[in] location_len`: The length of the location in bytes, or -1 if it is
555-
null-terminated.
554+
- `[in] location_len`: The length of the location in bytes, or
555+
NAPI_AUTO_LENGTH if it is null-terminated.
556556
- `[in] message`: The message associated with the error.
557-
- `[in] message_len`: The length of the message in bytes, or -1 if it is
557+
- `[in] message_len`: The length of the message in bytes, or
558+
NAPI_AUTO_LENGTH if it is
558559
null-terminated.
559560

560561
The function call does not return, the process will be terminated.
@@ -1256,8 +1257,8 @@ napi_status napi_create_function(napi_env env,
12561257
- `[in] env`: The environment that the API is invoked under.
12571258
- `[in] utf8name`: A string representing the name of the function encoded as
12581259
UTF8.
1259-
- `[in] length`: The length of the utf8name in bytes, or -1 if it is
1260-
null-terminated.
1260+
- `[in] length`: The length of the utf8name in bytes, or
1261+
NAPI_AUTO_LENGTH if it is null-terminated.
12611262
- `[in] cb`: A function pointer to the native function to be invoked when the
12621263
created function is invoked from JavaScript.
12631264
- `[in] data`: Optional arbitrary context data to be passed into the native
@@ -1489,8 +1490,8 @@ napi_status napi_create_string_latin1(napi_env env,
14891490

14901491
- `[in] env`: The environment that the API is invoked under.
14911492
- `[in] str`: Character buffer representing a ISO-8859-1-encoded string.
1492-
- `[in] length`: The length of the string in bytes, or -1 if it is
1493-
null-terminated.
1493+
- `[in] length`: The length of the string in bytes, or
1494+
NAPI_AUTO_LENGTH if it is null-terminated.
14941495
- `[out] result`: A `napi_value` representing a JavaScript String.
14951496

14961497
Returns `napi_ok` if the API succeeded.
@@ -1514,8 +1515,8 @@ napi_status napi_create_string_utf16(napi_env env,
15141515

15151516
- `[in] env`: The environment that the API is invoked under.
15161517
- `[in] str`: Character buffer representing a UTF16-LE-encoded string.
1517-
- `[in] length`: The length of the string in two-byte code units, or -1 if
1518-
it is null-terminated.
1518+
- `[in] length`: The length of the string in two-byte code units, or
1519+
NAPI_AUTO_LENGTH if it is null-terminated.
15191520
- `[out] result`: A `napi_value` representing a JavaScript String.
15201521

15211522
Returns `napi_ok` if the API succeeded.
@@ -1539,8 +1540,8 @@ napi_status napi_create_string_utf8(napi_env env,
15391540

15401541
- `[in] env`: The environment that the API is invoked under.
15411542
- `[in] str`: Character buffer representing a UTF8-encoded string.
1542-
- `[in] length`: The length of the string in bytes, or -1 if it is
1543-
null-terminated.
1543+
- `[in] length`: The length of the string in bytes, or NAPI_AUTO_LENGTH
1544+
if it is null-terminated.
15441545
- `[out] result`: A `napi_value` representing a JavaScript String.
15451546

15461547
Returns `napi_ok` if the API succeeded.
@@ -2304,7 +2305,7 @@ status = napi_create_array(env, &arr);
23042305
if (status != napi_ok) return status;
23052306

23062307
// Create a napi_value for 'hello'
2307-
status = napi_create_string_utf8(env, "hello", -1, &value);
2308+
status = napi_create_string_utf8(env, "hello", NAPI_AUTO_LENGTH, &value);
23082309
if (status != napi_ok) return status;
23092310

23102311
// arr[123] = 'hello';
@@ -2993,7 +2994,7 @@ status = napi_get_named_property(env, global, "MyObject", &constructor);
29932994
if (status != napi_ok) return;
29942995

29952996
// const arg = "hello"
2996-
status = napi_create_string_utf8(env, "hello", -1, &arg);
2997+
status = napi_create_string_utf8(env, "hello", NAPI_AUTO_LENGTH, &arg);
29972998
if (status != napi_ok) return;
29982999

29993000
napi_value* argv = &arg;
@@ -3040,8 +3041,8 @@ napi_status napi_define_class(napi_env env,
30403041
- `[in] utf8name`: Name of the JavaScript constructor function; this is
30413042
not required to be the same as the C++ class name, though it is recommended
30423043
for clarity.
3043-
- `[in] length`: The length of the utf8name in bytes, or -1 if it is
3044-
null-terminated.
3044+
- `[in] length`: The length of the utf8name in bytes, or NAPI_AUTO_LENGTH
3045+
if it is null-terminated.
30453046
- `[in] constructor`: Callback function that handles constructing instances
30463047
of the class. (This should be a static method on the class, not an actual
30473048
C++ constructor function.)

0 commit comments

Comments
 (0)
Please sign in to comment.