@@ -391,6 +391,7 @@ napi_status napi_set_instance_data(napi_env env,
391
391
* `[in] data`: The data item to make available to bindings of this instance.
392
392
* `[in] finalize_cb`: The function to call when the environment is being torn
393
393
down. The function receives `data` so that it might free it.
394
+ [`napi_finalize`][] provides more details.
394
395
* `[in] finalize_hint`: Optional hint to pass to the finalize callback during
395
396
collection.
396
397
@@ -597,6 +598,7 @@ minimum lifetimes explicitly.
597
598
For more details, review the [Object lifetime management][].
598
599
599
600
### N-API callback types
601
+
600
602
#### napi_callback_info
601
603
<!-- YAML
602
604
added: v8.0.0
@@ -619,6 +621,9 @@ following signature:
619
621
typedef napi_value (*napi_callback)(napi_env, napi_callback_info);
620
622
```
621
623
624
+ Unless for reasons discussed in [Object Lifetime Management][], creating a
625
+ handle and/or callback scope inside a `napi_callback` is not necessary.
626
+
622
627
#### napi_finalize
623
628
<!-- YAML
624
629
added: v8.0.0
@@ -637,6 +642,9 @@ typedef void (*napi_finalize)(napi_env env,
637
642
void* finalize_hint);
638
643
```
639
644
645
+ Unless for reasons discussed in [Object Lifetime Management][], creating a
646
+ handle and/or callback scope inside the function body is not necessary.
647
+
640
648
#### napi_async_execute_callback
641
649
<!-- YAML
642
650
added: v8.0.0
@@ -649,12 +657,10 @@ operations. Callback functions must satisfy the following signature:
649
657
typedef void (*napi_async_execute_callback)(napi_env env, void* data);
650
658
```
651
659
652
- Implementations of this function must avoid making N-API calls
653
- that execute JavaScript or interact with
654
- JavaScript objects. N-API
655
- calls should be in the `napi_async_complete_callback` instead.
656
- Do not use the `napi_env` parameter as it will likely
657
- result in execution of JavaScript.
660
+ Implementations of this function must avoid making N-API calls that execute
661
+ JavaScript or interact with JavaScript objects. N-API calls should be in the
662
+ `napi_async_complete_callback` instead. Do not use the `napi_env` parameter as
663
+ it will likely result in execution of JavaScript.
658
664
659
665
#### napi_async_complete_callback
660
666
<!-- YAML
@@ -670,6 +676,9 @@ typedef void (*napi_async_complete_callback)(napi_env env,
670
676
void* data);
671
677
```
672
678
679
+ Unless for reasons discussed in [Object Lifetime Management][], creating a
680
+ handle and/or callback scope inside the function body is not necessary.
681
+
673
682
#### napi_threadsafe_function_call_js
674
683
<!-- YAML
675
684
added: v10.6.0
@@ -713,6 +722,9 @@ typedef void (*napi_threadsafe_function_call_js)(napi_env env,
713
722
This pointer is managed entirely by the threads and this callback. Thus this
714
723
callback should free the data.
715
724
725
+ Unless for reasons discussed in [Object Lifetime Management][], creating a
726
+ handle and/or callback scope inside the function body is not necessary.
727
+
716
728
## Error handling
717
729
718
730
N-API uses both return values and JavaScript exceptions for error handling.
@@ -1958,7 +1970,7 @@ napi_status napi_create_external(napi_env env,
1958
1970
* `[in] env`: The environment that the API is invoked under.
1959
1971
* `[in] data`: Raw pointer to the external data.
1960
1972
* `[in] finalize_cb`: Optional callback to call when the external value is being
1961
- collected.
1973
+ collected. [`napi_finalize`][] provides more details.
1962
1974
* `[in] finalize_hint`: Optional hint to pass to the finalize callback during
1963
1975
collection.
1964
1976
* `[out] result`: A `napi_value` representing an external value.
@@ -2002,7 +2014,7 @@ napi_create_external_arraybuffer(napi_env env,
2002
2014
`ArrayBuffer`.
2003
2015
* `[in] byte_length`: The length in bytes of the underlying buffer.
2004
2016
* `[in] finalize_cb`: Optional callback to call when the `ArrayBuffer` is being
2005
- collected.
2017
+ collected. [`napi_finalize`][] provides more details.
2006
2018
* `[in] finalize_hint`: Optional hint to pass to the finalize callback during
2007
2019
collection.
2008
2020
* `[out] result`: A `napi_value` representing a JavaScript `ArrayBuffer`.
@@ -2045,7 +2057,7 @@ napi_status napi_create_external_buffer(napi_env env,
2045
2057
size of the new buffer).
2046
2058
* `[in] data`: Raw pointer to the underlying buffer to copy from.
2047
2059
* `[in] finalize_cb`: Optional callback to call when the `ArrayBuffer` is being
2048
- collected.
2060
+ collected. [`napi_finalize`][] provides more details.
2049
2061
* `[in] finalize_hint`: Optional hint to pass to the finalize callback during
2050
2062
collection.
2051
2063
* `[out] result`: A `napi_value` representing a `node::Buffer`.
@@ -3572,16 +3584,16 @@ typedef struct {
3572
3584
If this is passed in, set `value` and `method` to `NULL` (since these members
3573
3585
won't be used). The given function is called implicitly by the runtime when
3574
3586
the property is accessed from JavaScript code (or if a get on the property is
3575
- performed using a N-API call).
3587
+ performed using a N-API call). [`napi_callback`][] provides more details.
3576
3588
* `setter`: A function to call when a set access of the property is performed.
3577
3589
If this is passed in, set `value` and `method` to `NULL` (since these members
3578
3590
won't be used). The given function is called implicitly by the runtime when
3579
3591
the property is set from JavaScript code (or if a set on the property is
3580
- performed using a N-API call).
3592
+ performed using a N-API call). [`napi_callback`][] provides more details.
3581
3593
* `method`: Set this to make the property descriptor object's `value`
3582
3594
property to be a JavaScript function represented by `method`. If this is
3583
3595
passed in, set `value`, `getter` and `setter` to `NULL` (since these members
3584
- won't be used).
3596
+ won't be used). [`napi_callback`][] provides more details.
3585
3597
* `attributes`: The attributes associated with the particular property. See
3586
3598
[`napi_property_attributes`][].
3587
3599
* `data`: The callback data passed into `method`, `getter` and `setter` if this
@@ -4059,7 +4071,7 @@ napi_status napi_create_function(napi_env env,
4059
4071
* `[in] length`: The length of the `utf8name` in bytes, or `NAPI_AUTO_LENGTH` if
4060
4072
it is null-terminated.
4061
4073
* `[in] cb`: The native function which should be called when this function
4062
- object is invoked.
4074
+ object is invoked. [`napi_callback`][] provides more details.
4063
4075
* `[in] data`: User-provided data context. This will be passed back into the
4064
4076
function when invoked later.
4065
4077
* `[out] result`: `napi_value` representing the JavaScript function object for
@@ -4293,8 +4305,8 @@ napi_status napi_define_class(napi_env env,
4293
4305
* `[in] length`: The length of the `utf8name` in bytes, or `NAPI_AUTO_LENGTH`
4294
4306
if it is null-terminated.
4295
4307
* `[in] constructor`: Callback function that handles constructing instances
4296
- of the class. ( This should be a static method on the class, not an actual
4297
- C++ constructor function.)
4308
+ of the class. This should be a static method on the class, not an actual
4309
+ C++ constructor function. [`napi_callback`][] provides more details.
4298
4310
* `[in] data`: Optional data to be passed to the constructor callback as
4299
4311
the `data` property of the callback info.
4300
4312
* `[in] property_count`: Number of items in the `properties` array argument.
@@ -4356,6 +4368,7 @@ napi_status napi_wrap(napi_env env,
4356
4368
JavaScript object.
4357
4369
* `[in] finalize_cb`: Optional native callback that can be used to free the
4358
4370
native instance when the JavaScript object is ready for garbage-collection.
4371
+ [`napi_finalize`][] provides more details.
4359
4372
* `[in] finalize_hint`: Optional contextual hint that is passed to the
4360
4373
finalize callback.
4361
4374
* `[out] result`: Optional reference to the wrapped object.
@@ -4464,6 +4477,7 @@ napi_status napi_add_finalizer(napi_env env,
4464
4477
object.
4465
4478
* `[in] finalize_cb`: Native callback that will be used to free the
4466
4479
native data when the JavaScript object is ready for garbage-collection.
4480
+ [`napi_finalize`][] provides more details.
4467
4481
* `[in] finalize_hint`: Optional contextual hint that is passed to the
4468
4482
finalize callback.
4469
4483
* `[out] result`: Optional reference to the JavaScript object.
@@ -4571,7 +4585,8 @@ napi_status napi_create_async_work(napi_env env,
4571
4585
and can execute in parallel with the main event loop thread.
4572
4586
* `[in] complete`: The native function which will be called when the
4573
4587
asynchronous logic is completed or is cancelled. The given function is called
4574
- from the main event loop thread.
4588
+ from the main event loop thread. [`napi_async_complete_callback`][] provides
4589
+ more details.
4575
4590
* `[in] data`: User-provided data context. This will be passed back into the
4576
4591
execute and complete functions.
4577
4592
* `[out] result`: `napi_async_work*` which is the handle to the newly created
@@ -5262,6 +5277,7 @@ napi_create_threadsafe_function(napi_env env,
5262
5277
response to a call on a different thread. This callback will be called on the
5263
5278
main thread. If not given, the JavaScript function will be called with no
5264
5279
parameters and with `undefined` as its `this` value.
5280
+ [`napi_threadsafe_function_call_js`][] provides more details.
5265
5281
* `[out] result`: The asynchronous thread-safe JavaScript function.
5266
5282
5267
5283
### napi_get_threadsafe_function_context
@@ -5474,7 +5490,9 @@ This API may only be called from the main thread.
5474
5490
[`init` hooks]: async_hooks.html#async_hooks_init_asyncid_type_triggerasyncid_resource
5475
5491
[`napi_add_env_cleanup_hook`]: #n_api_napi_add_env_cleanup_hook
5476
5492
[`napi_add_finalizer`]: #n_api_napi_add_finalizer
5493
+ [`napi_async_complete_callback`]: #n_api_napi_async_complete_callback
5477
5494
[`napi_async_init`]: #n_api_napi_async_init
5495
+ [`napi_callback`]: #n_api_napi_callback
5478
5496
[`napi_cancel_async_work`]: #n_api_napi_cancel_async_work
5479
5497
[`napi_close_callback_scope`]: #n_api_napi_close_callback_scope
5480
5498
[`napi_close_escapable_handle_scope`]: #n_api_napi_close_escapable_handle_scope
@@ -5489,6 +5507,7 @@ This API may only be called from the main thread.
5489
5507
[`napi_delete_async_work`]: #n_api_napi_delete_async_work
5490
5508
[`napi_delete_reference`]: #n_api_napi_delete_reference
5491
5509
[`napi_escape_handle`]: #n_api_napi_escape_handle
5510
+ [`napi_finalize`]: #n_api_napi_finalize
5492
5511
[`napi_get_and_clear_last_exception`]: #n_api_napi_get_and_clear_last_exception
5493
5512
[`napi_get_array_length`]: #n_api_napi_get_array_length
5494
5513
[`napi_get_element`]: #n_api_napi_get_element
@@ -5510,6 +5529,7 @@ This API may only be called from the main thread.
5510
5529
[`napi_reference_unref`]: #n_api_napi_reference_unref
5511
5530
[`napi_set_instance_data`]: #n_api_napi_set_instance_data
5512
5531
[`napi_set_property`]: #n_api_napi_set_property
5532
+ [`napi_threadsafe_function_call_js`]: #n_api_napi_threadsafe_function_call_js
5513
5533
[`napi_throw_error`]: #n_api_napi_throw_error
5514
5534
[`napi_throw_range_error`]: #n_api_napi_throw_range_error
5515
5535
[`napi_throw_type_error`]: #n_api_napi_throw_type_error
0 commit comments