@@ -389,6 +389,7 @@ napi_status napi_set_instance_data(napi_env env,
389
389
* `[in] data`: The data item to make available to bindings of this instance.
390
390
* `[in] finalize_cb`: The function to call when the environment is being torn
391
391
down. The function receives `data` so that it might free it.
392
+ [`napi_finalize`][] provides more details.
392
393
* `[in] finalize_hint`: Optional hint to pass to the finalize callback during
393
394
collection.
394
395
@@ -592,6 +593,7 @@ minimum lifetimes explicitly.
592
593
For more details, review the [Object lifetime management][].
593
594
594
595
### N-API callback types
596
+
595
597
#### napi_callback_info
596
598
<!-- YAML
597
599
added: v8.0.0
@@ -614,6 +616,9 @@ following signature:
614
616
typedef napi_value (*napi_callback)(napi_env, napi_callback_info);
615
617
```
616
618
619
+ Unless for reasons discussed in [Object Lifetime Management][], creating a
620
+ handle and/or callback scope inside a `napi_callback` is not necessary.
621
+
617
622
#### napi_finalize
618
623
<!-- YAML
619
624
added: v8.0.0
@@ -632,6 +637,9 @@ typedef void (*napi_finalize)(napi_env env,
632
637
void* finalize_hint);
633
638
```
634
639
640
+ Unless for reasons discussed in [Object Lifetime Management][], creating a
641
+ handle and/or callback scope inside the function body is not necessary.
642
+
635
643
#### napi_async_execute_callback
636
644
<!-- YAML
637
645
added: v8.0.0
@@ -644,12 +652,10 @@ operations. Callback functions must satisfy the following signature:
644
652
typedef void (*napi_async_execute_callback)(napi_env env, void* data);
645
653
```
646
654
647
- Implementations of this function must avoid making N-API calls
648
- that execute JavaScript or interact with
649
- JavaScript objects. N-API
650
- calls should be in the `napi_async_complete_callback` instead.
651
- Do not use the `napi_env` parameter as it will likely
652
- result in execution of JavaScript.
655
+ Implementations of this function must avoid making N-API calls that execute
656
+ JavaScript or interact with JavaScript objects. N-API calls should be in the
657
+ `napi_async_complete_callback` instead. Do not use the `napi_env` parameter as
658
+ it will likely result in execution of JavaScript.
653
659
654
660
#### napi_async_complete_callback
655
661
<!-- YAML
@@ -665,6 +671,9 @@ typedef void (*napi_async_complete_callback)(napi_env env,
665
671
void* data);
666
672
```
667
673
674
+ Unless for reasons discussed in [Object Lifetime Management][], creating a
675
+ handle and/or callback scope inside the function body is not necessary.
676
+
668
677
#### napi_threadsafe_function_call_js
669
678
<!-- YAML
670
679
added: v10.6.0
@@ -708,6 +717,9 @@ typedef void (*napi_threadsafe_function_call_js)(napi_env env,
708
717
This pointer is managed entirely by the threads and this callback. Thus this
709
718
callback should free the data.
710
719
720
+ Unless for reasons discussed in [Object Lifetime Management][], creating a
721
+ handle and/or callback scope inside the function body is not necessary.
722
+
711
723
## Error handling
712
724
713
725
N-API uses both return values and JavaScript exceptions for error handling.
@@ -1942,7 +1954,7 @@ napi_status napi_create_external(napi_env env,
1942
1954
* `[in] env`: The environment that the API is invoked under.
1943
1955
* `[in] data`: Raw pointer to the external data.
1944
1956
* `[in] finalize_cb`: Optional callback to call when the external value is being
1945
- collected.
1957
+ collected. [`napi_finalize`][] provides more details.
1946
1958
* `[in] finalize_hint`: Optional hint to pass to the finalize callback during
1947
1959
collection.
1948
1960
* `[out] result`: A `napi_value` representing an external value.
@@ -1986,7 +1998,7 @@ napi_create_external_arraybuffer(napi_env env,
1986
1998
`ArrayBuffer`.
1987
1999
* `[in] byte_length`: The length in bytes of the underlying buffer.
1988
2000
* `[in] finalize_cb`: Optional callback to call when the `ArrayBuffer` is being
1989
- collected.
2001
+ collected. [`napi_finalize`][] provides more details.
1990
2002
* `[in] finalize_hint`: Optional hint to pass to the finalize callback during
1991
2003
collection.
1992
2004
* `[out] result`: A `napi_value` representing a JavaScript `ArrayBuffer`.
@@ -2029,7 +2041,7 @@ napi_status napi_create_external_buffer(napi_env env,
2029
2041
size of the new buffer).
2030
2042
* `[in] data`: Raw pointer to the underlying buffer to copy from.
2031
2043
* `[in] finalize_cb`: Optional callback to call when the `ArrayBuffer` is being
2032
- collected.
2044
+ collected. [`napi_finalize`][] provides more details.
2033
2045
* `[in] finalize_hint`: Optional hint to pass to the finalize callback during
2034
2046
collection.
2035
2047
* `[out] result`: A `napi_value` representing a `node::Buffer`.
@@ -3548,16 +3560,16 @@ typedef struct {
3548
3560
If this is passed in, set `value` and `method` to `NULL` (since these members
3549
3561
won't be used). The given function is called implicitly by the runtime when
3550
3562
the property is accessed from JavaScript code (or if a get on the property is
3551
- performed using a N-API call).
3563
+ performed using a N-API call). [`napi_callback`][] provides more details.
3552
3564
* `setter`: A function to call when a set access of the property is performed.
3553
3565
If this is passed in, set `value` and `method` to `NULL` (since these members
3554
3566
won't be used). The given function is called implicitly by the runtime when
3555
3567
the property is set from JavaScript code (or if a set on the property is
3556
- performed using a N-API call).
3568
+ performed using a N-API call). [`napi_callback`][] provides more details.
3557
3569
* `method`: Set this to make the property descriptor object's `value`
3558
3570
property to be a JavaScript function represented by `method`. If this is
3559
3571
passed in, set `value`, `getter` and `setter` to `NULL` (since these members
3560
- won't be used).
3572
+ won't be used). [`napi_callback`][] provides more details.
3561
3573
* `attributes`: The attributes associated with the particular property. See
3562
3574
[`napi_property_attributes`][].
3563
3575
* `data`: The callback data passed into `method`, `getter` and `setter` if this
@@ -4032,7 +4044,7 @@ napi_status napi_create_function(napi_env env,
4032
4044
* `[in] length`: The length of the `utf8name` in bytes, or `NAPI_AUTO_LENGTH` if
4033
4045
it is null-terminated.
4034
4046
* `[in] cb`: The native function which should be called when this function
4035
- object is invoked.
4047
+ object is invoked. [`napi_callback`][] provides more details.
4036
4048
* `[in] data`: User-provided data context. This will be passed back into the
4037
4049
function when invoked later.
4038
4050
* `[out] result`: `napi_value` representing the JavaScript function object for
@@ -4266,8 +4278,8 @@ napi_status napi_define_class(napi_env env,
4266
4278
* `[in] length`: The length of the `utf8name` in bytes, or `NAPI_AUTO_LENGTH`
4267
4279
if it is null-terminated.
4268
4280
* `[in] constructor`: Callback function that handles constructing instances
4269
- of the class. ( This should be a static method on the class, not an actual
4270
- C++ constructor function.)
4281
+ of the class. This should be a static method on the class, not an actual
4282
+ C++ constructor function. [`napi_callback`][] provides more details.
4271
4283
* `[in] data`: Optional data to be passed to the constructor callback as
4272
4284
the `data` property of the callback info.
4273
4285
* `[in] property_count`: Number of items in the `properties` array argument.
@@ -4329,6 +4341,7 @@ napi_status napi_wrap(napi_env env,
4329
4341
JavaScript object.
4330
4342
* `[in] finalize_cb`: Optional native callback that can be used to free the
4331
4343
native instance when the JavaScript object is ready for garbage-collection.
4344
+ [`napi_finalize`][] provides more details.
4332
4345
* `[in] finalize_hint`: Optional contextual hint that is passed to the
4333
4346
finalize callback.
4334
4347
* `[out] result`: Optional reference to the wrapped object.
@@ -4437,6 +4450,7 @@ napi_status napi_add_finalizer(napi_env env,
4437
4450
object.
4438
4451
* `[in] finalize_cb`: Native callback that will be used to free the
4439
4452
native data when the JavaScript object is ready for garbage-collection.
4453
+ [`napi_finalize`][] provides more details.
4440
4454
* `[in] finalize_hint`: Optional contextual hint that is passed to the
4441
4455
finalize callback.
4442
4456
* `[out] result`: Optional reference to the JavaScript object.
@@ -4544,7 +4558,8 @@ napi_status napi_create_async_work(napi_env env,
4544
4558
and can execute in parallel with the main event loop thread.
4545
4559
* `[in] complete`: The native function which will be called when the
4546
4560
asynchronous logic is completed or is cancelled. The given function is called
4547
- from the main event loop thread.
4561
+ from the main event loop thread. [`napi_async_complete_callback`][] provides
4562
+ more details.
4548
4563
* `[in] data`: User-provided data context. This will be passed back into the
4549
4564
execute and complete functions.
4550
4565
* `[out] result`: `napi_async_work*` which is the handle to the newly created
@@ -5229,6 +5244,7 @@ napi_create_threadsafe_function(napi_env env,
5229
5244
response to a call on a different thread. This callback will be called on the
5230
5245
main thread. If not given, the JavaScript function will be called with no
5231
5246
parameters and with `undefined` as its `this` value.
5247
+ [`napi_threadsafe_function_call_js`][] provides more details.
5232
5248
* `[out] result`: The asynchronous thread-safe JavaScript function.
5233
5249
5234
5250
### napi_get_threadsafe_function_context
@@ -5427,7 +5443,9 @@ This API may only be called from the main thread.
5427
5443
[`init` hooks]: async_hooks.html#async_hooks_init_asyncid_type_triggerasyncid_resource
5428
5444
[`napi_add_env_cleanup_hook`]: #n_api_napi_add_env_cleanup_hook
5429
5445
[`napi_add_finalizer`]: #n_api_napi_add_finalizer
5446
+ [`napi_async_complete_callback`]: #n_api_napi_async_complete_callback
5430
5447
[`napi_async_init`]: #n_api_napi_async_init
5448
+ [`napi_callback`]: #n_api_napi_callback
5431
5449
[`napi_cancel_async_work`]: #n_api_napi_cancel_async_work
5432
5450
[`napi_close_callback_scope`]: #n_api_napi_close_callback_scope
5433
5451
[`napi_close_escapable_handle_scope`]: #n_api_napi_close_escapable_handle_scope
@@ -5442,6 +5460,7 @@ This API may only be called from the main thread.
5442
5460
[`napi_delete_async_work`]: #n_api_napi_delete_async_work
5443
5461
[`napi_delete_reference`]: #n_api_napi_delete_reference
5444
5462
[`napi_escape_handle`]: #n_api_napi_escape_handle
5463
+ [`napi_finalize`]: #n_api_napi_finalize
5445
5464
[`napi_get_and_clear_last_exception`]: #n_api_napi_get_and_clear_last_exception
5446
5465
[`napi_get_array_length`]: #n_api_napi_get_array_length
5447
5466
[`napi_get_element`]: #n_api_napi_get_element
@@ -5463,6 +5482,7 @@ This API may only be called from the main thread.
5463
5482
[`napi_reference_unref`]: #n_api_napi_reference_unref
5464
5483
[`napi_set_instance_data`]: #n_api_napi_set_instance_data
5465
5484
[`napi_set_property`]: #n_api_napi_set_property
5485
+ [`napi_threadsafe_function_call_js`]: #n_api_napi_threadsafe_function_call_js
5466
5486
[`napi_throw_error`]: #n_api_napi_throw_error
5467
5487
[`napi_throw_range_error`]: #n_api_napi_throw_range_error
5468
5488
[`napi_throw_type_error`]: #n_api_napi_throw_type_error
0 commit comments