Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 07ba50a

Browse files
BridgeARtargos
authored andcommittedJan 13, 2020
doc: improve napi formatting
This addresses two nits: 1. Bullet points that span over multiple lines should be indented consitently. Otherwise they are not always properly highlighted. 2. Lines breaks after titles improve the readability. PR-URL: #30772 Reviewed-By: Beth Griggs <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent f6356fe commit 07ba50a

File tree

1 file changed

+180
-178
lines changed

1 file changed

+180
-178
lines changed
 

‎doc/api/n-api.md

+180-178
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,9 @@ napi_status napi_set_instance_data(napi_env env,
386386
* `[in] env`: The environment that the N-API call is invoked under.
387387
* `[in] data`: The data item to make available to bindings of this instance.
388388
* `[in] finalize_cb`: The function to call when the environment is being torn
389-
down. The function receives `data` so that it might free it.
390-
* `[in] finalize_hint`: Optional hint to pass to the finalize callback
391-
during collection.
389+
down. The function receives `data` so that it might free it.
390+
* `[in] finalize_hint`: Optional hint to pass to the finalize callback during
391+
collection.
392392

393393
Returns `napi_ok` if the API succeeded.
394394

@@ -410,7 +410,7 @@ napi_status napi_get_instance_data(napi_env env,
410410

411411
* `[in] env`: The environment that the N-API call is invoked under.
412412
* `[out] data`: The data item that was previously associated with the currently
413-
running Agent by a call to `napi_set_instance_data()`.
413+
running Agent by a call to `napi_set_instance_data()`.
414414

415415
Returns `napi_ok` if the API succeeded.
416416

@@ -487,6 +487,7 @@ typedef struct {
487487
See the [Error Handling][] section for additional information.
488488

489489
### napi_env
490+
490491
`napi_env` is used to represent a context that the underlying N-API
491492
implementation can use to persist VM-specific state. This structure is passed
492493
to native functions when they're invoked, and it must be passed back when
@@ -496,6 +497,7 @@ nested N-API calls. Caching the `napi_env` for the purpose of general reuse is
496497
not allowed.
497498

498499
### napi_value
500+
499501
This is an opaque pointer that is used to represent a JavaScript value.
500502

501503
### napi_threadsafe_function
@@ -545,6 +547,7 @@ typedef enum {
545547

546548
### N-API Memory Management types
547549
#### napi_handle_scope
550+
548551
This is an abstraction used to control and modify the lifetime of objects
549552
created within a particular scope. In general, N-API values are created within
550553
the context of a handle scope. When a native method is called from
@@ -685,23 +688,26 @@ typedef void (*napi_threadsafe_function_call_js)(napi_env env,
685688
```
686689

687690
* `[in] env`: The environment to use for API calls, or `NULL` if the thread-safe
688-
function is being torn down and `data` may need to be freed.
691+
function is being torn down and `data` may need to be freed.
689692
* `[in] js_callback`: The JavaScript function to call, or `NULL` if the
690-
thread-safe function is being torn down and `data` may need to be freed. It may
691-
also be `NULL` if the thread-safe function was created without `js_callback`.
693+
thread-safe function is being torn down and `data` may need to be freed. It
694+
may also be `NULL` if the thread-safe function was created without
695+
`js_callback`.
692696
* `[in] context`: The optional data with which the thread-safe function was
693-
created.
697+
created.
694698
* `[in] data`: Data created by the secondary thread. It is the responsibility of
695-
the callback to convert this native data to JavaScript values (with N-API
696-
functions) that can be passed as parameters when `js_callback` is invoked. This
697-
pointer is managed entirely by the threads and this callback. Thus this callback
698-
should free the data.
699+
the callback to convert this native data to JavaScript values (with N-API
700+
functions) that can be passed as parameters when `js_callback` is invoked.
701+
This pointer is managed entirely by the threads and this callback. Thus this
702+
callback should free the data.
699703

700704
## Error Handling
705+
701706
N-API uses both return values and JavaScript exceptions for error handling.
702707
The following sections explain the approach for each case.
703708

704709
### Return values
710+
705711
All of the N-API functions share the same error handling pattern. The
706712
return type of all API functions is `napi_status`.
707713

@@ -785,6 +791,7 @@ logging purposes.
785791
This API can be called even if there is a pending JavaScript exception.
786792

787793
### Exceptions
794+
788795
Any N-API function call may result in a pending JavaScript exception. This is
789796
obviously the case for any function that may cause the execution of
790797
JavaScript, but N-API specifies that an exception may be pending
@@ -895,8 +902,7 @@ NAPI_EXTERN napi_status napi_throw_error(napi_env env,
895902

896903
* `[in] env`: The environment that the API is invoked under.
897904
* `[in] code`: Optional error code to be set on the error.
898-
* `[in] msg`: C string representing the text to be associated with
899-
the error.
905+
* `[in] msg`: C string representing the text to be associated with the error.
900906

901907
Returns `napi_ok` if the API succeeded.
902908

@@ -916,8 +922,7 @@ NAPI_EXTERN napi_status napi_throw_type_error(napi_env env,
916922

917923
* `[in] env`: The environment that the API is invoked under.
918924
* `[in] code`: Optional error code to be set on the error.
919-
* `[in] msg`: C string representing the text to be associated with
920-
the error.
925+
* `[in] msg`: C string representing the text to be associated with the error.
921926

922927
Returns `napi_ok` if the API succeeded.
923928

@@ -937,8 +942,7 @@ NAPI_EXTERN napi_status napi_throw_range_error(napi_env env,
937942

938943
* `[in] env`: The environment that the API is invoked under.
939944
* `[in] code`: Optional error code to be set on the error.
940-
* `[in] msg`: C string representing the text to be associated with
941-
the error.
945+
* `[in] msg`: C string representing the text to be associated with the error.
942946

943947
Returns `napi_ok` if the API succeeded.
944948

@@ -959,7 +963,7 @@ NAPI_EXTERN napi_status napi_is_error(napi_env env,
959963
* `[in] env`: The environment that the API is invoked under.
960964
* `[in] value`: The `napi_value` to be checked.
961965
* `[out] result`: Boolean value that is set to true if `napi_value` represents
962-
an error, false otherwise.
966+
an error, false otherwise.
963967

964968
Returns `napi_ok` if the API succeeded.
965969

@@ -979,10 +983,10 @@ NAPI_EXTERN napi_status napi_create_error(napi_env env,
979983
```
980984

981985
* `[in] env`: The environment that the API is invoked under.
982-
* `[in] code`: Optional `napi_value` with the string for the error code to
983-
be associated with the error.
984-
* `[in] msg`: `napi_value` that references a JavaScript `String` to be
985-
used as the message for the `Error`.
986+
* `[in] code`: Optional `napi_value` with the string for the error code to be
987+
associated with the error.
988+
* `[in] msg`: `napi_value` that references a JavaScript `String` to be used as
989+
the message for the `Error`.
986990
* `[out] result`: `napi_value` representing the error created.
987991

988992
Returns `napi_ok` if the API succeeded.
@@ -1003,10 +1007,10 @@ NAPI_EXTERN napi_status napi_create_type_error(napi_env env,
10031007
```
10041008

10051009
* `[in] env`: The environment that the API is invoked under.
1006-
* `[in] code`: Optional `napi_value` with the string for the error code to
1007-
be associated with the error.
1008-
* `[in] msg`: `napi_value` that references a JavaScript `String` to be
1009-
used as the message for the `Error`.
1010+
* `[in] code`: Optional `napi_value` with the string for the error code to be
1011+
associated with the error.
1012+
* `[in] msg`: `napi_value` that references a JavaScript `String` to be used as
1013+
the message for the `Error`.
10101014
* `[out] result`: `napi_value` representing the error created.
10111015

10121016
Returns `napi_ok` if the API succeeded.
@@ -1027,10 +1031,10 @@ NAPI_EXTERN napi_status napi_create_range_error(napi_env env,
10271031
```
10281032

10291033
* `[in] env`: The environment that the API is invoked under.
1030-
* `[in] code`: Optional `napi_value` with the string for the error code to
1031-
be associated with the error.
1032-
* `[in] msg`: `napi_value` that references a JavaScript `String` to be
1033-
used as the message for the `Error`.
1034+
* `[in] code`: Optional `napi_value` with the string for the error code to be
1035+
associated with the error.
1036+
* `[in] msg`: `napi_value` that references a JavaScript `String` to be used as
1037+
the message for the `Error`.
10341038
* `[out] result`: `napi_value` representing the error created.
10351039

10361040
Returns `napi_ok` if the API succeeded.
@@ -1112,11 +1116,10 @@ NAPI_NO_RETURN void napi_fatal_error(const char* location,
11121116

11131117
* `[in] location`: Optional location at which the error occurred.
11141118
* `[in] location_len`: The length of the location in bytes, or
1115-
`NAPI_AUTO_LENGTH` if it is null-terminated.
1119+
`NAPI_AUTO_LENGTH` if it is null-terminated.
11161120
* `[in] message`: The message associated with the error.
1117-
* `[in] message_len`: The length of the message in bytes, or
1118-
`NAPI_AUTO_LENGTH` if it is
1119-
null-terminated.
1121+
* `[in] message_len`: The length of the message in bytes, or `NAPI_AUTO_LENGTH`
1122+
if it is null-terminated.
11201123

11211124
The function call does not return, the process will be terminated.
11221125

@@ -1309,9 +1312,9 @@ napi_status napi_escape_handle(napi_env env,
13091312
* `[in] env`: The environment that the API is invoked under.
13101313
* `[in] scope`: `napi_value` representing the current scope.
13111314
* `[in] escapee`: `napi_value` representing the JavaScript `Object` to be
1312-
escaped.
1313-
* `[out] result`: `napi_value` representing the handle to the escaped
1314-
`Object` in the outer scope.
1315+
escaped.
1316+
* `[out] result`: `napi_value` representing the handle to the escaped `Object`
1317+
in the outer scope.
13151318

13161319
Returns `napi_ok` if the API succeeded.
13171320

@@ -1374,8 +1377,8 @@ NAPI_EXTERN napi_status napi_create_reference(napi_env env,
13741377
```
13751378

13761379
* `[in] env`: The environment that the API is invoked under.
1377-
* `[in] value`: `napi_value` representing the `Object` to which we want
1378-
a reference.
1380+
* `[in] value`: `napi_value` representing the `Object` to which we want a
1381+
reference.
13791382
* `[in] initial_refcount`: Initial reference count for the new reference.
13801383
* `[out] result`: `napi_ref` pointing to the new reference.
13811384

@@ -1463,7 +1466,7 @@ object to which the reference is related.
14631466
* `[in] env`: The environment that the API is invoked under.
14641467
* `[in] ref`: `napi_ref` for which we requesting the corresponding `Object`.
14651468
* `[out] result`: The `napi_value` for the `Object` referenced by the
1466-
`napi_ref`.
1469+
`napi_ref`.
14671470

14681471
Returns `napi_ok` if the API succeeded.
14691472

@@ -1825,8 +1828,8 @@ napi_status napi_create_buffer_copy(napi_env env,
18251828
```
18261829

18271830
* `[in] env`: The environment that the API is invoked under.
1828-
* `[in] size`: Size in bytes of the input buffer (should be the same as the
1829-
size of the new buffer).
1831+
* `[in] size`: Size in bytes of the input buffer (should be the same as the size
1832+
of the new buffer).
18301833
* `[in] data`: Raw pointer to the underlying buffer to copy from.
18311834
* `[out] result_data`: Pointer to the new `Buffer`'s underlying data buffer.
18321835
* `[out] result`: A `napi_value` representing a `node::Buffer`.
@@ -1879,10 +1882,10 @@ napi_status napi_create_external(napi_env env,
18791882

18801883
* `[in] env`: The environment that the API is invoked under.
18811884
* `[in] data`: Raw pointer to the external data.
1882-
* `[in] finalize_cb`: Optional callback to call when the external value
1883-
is being collected.
1884-
* `[in] finalize_hint`: Optional hint to pass to the finalize callback
1885-
during collection.
1885+
* `[in] finalize_cb`: Optional callback to call when the external value is being
1886+
collected.
1887+
* `[in] finalize_hint`: Optional hint to pass to the finalize callback during
1888+
collection.
18861889
* `[out] result`: A `napi_value` representing an external value.
18871890

18881891
Returns `napi_ok` if the API succeeded.
@@ -1921,12 +1924,12 @@ napi_create_external_arraybuffer(napi_env env,
19211924

19221925
* `[in] env`: The environment that the API is invoked under.
19231926
* `[in] external_data`: Pointer to the underlying byte buffer of the
1924-
`ArrayBuffer`.
1927+
`ArrayBuffer`.
19251928
* `[in] byte_length`: The length in bytes of the underlying buffer.
1926-
* `[in] finalize_cb`: Optional callback to call when the `ArrayBuffer` is
1927-
being collected.
1928-
* `[in] finalize_hint`: Optional hint to pass to the finalize callback
1929-
during collection.
1929+
* `[in] finalize_cb`: Optional callback to call when the `ArrayBuffer` is being
1930+
collected.
1931+
* `[in] finalize_hint`: Optional hint to pass to the finalize callback during
1932+
collection.
19301933
* `[out] result`: A `napi_value` representing a JavaScript `ArrayBuffer`.
19311934

19321935
Returns `napi_ok` if the API succeeded.
@@ -1963,13 +1966,13 @@ napi_status napi_create_external_buffer(napi_env env,
19631966
```
19641967

19651968
* `[in] env`: The environment that the API is invoked under.
1966-
* `[in] length`: Size in bytes of the input buffer (should be the same as
1967-
the size of the new buffer).
1969+
* `[in] length`: Size in bytes of the input buffer (should be the same as the
1970+
size of the new buffer).
19681971
* `[in] data`: Raw pointer to the underlying buffer to copy from.
1969-
* `[in] finalize_cb`: Optional callback to call when the `ArrayBuffer` is
1970-
being collected.
1971-
* `[in] finalize_hint`: Optional hint to pass to the finalize callback
1972-
during collection.
1972+
* `[in] finalize_cb`: Optional callback to call when the `ArrayBuffer` is being
1973+
collected.
1974+
* `[in] finalize_hint`: Optional hint to pass to the finalize callback during
1975+
collection.
19731976
* `[out] result`: A `napi_value` representing a `node::Buffer`.
19741977

19751978
Returns `napi_ok` if the API succeeded.
@@ -2023,7 +2026,7 @@ napi_status napi_create_symbol(napi_env env,
20232026

20242027
* `[in] env`: The environment that the API is invoked under.
20252028
* `[in] description`: Optional `napi_value` which refers to a JavaScript
2026-
`String` to be set as the description for the symbol.
2029+
`String` to be set as the description for the symbol.
20272030
* `[out] result`: A `napi_value` representing a JavaScript `Symbol`.
20282031

20292032
Returns `napi_ok` if the API succeeded.
@@ -2053,7 +2056,7 @@ napi_status napi_create_typedarray(napi_env env,
20532056
* `[in] length`: Number of elements in the `TypedArray`.
20542057
* `[in] arraybuffer`: `ArrayBuffer` underlying the typed array.
20552058
* `[in] byte_offset`: The byte offset within the `ArrayBuffer` from which to
2056-
start projecting the `TypedArray`.
2059+
start projecting the `TypedArray`.
20572060
* `[out] result`: A `napi_value` representing a JavaScript `TypedArray`.
20582061

20592062
Returns `napi_ok` if the API succeeded.
@@ -2283,8 +2286,8 @@ napi_status napi_create_string_latin1(napi_env env,
22832286

22842287
* `[in] env`: The environment that the API is invoked under.
22852288
* `[in] str`: Character buffer representing an ISO-8859-1-encoded string.
2286-
* `[in] length`: The length of the string in bytes, or
2287-
`NAPI_AUTO_LENGTH` if it is null-terminated.
2289+
* `[in] length`: The length of the string in bytes, or `NAPI_AUTO_LENGTH` if it
2290+
is null-terminated.
22882291
* `[out] result`: A `napi_value` representing a JavaScript `String`.
22892292

22902293
Returns `napi_ok` if the API succeeded.
@@ -2311,7 +2314,7 @@ napi_status napi_create_string_utf16(napi_env env,
23112314
* `[in] env`: The environment that the API is invoked under.
23122315
* `[in] str`: Character buffer representing a UTF16-LE-encoded string.
23132316
* `[in] length`: The length of the string in two-byte code units, or
2314-
`NAPI_AUTO_LENGTH` if it is null-terminated.
2317+
`NAPI_AUTO_LENGTH` if it is null-terminated.
23152318
* `[out] result`: A `napi_value` representing a JavaScript `String`.
23162319

23172320
Returns `napi_ok` if the API succeeded.
@@ -2337,8 +2340,8 @@ napi_status napi_create_string_utf8(napi_env env,
23372340

23382341
* `[in] env`: The environment that the API is invoked under.
23392342
* `[in] str`: Character buffer representing a UTF8-encoded string.
2340-
* `[in] length`: The length of the string in bytes, or `NAPI_AUTO_LENGTH`
2341-
if it is null-terminated.
2343+
* `[in] length`: The length of the string in bytes, or `NAPI_AUTO_LENGTH` if it
2344+
is null-terminated.
23422345
* `[out] result`: A `napi_value` representing a JavaScript `String`.
23432346

23442347
Returns `napi_ok` if the API succeeded.
@@ -2364,7 +2367,7 @@ napi_status napi_get_array_length(napi_env env,
23642367

23652368
* `[in] env`: The environment that the API is invoked under.
23662369
* `[in] value`: `napi_value` representing the JavaScript `Array` whose length is
2367-
being queried.
2370+
being queried.
23682371
* `[out] result`: `uint32` representing length of the array.
23692372

23702373
Returns `napi_ok` if the API succeeded.
@@ -2445,8 +2448,8 @@ napi_status napi_get_prototype(napi_env env,
24452448

24462449
* `[in] env`: The environment that the API is invoked under.
24472450
* `[in] object`: `napi_value` representing JavaScript `Object` whose prototype
2448-
to return. This returns the equivalent of `Object.getPrototypeOf` (which is
2449-
not the same as the function's `prototype` property).
2451+
to return. This returns the equivalent of `Object.getPrototypeOf` (which is
2452+
not the same as the function's `prototype` property).
24502453
* `[out] result`: `napi_value` representing prototype of the given object.
24512454

24522455
Returns `napi_ok` if the API succeeded.
@@ -2531,8 +2534,8 @@ napi_status napi_get_date_value(napi_env env,
25312534

25322535
* `[in] env`: The environment that the API is invoked under.
25332536
* `[in] value`: `napi_value` representing a JavaScript `Date`.
2534-
* `[out] result`: Time value as a `double` represented as milliseconds
2535-
since midnight at the beginning of 01 January, 1970 UTC.
2537+
* `[out] result`: Time value as a `double` represented as milliseconds since
2538+
midnight at the beginning of 01 January, 1970 UTC.
25362539

25372540
This API does not observe leap seconds; they are ignored, as
25382541
ECMAScript aligns with POSIX time specification.
@@ -2556,7 +2559,7 @@ napi_status napi_get_value_bool(napi_env env, napi_value value, bool* result)
25562559
* `[in] env`: The environment that the API is invoked under.
25572560
* `[in] value`: `napi_value` representing JavaScript `Boolean`.
25582561
* `[out] result`: C boolean primitive equivalent of the given JavaScript
2559-
`Boolean`.
2562+
`Boolean`.
25602563

25612564
Returns `napi_ok` if the API succeeded. If a non-boolean `napi_value` is
25622565
passed in it returns `napi_boolean_expected`.
@@ -2579,7 +2582,7 @@ napi_status napi_get_value_double(napi_env env,
25792582
* `[in] env`: The environment that the API is invoked under.
25802583
* `[in] value`: `napi_value` representing JavaScript `Number`.
25812584
* `[out] result`: C double primitive equivalent of the given JavaScript
2582-
`Number`.
2585+
`Number`.
25832586

25842587
Returns `napi_ok` if the API succeeded. If a non-number `napi_value` is passed
25852588
in it returns `napi_number_expected`.
@@ -2769,11 +2772,11 @@ napi_status napi_get_value_string_latin1(napi_env env,
27692772
* `[in] env`: The environment that the API is invoked under.
27702773
* `[in] value`: `napi_value` representing JavaScript string.
27712774
* `[in] buf`: Buffer to write the ISO-8859-1-encoded string into. If NULL is
2772-
passed in, the length of the string (in bytes) is returned.
2775+
passed in, the length of the string (in bytes) is returned.
27732776
* `[in] bufsize`: Size of the destination buffer. When this value is
2774-
insufficient, the returned string will be truncated.
2777+
insufficient, the returned string will be truncated.
27752778
* `[out] result`: Number of bytes copied into the buffer, excluding the null
2776-
terminator.
2779+
terminator.
27772780

27782781
Returns `napi_ok` if the API succeeded. If a non-`String` `napi_value`
27792782
is passed in it returns `napi_string_expected`.
@@ -2798,11 +2801,11 @@ napi_status napi_get_value_string_utf8(napi_env env,
27982801
* `[in] env`: The environment that the API is invoked under.
27992802
* `[in] value`: `napi_value` representing JavaScript string.
28002803
* `[in] buf`: Buffer to write the UTF8-encoded string into. If NULL is passed
2801-
in, the length of the string (in bytes) is returned.
2804+
in, the length of the string (in bytes) is returned.
28022805
* `[in] bufsize`: Size of the destination buffer. When this value is
2803-
insufficient, the returned string will be truncated.
2806+
insufficient, the returned string will be truncated.
28042807
* `[out] result`: Number of bytes copied into the buffer, excluding the null
2805-
terminator.
2808+
terminator.
28062809

28072810
Returns `napi_ok` if the API succeeded. If a non-`String` `napi_value`
28082811
is passed in it returns `napi_string_expected`.
@@ -2826,11 +2829,11 @@ napi_status napi_get_value_string_utf16(napi_env env,
28262829
* `[in] env`: The environment that the API is invoked under.
28272830
* `[in] value`: `napi_value` representing JavaScript string.
28282831
* `[in] buf`: Buffer to write the UTF16-LE-encoded string into. If NULL is
2829-
passed in, the length of the string (in 2-byte code units) is returned.
2832+
passed in, the length of the string (in 2-byte code units) is returned.
28302833
* `[in] bufsize`: Size of the destination buffer. When this value is
2831-
insufficient, the returned string will be truncated.
2834+
insufficient, the returned string will be truncated.
28322835
* `[out] result`: Number of 2-byte code units copied into the buffer, excluding
2833-
the null terminator.
2836+
the null terminator.
28342837

28352838
Returns `napi_ok` if the API succeeded. If a non-`String` `napi_value`
28362839
is passed in it returns `napi_string_expected`.
@@ -2852,7 +2855,7 @@ napi_status napi_get_value_uint32(napi_env env,
28522855
* `[in] env`: The environment that the API is invoked under.
28532856
* `[in] value`: `napi_value` representing JavaScript `Number`.
28542857
* `[out] result`: C primitive equivalent of the given `napi_value` as a
2855-
`uint32_t`.
2858+
`uint32_t`.
28562859

28572860
Returns `napi_ok` if the API succeeded. If a non-number `napi_value`
28582861
is passed in it returns `napi_number_expected`.
@@ -2874,7 +2877,7 @@ napi_status napi_get_boolean(napi_env env, bool value, napi_value* result)
28742877
* `[in] env`: The environment that the API is invoked under.
28752878
* `[in] value`: The value of the boolean to retrieve.
28762879
* `[out] result`: `napi_value` representing JavaScript `Boolean` singleton to
2877-
retrieve.
2880+
retrieve.
28782881

28792882
Returns `napi_ok` if the API succeeded.
28802883

@@ -3072,10 +3075,10 @@ napi_status napi_instanceof(napi_env env,
30723075

30733076
* `[in] env`: The environment that the API is invoked under.
30743077
* `[in] object`: The JavaScript value to check.
3075-
* `[in] constructor`: The JavaScript function object of the constructor
3076-
function to check against.
3078+
* `[in] constructor`: The JavaScript function object of the constructor function
3079+
to check against.
30773080
* `[out] result`: Boolean that is set to true if `object instanceof constructor`
3078-
is true.
3081+
is true.
30793082

30803083
Returns `napi_ok` if the API succeeded.
30813084

@@ -3132,7 +3135,7 @@ napi_status napi_is_buffer(napi_env env, napi_value value, bool* result)
31323135
* `[in] env`: The environment that the API is invoked under.
31333136
* `[in] value`: The JavaScript value to check.
31343137
* `[out] result`: Whether the given `napi_value` represents a `node::Buffer`
3135-
object.
3138+
object.
31363139

31373140
Returns `napi_ok` if the API succeeded.
31383141

@@ -3151,7 +3154,7 @@ napi_status napi_is_date(napi_env env, napi_value value, bool* result)
31513154
* `[in] env`: The environment that the API is invoked under.
31523155
* `[in] value`: The JavaScript value to check.
31533156
* `[out] result`: Whether the given `napi_value` represents a JavaScript `Date`
3154-
object.
3157+
object.
31553158

31563159
Returns `napi_ok` if the API succeeded.
31573160

@@ -3451,32 +3454,32 @@ typedef struct {
34513454
```
34523455

34533456
* `utf8name`: Optional `String` describing the key for the property,
3454-
encoded as UTF8. One of `utf8name` or `name` must be provided for the
3455-
property.
3457+
encoded as UTF8. One of `utf8name` or `name` must be provided for the
3458+
property.
34563459
* `name`: Optional `napi_value` that points to a JavaScript string or symbol
3457-
to be used as the key for the property. One of `utf8name` or `name` must
3458-
be provided for the property.
3460+
to be used as the key for the property. One of `utf8name` or `name` must
3461+
be provided for the property.
34593462
* `value`: The value that's retrieved by a get access of the property if the
3460-
property is a data property. If this is passed in, set `getter`, `setter`,
3461-
`method` and `data` to `NULL` (since these members won't be used).
3463+
property is a data property. If this is passed in, set `getter`, `setter`,
3464+
`method` and `data` to `NULL` (since these members won't be used).
34623465
* `getter`: A function to call when a get access of the property is performed.
3463-
If this is passed in, set `value` and `method` to `NULL` (since these members
3464-
won't be used). The given function is called implicitly by the runtime when the
3465-
property is accessed from JavaScript code (or if a get on the property is
3466-
performed using a N-API call).
3466+
If this is passed in, set `value` and `method` to `NULL` (since these members
3467+
won't be used). The given function is called implicitly by the runtime when
3468+
the property is accessed from JavaScript code (or if a get on the property is
3469+
performed using a N-API call).
34673470
* `setter`: A function to call when a set access of the property is performed.
3468-
If this is passed in, set `value` and `method` to `NULL` (since these members
3469-
won't be used). The given function is called implicitly by the runtime when the
3470-
property is set from JavaScript code (or if a set on the property is
3471-
performed using a N-API call).
3471+
If this is passed in, set `value` and `method` to `NULL` (since these members
3472+
won't be used). The given function is called implicitly by the runtime when
3473+
the property is set from JavaScript code (or if a set on the property is
3474+
performed using a N-API call).
34723475
* `method`: Set this to make the property descriptor object's `value`
3473-
property to be a JavaScript function represented by `method`. If this is
3474-
passed in, set `value`, `getter` and `setter` to `NULL` (since these members
3475-
won't be used).
3476-
* `attributes`: The attributes associated with the particular property.
3477-
See [`napi_property_attributes`][].
3478-
* `data`: The callback data passed into `method`, `getter` and `setter` if
3479-
this function is invoked.
3476+
property to be a JavaScript function represented by `method`. If this is
3477+
passed in, set `value`, `getter` and `setter` to `NULL` (since these members
3478+
won't be used).
3479+
* `attributes`: The attributes associated with the particular property. See
3480+
[`napi_property_attributes`][].
3481+
* `data`: The callback data passed into `method`, `getter` and `setter` if this
3482+
function is invoked.
34803483

34813484
### Functions
34823485
#### napi_get_property_names
@@ -3494,9 +3497,9 @@ napi_status napi_get_property_names(napi_env env,
34943497
* `[in] env`: The environment that the N-API call is invoked under.
34953498
* `[in] object`: The object from which to retrieve the properties.
34963499
* `[out] result`: A `napi_value` representing an array of JavaScript values
3497-
that represent the property names of the object. The API can be used to
3498-
iterate over `result` using [`napi_get_array_length`][]
3499-
and [`napi_get_element`][].
3500+
that represent the property names of the object. The API can be used to
3501+
iterate over `result` using [`napi_get_array_length`][]
3502+
and [`napi_get_element`][].
35003503

35013504
Returns `napi_ok` if the API succeeded.
35023505

@@ -3587,7 +3590,7 @@ napi_status napi_delete_property(napi_env env,
35873590
* `[in] object`: The object to query.
35883591
* `[in] key`: The name of the property to delete.
35893592
* `[out] result`: Whether the property deletion succeeded or not. `result` can
3590-
optionally be ignored by passing `NULL`.
3593+
optionally be ignored by passing `NULL`.
35913594

35923595
Returns `napi_ok` if the API succeeded.
35933596

@@ -3770,7 +3773,7 @@ napi_status napi_delete_element(napi_env env,
37703773
* `[in] object`: The object to query.
37713774
* `[in] index`: The index of the property to delete.
37723775
* `[out] result`: Whether the element deletion succeeded or not. `result` can
3773-
optionally be ignored by passing `NULL`.
3776+
optionally be ignored by passing `NULL`.
37743777

37753778
Returns `napi_ok` if the API succeeded.
37763779

@@ -3844,11 +3847,10 @@ NAPI_EXTERN napi_status napi_call_function(napi_env env,
38443847

38453848
* `[in] env`: The environment that the API is invoked under.
38463849
* `[in] recv`: The `this` object passed to the called function.
3847-
* `[in] func`: `napi_value` representing the JavaScript function
3848-
to be invoked.
3850+
* `[in] func`: `napi_value` representing the JavaScript function to be invoked.
38493851
* `[in] argc`: The count of elements in the `argv` array.
3850-
* `[in] argv`: Array of `napi_values` representing JavaScript values passed
3851-
in as arguments to the function.
3852+
* `[in] argv`: Array of `napi_values` representing JavaScript values passed in
3853+
as arguments to the function.
38523854
* `[out] result`: `napi_value` representing the JavaScript object returned.
38533855

38543856
Returns `napi_ok` if the API succeeded.
@@ -3914,15 +3916,15 @@ napi_status napi_create_function(napi_env env,
39143916

39153917
* `[in] env`: The environment that the API is invoked under.
39163918
* `[in] utf8Name`: The name of the function encoded as UTF8. This is visible
3917-
within JavaScript as the new function object's `name` property.
3918-
* `[in] length`: The length of the `utf8name` in bytes, or
3919-
`NAPI_AUTO_LENGTH` if it is null-terminated.
3919+
within JavaScript as the new function object's `name` property.
3920+
* `[in] length`: The length of the `utf8name` in bytes, or `NAPI_AUTO_LENGTH` if
3921+
it is null-terminated.
39203922
* `[in] cb`: The native function which should be called when this function
3921-
object is invoked.
3923+
object is invoked.
39223924
* `[in] data`: User-provided data context. This will be passed back into the
3923-
function when invoked later.
3925+
function when invoked later.
39243926
* `[out] result`: `napi_value` representing the JavaScript function object for
3925-
the newly created function.
3927+
the newly created function.
39263928

39273929
Returns `napi_ok` if the API succeeded.
39283930

@@ -3995,13 +3997,13 @@ napi_status napi_get_cb_info(napi_env env,
39953997

39963998
* `[in] env`: The environment that the API is invoked under.
39973999
* `[in] cbinfo`: The callback info passed into the callback function.
3998-
* `[in-out] argc`: Specifies the size of the provided `argv` array
3999-
and receives the actual count of arguments.
4000-
* `[out] argv`: Buffer to which the `napi_value` representing the
4001-
arguments are copied. If there are more arguments than the provided
4002-
count, only the requested number of arguments are copied. If there are fewer
4003-
arguments provided than claimed, the rest of `argv` is filled with `napi_value`
4004-
values that represent `undefined`.
4000+
* `[in-out] argc`: Specifies the size of the provided `argv` array and receives
4001+
the actual count of arguments.
4002+
* `[out] argv`: Buffer to which the `napi_value` representing the arguments are
4003+
copied. If there are more arguments than the provided count, only the
4004+
requested number of arguments are copied. If there are fewer arguments
4005+
provided than claimed, the rest of `argv` is filled with `napi_value` values
4006+
that represent `undefined`.
40054007
* `[out] this`: Receives the JavaScript `this` argument for the call.
40064008
* `[out] data`: Receives the data pointer for the callback.
40074009

@@ -4046,13 +4048,13 @@ napi_status napi_new_instance(napi_env env,
40464048
```
40474049

40484050
* `[in] env`: The environment that the API is invoked under.
4049-
* `[in] cons`: `napi_value` representing the JavaScript function
4050-
to be invoked as a constructor.
4051+
* `[in] cons`: `napi_value` representing the JavaScript function to be invoked
4052+
as a constructor.
40514053
* `[in] argc`: The count of elements in the `argv` array.
4052-
* `[in] argv`: Array of JavaScript values as `napi_value`
4053-
representing the arguments to the constructor.
4054+
* `[in] argv`: Array of JavaScript values as `napi_value` representing the
4055+
arguments to the constructor.
40544056
* `[out] result`: `napi_value` representing the JavaScript object returned,
4055-
which in this case is the constructed object.
4057+
which in this case is the constructed object.
40564058

40574059
This method is used to instantiate a new JavaScript value using a given
40584060
`napi_value` that represents the constructor for the object. For example,
@@ -4423,18 +4425,18 @@ napi_status napi_create_async_work(napi_env env,
44234425
* `[in] env`: The environment that the API is invoked under.
44244426
* `[in] async_resource`: An optional object associated with the async work
44254427
that will be passed to possible `async_hooks` [`init` hooks][].
4426-
* `[in] async_resource_name`: Identifier for the kind of resource that is
4427-
being provided for diagnostic information exposed by the `async_hooks` API.
4428-
* `[in] execute`: The native function which should be called to execute
4429-
the logic asynchronously. The given function is called from a worker pool
4430-
thread and can execute in parallel with the main event loop thread.
4428+
* `[in] async_resource_name`: Identifier for the kind of resource that is being
4429+
provided for diagnostic information exposed by the `async_hooks` API.
4430+
* `[in] execute`: The native function which should be called to execute the
4431+
logic asynchronously. The given function is called from a worker pool thread
4432+
and can execute in parallel with the main event loop thread.
44314433
* `[in] complete`: The native function which will be called when the
4432-
asynchronous logic is completed or is cancelled. The given function is called
4433-
from the main event loop thread.
4434+
asynchronous logic is completed or is cancelled. The given function is called
4435+
from the main event loop thread.
44344436
* `[in] data`: User-provided data context. This will be passed back into the
4435-
execute and complete functions.
4437+
execute and complete functions.
44364438
* `[out] result`: `napi_async_work*` which is the handle to the newly created
4437-
async work.
4439+
async work.
44384440

44394441
Returns `napi_ok` if the API succeeded.
44404442

@@ -4515,6 +4517,7 @@ callback invocation, even if it has been successfully cancelled.
45154517
This API can be called even if there is a pending JavaScript exception.
45164518

45174519
## Custom Asynchronous Operations
4520+
45184521
The simple asynchronous work APIs above may not be appropriate for every
45194522
scenario. When using any other asynchronous mechanism, the following APIs
45204523
are necessary to ensure an asynchronous operation is properly tracked by
@@ -4587,11 +4590,10 @@ NAPI_EXTERN napi_status napi_make_callback(napi_env env,
45874590
which indicates the current async context (if any) is to be used
45884591
for the callback.
45894592
* `[in] recv`: The `this` object passed to the called function.
4590-
* `[in] func`: `napi_value` representing the JavaScript function
4591-
to be invoked.
4593+
* `[in] func`: `napi_value` representing the JavaScript function to be invoked.
45924594
* `[in] argc`: The count of elements in the `argv` array.
4593-
* `[in] argv`: Array of JavaScript values as `napi_value`
4594-
representing the arguments to the function.
4595+
* `[in] argv`: Array of JavaScript values as `napi_value` representing the
4596+
arguments to the function.
45954597
* `[out] result`: `napi_value` representing the JavaScript object returned.
45964598

45974599
Returns `napi_ok` if the API succeeded.
@@ -4625,9 +4627,8 @@ NAPI_EXTERN napi_status napi_open_callback_scope(napi_env env,
46254627
* `[in] env`: The environment that the API is invoked under.
46264628
* `[in] resource_object`: An object associated with the async work
46274629
that will be passed to possible `async_hooks` [`init` hooks][].
4628-
* `[in] context`: Context for the async operation that is
4629-
invoking the callback. This should be a value previously obtained
4630-
from [`napi_async_init`][].
4630+
* `[in] context`: Context for the async operation that is invoking the callback.
4631+
This should be a value previously obtained from [`napi_async_init`][].
46314632
* `[out] result`: The newly created scope.
46324633

46334634
There are cases (for example, resolving promises) where it is
@@ -4729,8 +4730,8 @@ NAPI_EXTERN napi_status napi_adjust_external_memory(napi_env env,
47294730
```
47304731

47314732
* `[in] env`: The environment that the API is invoked under.
4732-
* `[in] change_in_bytes`: The change in externally allocated memory that is
4733-
kept alive by JavaScript objects.
4733+
* `[in] change_in_bytes`: The change in externally allocated memory that is kept
4734+
alive by JavaScript objects.
47344735
* `[out] result`: The adjusted value
47354736

47364737
Returns `napi_ok` if the API succeeded.
@@ -4811,8 +4812,8 @@ napi_status napi_create_promise(napi_env env,
48114812

48124813
* `[in] env`: The environment that the API is invoked under.
48134814
* `[out] deferred`: A newly created deferred object which can later be passed to
4814-
`napi_resolve_deferred()` or `napi_reject_deferred()` to resolve resp. reject
4815-
the associated promise.
4815+
`napi_resolve_deferred()` or `napi_reject_deferred()` to resolve resp. reject
4816+
the associated promise.
48164817
* `[out] promise`: The JavaScript promise associated with the deferred object.
48174818

48184819
Returns `napi_ok` if the API succeeded.
@@ -5062,25 +5063,25 @@ napi_create_threadsafe_function(napi_env env,
50625063
```
50635064

50645065
* `[in] env`: The environment that the API is invoked under.
5065-
* `[in] func`: An optional JavaScript function to call from another thread.
5066-
It must be provided if `NULL` is passed to `call_js_cb`.
5066+
* `[in] func`: An optional JavaScript function to call from another thread. It
5067+
must be provided if `NULL` is passed to `call_js_cb`.
50675068
* `[in] async_resource`: An optional object associated with the async work that
5068-
will be passed to possible `async_hooks` [`init` hooks][].
5069+
will be passed to possible `async_hooks` [`init` hooks][].
50695070
* `[in] async_resource_name`: A JavaScript string to provide an identifier for
5070-
the kind of resource that is being provided for diagnostic information exposed
5071-
by the `async_hooks` API.
5071+
the kind of resource that is being provided for diagnostic information exposed
5072+
by the `async_hooks` API.
50725073
* `[in] max_queue_size`: Maximum size of the queue. `0` for no limit.
50735074
* `[in] initial_thread_count`: The initial number of threads, including the main
5074-
thread, which will be making use of this function.
5075+
thread, which will be making use of this function.
50755076
* `[in] thread_finalize_data`: Optional data to be passed to `thread_finalize_cb`.
50765077
* `[in] thread_finalize_cb`: Optional function to call when the
5077-
`napi_threadsafe_function` is being destroyed.
5078+
`napi_threadsafe_function` is being destroyed.
50785079
* `[in] context`: Optional data to attach to the resulting
5079-
`napi_threadsafe_function`.
5080+
`napi_threadsafe_function`.
50805081
* `[in] call_js_cb`: Optional callback which calls the JavaScript function in
5081-
response to a call on a different thread. This callback will be called on the
5082-
main thread. If not given, the JavaScript function will be called with no
5083-
parameters and with `undefined` as its `this` value.
5082+
response to a call on a different thread. This callback will be called on the
5083+
main thread. If not given, the JavaScript function will be called with no
5084+
parameters and with `undefined` as its `this` value.
50845085
* `[out] result`: The asynchronous thread-safe JavaScript function.
50855086

50865087
### napi_get_threadsafe_function_context
@@ -5117,11 +5118,11 @@ napi_call_threadsafe_function(napi_threadsafe_function func,
51175118

51185119
* `[in] func`: The asynchronous thread-safe JavaScript function to invoke.
51195120
* `[in] data`: Data to send into JavaScript via the callback `call_js_cb`
5120-
provided during the creation of the thread-safe JavaScript function.
5121+
provided during the creation of the thread-safe JavaScript function.
51215122
* `[in] is_blocking`: Flag whose value can be either `napi_tsfn_blocking` to
5122-
indicate that the call should block if the queue is full or
5123-
`napi_tsfn_nonblocking` to indicate that the call should return immediately with
5124-
a status of `napi_queue_full` whenever the queue is full.
5123+
indicate that the call should block if the queue is full or
5124+
`napi_tsfn_nonblocking` to indicate that the call should return immediately
5125+
with a status of `napi_queue_full` whenever the queue is full.
51255126

51265127
This API will return `napi_closing` if `napi_release_threadsafe_function()` was
51275128
called with `abort` set to `napi_tsfn_abort` from any thread. The value is only
@@ -5142,7 +5143,7 @@ napi_acquire_threadsafe_function(napi_threadsafe_function func);
51425143
```
51435144

51445145
* `[in] func`: The asynchronous thread-safe JavaScript function to start making
5145-
use of.
5146+
use of.
51465147

51475148
A thread should call this API before passing `func` to any other thread-safe
51485149
function APIs to indicate that it will be making use of `func`. This prevents
@@ -5165,13 +5166,14 @@ napi_release_threadsafe_function(napi_threadsafe_function func,
51655166
```
51665167

51675168
* `[in] func`: The asynchronous thread-safe JavaScript function whose reference
5168-
count to decrement.
5169+
count to decrement.
51695170
* `[in] mode`: Flag whose value can be either `napi_tsfn_release` to indicate
5170-
that the current thread will make no further calls to the thread-safe function,
5171-
or `napi_tsfn_abort` to indicate that in addition to the current thread, no
5172-
other thread should make any further calls to the thread-safe function. If set
5173-
to `napi_tsfn_abort`, further calls to `napi_call_threadsafe_function()` will
5174-
return `napi_closing`, and no further values will be placed in the queue.
5171+
that the current thread will make no further calls to the thread-safe
5172+
function, or `napi_tsfn_abort` to indicate that in addition to the current
5173+
thread, no other thread should make any further calls to the thread-safe
5174+
function. If set to `napi_tsfn_abort`, further calls to
5175+
`napi_call_threadsafe_function()` will return `napi_closing`, and no further
5176+
values will be placed in the queue.
51755177

51765178
A thread should call this API when it stops making use of `func`. Passing `func`
51775179
to any thread-safe APIs after having called this API has undefined results, as

0 commit comments

Comments
 (0)
Please sign in to comment.