Skip to content

Commit a8237ef

Browse files
Gabriel SchulhofMylesBorins
Gabriel Schulhof
authored andcommitted
n-api: update documentation
Document which APIs work while an exception is pending. This is the list of all APIs which do not start with `NAPI_PREAMBLE(env)`. Fixes: nodejs/abi-stable-node#257 Backport-PR-URL: #19447 PR-URL: #19078 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
1 parent af62c8f commit a8237ef

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

doc/api/n-api.md

+26-10
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ valid up until an n-api function is called on the same `env`.
277277
information as it is not subject to SemVer and may change at any time.
278278
It is intended only for logging purposes.
279279

280+
This API can be called even if there is a pending JavaScript exception.
281+
280282

281283
### Exceptions
282284
Any N-API function call may result in a pending JavaScript exception. This is
@@ -502,7 +504,6 @@ Returns `napi_ok` if the API succeeded.
502504

503505
This API returns a JavaScript RangeError with the text provided.
504506

505-
506507
#### napi_get_and_clear_last_exception
507508
<!-- YAML
508509
added: v8.0.0
@@ -519,6 +520,8 @@ Returns `napi_ok` if the API succeeded.
519520

520521
This API returns true if an exception is pending.
521522

523+
This API can be called even if there is a pending JavaScript exception.
524+
522525
#### napi_is_exception_pending
523526
<!-- YAML
524527
added: v8.0.0
@@ -534,6 +537,8 @@ Returns `napi_ok` if the API succeeded.
534537

535538
This API returns true if an exception is pending.
536539

540+
This API can be called even if there is a pending JavaScript exception.
541+
537542
### Fatal Errors
538543

539544
In the event of an unrecoverable error in a native module, a fatal error can be
@@ -560,6 +565,8 @@ null-terminated.
560565

561566
The function call does not return, the process will be terminated.
562567

568+
This API can be called even if there is a pending JavaScript exception.
569+
563570
## Object Lifetime management
564571

565572
As N-API calls are made, handles to objects in the heap for the underlying
@@ -680,6 +687,8 @@ Returns `napi_ok` if the API succeeded.
680687
This API closes the scope passed in. Scopes must be closed in the
681688
reverse order from which they were created.
682689

690+
This API can be called even if there is a pending JavaScript exception.
691+
683692
#### napi_open_escapable_handle_scope
684693
<!-- YAML
685694
added: v8.0.0
@@ -714,6 +723,8 @@ Returns `napi_ok` if the API succeeded.
714723
This API closes the scope passed in. Scopes must be closed in the
715724
reverse order from which they were created.
716725

726+
This API can be called even if there is a pending JavaScript exception.
727+
717728
#### napi_escape_handle
718729
<!-- YAML
719730
added: v8.0.0
@@ -737,7 +748,10 @@ This API promotes the handle to the JavaScript object so that it is valid
737748
for the lifetime of the outer scope. It can only be called once per scope.
738749
If it is called more than once an error will be returned.
739750

751+
This API can be called even if there is a pending JavaScript exception.
752+
740753
### References to objects with a lifespan longer than that of the native method
754+
741755
In some cases an addon will need to be able to create and reference objects
742756
with a lifespan longer than that of a single native method invocation. For
743757
example, to create a constructor and later use that constructor
@@ -812,6 +826,8 @@ Returns `napi_ok` if the API succeeded.
812826

813827
This API deletes the reference passed in.
814828

829+
This API can be called even if there is a pending JavaScript exception.
830+
815831
#### napi_reference_ref
816832
<!-- YAML
817833
added: v8.0.0
@@ -830,7 +846,6 @@ Returns `napi_ok` if the API succeeded.
830846
This API increments the reference count for the reference
831847
passed in and returns the resulting reference count.
832848

833-
834849
#### napi_reference_unref
835850
<!-- YAML
836851
added: v8.0.0
@@ -849,7 +864,6 @@ Returns `napi_ok` if the API succeeded.
849864
This API decrements the reference count for the reference
850865
passed in and returns the resulting reference count.
851866

852-
853867
#### napi_get_reference_value
854868
<!-- YAML
855869
added: v8.0.0
@@ -1676,8 +1690,6 @@ This API returns various properties of a typed array.
16761690
*Warning*: Use caution while using this API since the underlying data buffer
16771691
is managed by the VM
16781692

1679-
1680-
16811693
#### napi_get_dataview_info
16821694
<!-- YAML
16831695
added: REPLACEME
@@ -1705,7 +1717,6 @@ Returns `napi_ok` if the API succeeded.
17051717

17061718
This API returns various properties of a DataView.
17071719

1708-
17091720
#### napi_get_value_bool
17101721
<!-- YAML
17111722
added: v8.0.0
@@ -1746,7 +1757,6 @@ in it returns `napi_number_expected`.
17461757
This API returns the C double primitive equivalent of the given JavaScript
17471758
Number.
17481759

1749-
17501760
#### napi_get_value_external
17511761
<!-- YAML
17521762
added: v8.0.0
@@ -1808,7 +1818,7 @@ Returns `napi_ok` if the API succeeded. If a non-number `napi_value`
18081818
is passed in it returns `napi_number_expected`.
18091819

18101820
This API returns the C int64 primitive equivalent of the given
1811-
JavaScript Number
1821+
JavaScript Number.
18121822

18131823
#### napi_get_value_string_latin1
18141824
<!-- YAML
@@ -2200,8 +2210,6 @@ Returns `napi_ok` if the API succeeded.
22002210

22012211
This API checks if the Object passsed in is a typed array.
22022212

2203-
2204-
22052213
### napi_is_dataview
22062214
<!-- YAML
22072215
added: REPLACEME
@@ -3321,6 +3329,8 @@ Returns `napi_ok` if the API succeeded.
33213329

33223330
This API frees a previously allocated work object.
33233331

3332+
This API can be called even if there is a pending JavaScript exception.
3333+
33243334
### napi_queue_async_work
33253335
<!-- YAML
33263336
added: v8.0.0
@@ -3359,6 +3369,8 @@ the `complete` callback will be invoked with a status value of
33593369
`napi_cancelled`. The work should not be deleted before the `complete`
33603370
callback invocation, even if it has been successfully cancelled.
33613371

3372+
This API can be called even if there is a pending JavaScript exception.
3373+
33623374
## Custom Asynchronous Operations
33633375
The simple asynchronous work APIs above may not be appropriate for every
33643376
scenario. When using any other asynchronous mechanism, the following APIs
@@ -3400,6 +3412,8 @@ napi_status napi_async_destroy(napi_env env,
34003412

34013413
Returns `napi_ok` if the API succeeded.
34023414

3415+
This API can be called even if there is a pending JavaScript exception.
3416+
34033417
### napi_make_callback
34043418
<!-- YAML
34053419
added: v8.0.0
@@ -3482,6 +3496,8 @@ NAPI_EXTERN napi_status napi_close_callback_scope(napi_env env,
34823496
- `[in] env`: The environment that the API is invoked under.
34833497
- `[in] scope`: The scope to be closed.
34843498

3499+
This API can be called even if there is a pending JavaScript exception.
3500+
34853501
## Version Management
34863502

34873503
### napi_get_node_version

0 commit comments

Comments
 (0)