@@ -1059,20 +1059,24 @@ napi_status napi_create_external(napi_env env,
1059
1059
```
1060
1060
1061
1061
- ` [in] env ` : The environment that the API is invoked under.
1062
- - ` [in] data ` : Raw pointer to the external data being wrapped .
1063
- - ` [in] finalize_cb ` : Optional callback to call when the wrapped object
1062
+ - ` [in] data ` : Raw pointer to the external data.
1063
+ - ` [in] finalize_cb ` : Optional callback to call when the external value
1064
1064
is being collected.
1065
1065
- ` [in] finalize_hint ` : Optional hint to pass to the finalize callback
1066
1066
during collection.
1067
- - ` [out] result ` : A ` napi_value ` representing an external object .
1067
+ - ` [out] result ` : A ` napi_value ` representing an external value .
1068
1068
1069
1069
Returns ` napi_ok ` if the API succeeded.
1070
1070
1071
- This API allocates a JavaScript object with external data attached to it.
1072
- This is used to wrap native objects and project them into JavaScript.
1073
- The API allows the caller to pass in a finalize callback, in case the
1074
- underlying native resource needs to be cleaned up when the wrapper
1075
- JavaScript object gets collected.
1071
+ This API allocates a JavaScript value with external data attached to it. This
1072
+ is used to pass external data through JavaScript code, so it can be retrieved
1073
+ later by native code. The API allows the caller to pass in a finalize callback,
1074
+ in case the underlying native resource needs to be cleaned up when the external
1075
+ JavaScript value gets collected.
1076
+
1077
+ Note: The created value is not an object, and therefore does not support
1078
+ additional properties. It is considered a distinct value type: calling
1079
+ ` napi_typeof() ` with an external value yields ` napi_external ` .
1076
1080
1077
1081
#### napi_create_external_arraybuffer
1078
1082
<!-- YAML
@@ -1457,8 +1461,8 @@ Boolean.
1457
1461
Returns `napi_ok` if the API succeeded. If a non-boolean `napi_value` is
1458
1462
passed in it returns `napi_boolean_expected`.
1459
1463
1460
- This API returns C boolean primitive equivalent of the given JavaScript
1461
- Boolea
1464
+ This API returns the C boolean primitive equivalent of the given JavaScript
1465
+ Boolean.
1462
1466
1463
1467
#### *napi_get_value_double*
1464
1468
<!-- YAML
@@ -1493,14 +1497,14 @@ napi_status napi_get_value_external(napi_env env,
1493
1497
```
1494
1498
1495
1499
- `[in] env`: The environment that the API is invoked under.
1496
- - `[in] value`: `napi_value` representing JavaScript External value.
1497
- - `[out] result`: Pointer to the data wrapped by the JavaScript External value.
1500
+ - `[in] value`: `napi_value` representing JavaScript external value.
1501
+ - `[out] result`: Pointer to the data wrapped by the JavaScript external value.
1498
1502
1499
1503
Returns `napi_ok` if the API succeeded. If a non-external `napi_value` is
1500
1504
passed in it returns `napi_invalid_arg`.
1501
1505
1502
- This API returns the pointer to the data wrapped by the JavaScript
1503
- External value
1506
+ This API retrieves the external data pointer that was previously passed to
1507
+ `napi_create_external()`.
1504
1508
1505
1509
#### *napi_get_value_int32*
1506
1510
<!-- YAML
@@ -2770,6 +2774,7 @@ napi_status napi_wrap(napi_env env,
2770
2774
Returns `napi_ok` if the API succeeded.
2771
2775
2772
2776
Wraps a native instance in JavaScript object of the corresponding type.
2777
+ The native instance can be retrieved later using `napi_unwrap()`.
2773
2778
2774
2779
When JavaScript code invokes a constructor for a class that was defined using
2775
2780
`napi_define_class()`, the `napi_callback` for the constructor is invoked.
@@ -2788,11 +2793,15 @@ has a reference count of 0. Typically this reference count would be incremented
2788
2793
temporarily during async operations that require the instance to remain valid.
2789
2794
2790
2795
Caution: The optional returned reference (if obtained) should be deleted via
2791
- [`napi_delete_reference`][] ONLY in response to the finalize callback invocation.
2792
- (If it is deleted before then, then the finalize callback may never be
2793
- invoked.) Therefore when obtaining a reference a finalize callback is also
2796
+ [`napi_delete_reference`][] ONLY in response to the finalize callback
2797
+ invocation. (If it is deleted before then, then the finalize callback may never
2798
+ be invoked.) Therefore when obtaining a reference a finalize callback is also
2794
2799
required in order to enable correct proper of the reference.
2795
2800
2801
+ Note: This API may modify the prototype chain of the wrapper object.
2802
+ Afterward, additional manipulation of the wrapper's prototype chain may cause
2803
+ `napi_unwrap()` to fail.
2804
+
2796
2805
### *napi_unwrap*
2797
2806
<!-- YAML
2798
2807
added: v8.0.0
@@ -2809,6 +2818,9 @@ napi_status napi_unwrap(napi_env env,
2809
2818
2810
2819
Returns ` napi_ok ` if the API succeeded.
2811
2820
2821
+ Retrieves a native instance that was previously wrapped in a JavaScript
2822
+ object using ` napi_wrap() ` .
2823
+
2812
2824
When JavaScript code invokes a method or property accessor on the class, the
2813
2825
corresponding ` napi_callback ` is invoked. If the callback is for an instance
2814
2826
method or accessor, then the ` this ` argument to the callback is the wrapper
0 commit comments