@@ -1650,23 +1650,23 @@ managed by scopes and all scopes must be closed before the end of a native
1650
1650
method.
1651
1651
1652
1652
Node-API provides methods for creating persistent references to values.
1653
+ Currently Node-API only allows references to be created for a
1654
+ limited set of value types, including object, external, function, and symbol.
1655
+
1653
1656
Each reference has an associated count with a value of 0 or higher,
1654
1657
which determines whether the reference will keep the corresponding value alive.
1655
1658
References with a count of 0 do not prevent values from being collected.
1656
1659
Values of object (object, function, external) and symbol types are becoming
1657
1660
'weak' references and can still be accessed while they are not collected.
1658
- Values of other types are released when the count becomes 0
1659
- and cannot be accessed from the reference any more.
1660
1661
Any count greater than 0 will prevent the values from being collected.
1661
1662
1662
1663
Symbol values have different flavors. The true weak reference behavior is
1663
- only supported by local symbols created with the `Symbol()` constructor call.
1664
- Globally registered symbols created with the `Symbol.for()` call remain
1665
- always strong references because the garbage collector does not collect them.
1666
- The same is true for well-known symbols such as `Symbol.iterator`. They are
1667
- also never collected by the garbage collector. JavaScript's `WeakRef` and
1668
- `WeakMap` types return an error when registered symbols are used,
1669
- but they succeed for local and well-known symbols.
1664
+ only supported by local symbols created with the `napi_create_symbol` function
1665
+ or the JavaScript `Symbol()` constructor calls. Globally registered symbols
1666
+ created with the `node_api_symbol_for` function or JavaScript `Symbol.for()`
1667
+ function calls remain always strong references because the garbage collector
1668
+ does not collect them. The same is true for well-known symbols such as
1669
+ `Symbol.iterator`. They are also never collected by the garbage collector.
1670
1670
1671
1671
References can be created with an initial reference count. The count can
1672
1672
then be modified through [`napi_reference_ref`][] and
@@ -1677,11 +1677,6 @@ will return `NULL` for the returned `napi_value`. An attempt to call
1677
1677
[`napi_reference_ref`][] for a reference whose object has been collected
1678
1678
results in an error.
1679
1679
1680
- Node-API versions 8 and earlier only allow references to be created for a
1681
- limited set of value types, including object, external, function, and symbol.
1682
- However, in newer Node-API versions, references can be created for any
1683
- value type.
1684
-
1685
1680
References must be deleted once they are no longer required by the addon. When
1686
1681
a reference is deleted, it will no longer prevent the corresponding object from
1687
1682
being collected. Failure to delete a persistent reference results in
@@ -1699,6 +1694,15 @@ run and the native memory pointed by the earlier persistent reference
1699
1694
will not be freed. This can be avoided by calling
1700
1695
`napi_delete_reference` in addition to `napi_reference_unref` when possible.
1701
1696
1697
+ **Change History:**
1698
+
1699
+ * Experimental (`NAPI_EXPERIMENTAL` is defined):
1700
+
1701
+ References can be created for all value types. The new supported value
1702
+ types do not support weak reference semantic and the values of these types
1703
+ are released when the reference count becomes 0 and cannot be accessed from
1704
+ the reference anymore.
1705
+
1702
1706
#### `napi_create_reference`
1703
1707
1704
1708
<!-- YAML
@@ -1723,10 +1727,6 @@ Returns `napi_ok` if the API succeeded.
1723
1727
This API creates a new reference with the specified reference count
1724
1728
to the value passed in.
1725
1729
1726
- In Node-API version 8 and earlier, a reference could only be created for
1727
- object, function, external, and symbol value types. However, in newer Node-API
1728
- versions, a reference can be created for any value type.
1729
-
1730
1730
#### `napi_delete_reference`
1731
1731
1732
1732
<!-- YAML
0 commit comments