Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node-api: make napi_ref for all value types to be experimental #47975

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions doc/api/n-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1657,8 +1657,8 @@ which determines whether the reference will keep the corresponding value alive.
References with a count of 0 do not prevent values from being collected.
Values of object (object, function, external) and symbol types are becoming
'weak' references and can still be accessed while they are not collected.
Values of other types are released when the count becomes 0
and cannot be accessed from the reference any more.
In experimental Node-API version values of other types are released when the
count becomes 0 and cannot be accessed from the reference any more.
Any count greater than 0 will prevent the values from being collected.

Symbol values have different flavors. The true weak reference behavior is
Expand All @@ -1679,10 +1679,10 @@ will return `NULL` for the returned `napi_value`. An attempt to call
[`napi_reference_ref`][] for a reference whose object has been collected
results in an error.

Node-API versions 8 and earlier only allow references to be created for a
Currently Node-API only allows references to be created for a
limited set of value types, including object, external, function, and symbol.
However, in newer Node-API versions, references can be created for any
value type.
However, in the experimental Node-API version, references can be created for
any value type.

References must be deleted once they are no longer required by the addon. When
a reference is deleted, it will no longer prevent the corresponding object from
Expand Down Expand Up @@ -1725,9 +1725,9 @@ Returns `napi_ok` if the API succeeded.
This API creates a new reference with the specified reference count
to the value passed in.

In Node-API version 8 and earlier, a reference could only be created for
object, function, external, and symbol value types. However, in newer Node-API
versions, a reference can be created for any value type.
In current Node-API version a reference can be created only for
vmoroz marked this conversation as resolved.
Show resolved Hide resolved
object, function, external, and symbol value types. However, in the
experimental Node-API version, a reference can be created for any value type.

#### `napi_delete_reference`

Expand Down
2 changes: 1 addition & 1 deletion src/js_native_api_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2436,7 +2436,7 @@ napi_status NAPI_CDECL napi_create_reference(napi_env env,
CHECK_ARG(env, result);

v8::Local<v8::Value> v8_value = v8impl::V8LocalValueFromJsValue(value);
if (env->module_api_version <= 8) {
if (env->module_api_version != NAPI_VERSION_EXPERIMENTAL) {
if (!(v8_value->IsObject() || v8_value->IsFunction() ||
v8_value->IsSymbol())) {
return napi_set_last_error(env, napi_invalid_arg);
Expand Down