@@ -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
@@ -1364,7 +1368,8 @@ Returns `napi_ok` if the API succeeded.
1364
1368
1365
1369
This API is used to retrieve the underlying data buffer of an ArrayBuffer and
1366
1370
its length.
1367
- WARNING: Use caution while using this API. The lifetime of the underlying data
1371
+
1372
+ *WARNING*: Use caution while using this API. The lifetime of the underlying data
1368
1373
buffer is managed by the ArrayBuffer even after it's returned. A
1369
1374
possible safe way to use this API is in conjunction with [`napi_create_reference`][],
1370
1375
which can be used to guarantee control over the lifetime of the
@@ -1391,7 +1396,8 @@ Returns `napi_ok` if the API succeeded.
1391
1396
1392
1397
This API is used to retrieve the underlying data buffer of a ` node::Buffer `
1393
1398
and it's length.
1394
- Warning: Use caution while using this API since the underlying data buffer's
1399
+
1400
+ * Warning* : Use caution while using this API since the underlying data buffer's
1395
1401
lifetime is not guaranteed if it's managed by the VM.
1396
1402
1397
1403
#### * napi_get_prototype*
@@ -1438,7 +1444,8 @@ to start projecting the TypedArray.
1438
1444
Returns ` napi_ok ` if the API succeeded.
1439
1445
1440
1446
This API returns various properties of a typed array.
1441
- Warning: Use caution while using this API since the underlying data buffer
1447
+
1448
+ * Warning* : Use caution while using this API since the underlying data buffer
1442
1449
is managed by the VM
1443
1450
1444
1451
#### * napi_get_value_bool*
@@ -1457,8 +1464,8 @@ Boolean.
1457
1464
Returns `napi_ok` if the API succeeded. If a non-boolean `napi_value` is
1458
1465
passed in it returns `napi_boolean_expected`.
1459
1466
1460
- This API returns C boolean primitive equivalent of the given JavaScript
1461
- Boolea
1467
+ This API returns the C boolean primitive equivalent of the given JavaScript
1468
+ Boolean.
1462
1469
1463
1470
#### *napi_get_value_double*
1464
1471
<!-- YAML
@@ -1493,14 +1500,14 @@ napi_status napi_get_value_external(napi_env env,
1493
1500
```
1494
1501
1495
1502
- `[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.
1503
+ - `[in] value`: `napi_value` representing JavaScript external value.
1504
+ - `[out] result`: Pointer to the data wrapped by the JavaScript external value.
1498
1505
1499
1506
Returns `napi_ok` if the API succeeded. If a non-external `napi_value` is
1500
1507
passed in it returns `napi_invalid_arg`.
1501
1508
1502
- This API returns the pointer to the data wrapped by the JavaScript
1503
- External value
1509
+ This API retrieves the external data pointer that was previously passed to
1510
+ `napi_create_external()`.
1504
1511
1505
1512
#### *napi_get_value_int32*
1506
1513
<!-- YAML
@@ -2770,6 +2777,7 @@ napi_status napi_wrap(napi_env env,
2770
2777
Returns `napi_ok` if the API succeeded.
2771
2778
2772
2779
Wraps a native instance in JavaScript object of the corresponding type.
2780
+ The native instance can be retrieved later using `napi_unwrap()`.
2773
2781
2774
2782
When JavaScript code invokes a constructor for a class that was defined using
2775
2783
`napi_define_class()`, the `napi_callback` for the constructor is invoked.
@@ -2787,12 +2795,16 @@ The optional returned reference is initially a weak reference, meaning it
2787
2795
has a reference count of 0. Typically this reference count would be incremented
2788
2796
temporarily during async operations that require the instance to remain valid.
2789
2797
2790
- 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
2798
+ * Caution* : The optional returned reference (if obtained) should be deleted via
2799
+ [`napi_delete_reference`][] ONLY in response to the finalize callback
2800
+ invocation. (If it is deleted before then, then the finalize callback may never
2801
+ be invoked.) Therefore, when obtaining a reference a finalize callback is also
2794
2802
required in order to enable correct proper of the reference.
2795
2803
2804
+ *Note*: This API may modify the prototype chain of the wrapper object.
2805
+ Afterward, additional manipulation of the wrapper's prototype chain may cause
2806
+ `napi_unwrap()` to fail.
2807
+
2796
2808
### *napi_unwrap*
2797
2809
<!-- YAML
2798
2810
added: v8.0.0
@@ -2809,6 +2821,9 @@ napi_status napi_unwrap(napi_env env,
2809
2821
2810
2822
Returns ` napi_ok ` if the API succeeded.
2811
2823
2824
+ Retrieves a native instance that was previously wrapped in a JavaScript
2825
+ object using ` napi_wrap() ` .
2826
+
2812
2827
When JavaScript code invokes a method or property accessor on the class, the
2813
2828
corresponding ` napi_callback ` is invoked. If the callback is for an instance
2814
2829
method or accessor, then the ` this ` argument to the callback is the wrapper
0 commit comments