@@ -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.
@@ -1955,7 +1967,7 @@ napi_status napi_create_external(napi_env env,
1955
1967
* `[in] env`: The environment that the API is invoked under.
1956
1968
* `[in] data`: Raw pointer to the external data.
1957
1969
* `[in] finalize_cb`: Optional callback to call when the external value is being
1958
- collected.
1970
+ collected. [`napi_finalize`][] provides more details.
1959
1971
* `[in] finalize_hint`: Optional hint to pass to the finalize callback during
1960
1972
collection.
1961
1973
* `[out] result`: A `napi_value` representing an external value.
@@ -1999,7 +2011,7 @@ napi_create_external_arraybuffer(napi_env env,
1999
2011
`ArrayBuffer`.
2000
2012
* `[in] byte_length`: The length in bytes of the underlying buffer.
2001
2013
* `[in] finalize_cb`: Optional callback to call when the `ArrayBuffer` is being
2002
- collected.
2014
+ collected. [`napi_finalize`][] provides more details.
2003
2015
* `[in] finalize_hint`: Optional hint to pass to the finalize callback during
2004
2016
collection.
2005
2017
* `[out] result`: A `napi_value` representing a JavaScript `ArrayBuffer`.
@@ -2042,7 +2054,7 @@ napi_status napi_create_external_buffer(napi_env env,
2042
2054
size of the new buffer).
2043
2055
* `[in] data`: Raw pointer to the underlying buffer to copy from.
2044
2056
* `[in] finalize_cb`: Optional callback to call when the `ArrayBuffer` is being
2045
- collected.
2057
+ collected. [`napi_finalize`][] provides more details.
2046
2058
* `[in] finalize_hint`: Optional hint to pass to the finalize callback during
2047
2059
collection.
2048
2060
* `[out] result`: A `napi_value` representing a `node::Buffer`.
@@ -3569,16 +3581,16 @@ typedef struct {
3569
3581
If this is passed in, set `value` and `method` to `NULL` (since these members
3570
3582
won't be used). The given function is called implicitly by the runtime when
3571
3583
the property is accessed from JavaScript code (or if a get on the property is
3572
- performed using a N-API call).
3584
+ performed using a N-API call). [`napi_callback`][] provides more details.
3573
3585
* `setter`: A function to call when a set access of the property is performed.
3574
3586
If this is passed in, set `value` and `method` to `NULL` (since these members
3575
3587
won't be used). The given function is called implicitly by the runtime when
3576
3588
the property is set from JavaScript code (or if a set on the property is
3577
- performed using a N-API call).
3589
+ performed using a N-API call). [`napi_callback`][] provides more details.
3578
3590
* `method`: Set this to make the property descriptor object's `value`
3579
3591
property to be a JavaScript function represented by `method`. If this is
3580
3592
passed in, set `value`, `getter` and `setter` to `NULL` (since these members
3581
- won't be used).
3593
+ won't be used). [`napi_callback`][] provides more details.
3582
3594
* `attributes`: The attributes associated with the particular property. See
3583
3595
[`napi_property_attributes`][].
3584
3596
* `data`: The callback data passed into `method`, `getter` and `setter` if this
@@ -4055,7 +4067,7 @@ napi_status napi_create_function(napi_env env,
4055
4067
* `[in] length`: The length of the `utf8name` in bytes, or `NAPI_AUTO_LENGTH` if
4056
4068
it is null-terminated.
4057
4069
* `[in] cb`: The native function which should be called when this function
4058
- object is invoked.
4070
+ object is invoked. [`napi_callback`][] provides more details.
4059
4071
* `[in] data`: User-provided data context. This will be passed back into the
4060
4072
function when invoked later.
4061
4073
* `[out] result`: `napi_value` representing the JavaScript function object for
@@ -4289,8 +4301,8 @@ napi_status napi_define_class(napi_env env,
4289
4301
* `[in] length`: The length of the `utf8name` in bytes, or `NAPI_AUTO_LENGTH`
4290
4302
if it is null-terminated.
4291
4303
* `[in] constructor`: Callback function that handles constructing instances
4292
- of the class. ( This should be a static method on the class, not an actual
4293
- C++ constructor function.)
4304
+ of the class. This should be a static method on the class, not an actual
4305
+ C++ constructor function. [`napi_callback`][] provides more details.
4294
4306
* `[in] data`: Optional data to be passed to the constructor callback as
4295
4307
the `data` property of the callback info.
4296
4308
* `[in] property_count`: Number of items in the `properties` array argument.
@@ -4352,6 +4364,7 @@ napi_status napi_wrap(napi_env env,
4352
4364
JavaScript object.
4353
4365
* `[in] finalize_cb`: Optional native callback that can be used to free the
4354
4366
native instance when the JavaScript object is ready for garbage-collection.
4367
+ [`napi_finalize`][] provides more details.
4355
4368
* `[in] finalize_hint`: Optional contextual hint that is passed to the
4356
4369
finalize callback.
4357
4370
* `[out] result`: Optional reference to the wrapped object.
@@ -4460,6 +4473,7 @@ napi_status napi_add_finalizer(napi_env env,
4460
4473
object.
4461
4474
* `[in] finalize_cb`: Native callback that will be used to free the
4462
4475
native data when the JavaScript object is ready for garbage-collection.
4476
+ [`napi_finalize`][] provides more details.
4463
4477
* `[in] finalize_hint`: Optional contextual hint that is passed to the
4464
4478
finalize callback.
4465
4479
* `[out] result`: Optional reference to the JavaScript object.
@@ -4567,7 +4581,8 @@ napi_status napi_create_async_work(napi_env env,
4567
4581
and can execute in parallel with the main event loop thread.
4568
4582
* `[in] complete`: The native function which will be called when the
4569
4583
asynchronous logic is completed or is cancelled. The given function is called
4570
- from the main event loop thread.
4584
+ from the main event loop thread. [`napi_async_complete_callback`][] provides
4585
+ more details.
4571
4586
* `[in] data`: User-provided data context. This will be passed back into the
4572
4587
execute and complete functions.
4573
4588
* `[out] result`: `napi_async_work*` which is the handle to the newly created
@@ -5258,6 +5273,7 @@ napi_create_threadsafe_function(napi_env env,
5258
5273
response to a call on a different thread. This callback will be called on the
5259
5274
main thread. If not given, the JavaScript function will be called with no
5260
5275
parameters and with `undefined` as its `this` value.
5276
+ [`napi_threadsafe_function_call_js`][] provides more details.
5261
5277
* `[out] result`: The asynchronous thread-safe JavaScript function.
5262
5278
5263
5279
### napi_get_threadsafe_function_context
@@ -5470,7 +5486,9 @@ This API may only be called from the main thread.
5470
5486
[`init` hooks]: async_hooks.html#async_hooks_init_asyncid_type_triggerasyncid_resource
5471
5487
[`napi_add_env_cleanup_hook`]: #n_api_napi_add_env_cleanup_hook
5472
5488
[`napi_add_finalizer`]: #n_api_napi_add_finalizer
5489
+ [`napi_async_complete_callback`]: #n_api_napi_async_complete_callback
5473
5490
[`napi_async_init`]: #n_api_napi_async_init
5491
+ [`napi_callback`]: #n_api_napi_callback
5474
5492
[`napi_cancel_async_work`]: #n_api_napi_cancel_async_work
5475
5493
[`napi_close_callback_scope`]: #n_api_napi_close_callback_scope
5476
5494
[`napi_close_escapable_handle_scope`]: #n_api_napi_close_escapable_handle_scope
@@ -5485,6 +5503,7 @@ This API may only be called from the main thread.
5485
5503
[`napi_delete_async_work`]: #n_api_napi_delete_async_work
5486
5504
[`napi_delete_reference`]: #n_api_napi_delete_reference
5487
5505
[`napi_escape_handle`]: #n_api_napi_escape_handle
5506
+ [`napi_finalize`]: #n_api_napi_finalize
5488
5507
[`napi_get_and_clear_last_exception`]: #n_api_napi_get_and_clear_last_exception
5489
5508
[`napi_get_array_length`]: #n_api_napi_get_array_length
5490
5509
[`napi_get_element`]: #n_api_napi_get_element
@@ -5506,6 +5525,7 @@ This API may only be called from the main thread.
5506
5525
[`napi_reference_unref`]: #n_api_napi_reference_unref
5507
5526
[`napi_set_instance_data`]: #n_api_napi_set_instance_data
5508
5527
[`napi_set_property`]: #n_api_napi_set_property
5528
+ [`napi_threadsafe_function_call_js`]: #n_api_napi_threadsafe_function_call_js
5509
5529
[`napi_throw_error`]: #n_api_napi_throw_error
5510
5530
[`napi_throw_range_error`]: #n_api_napi_throw_range_error
5511
5531
[`napi_throw_type_error`]: #n_api_napi_throw_type_error
0 commit comments