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

doc: update wrapping-related documentation #22363

Closed
Closed
Changes from all commits
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
20 changes: 7 additions & 13 deletions doc/api/n-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3569,8 +3569,7 @@ napi_status napi_wrap(napi_env env,

- `[in] env`: The environment that the API is invoked under.
- `[in] js_object`: The JavaScript object that will be the wrapper for the
native object. This object _must_ have been created from the `prototype` of
a constructor that was created using `napi_define_class()`.
native object.
- `[in] native_object`: The native instance that will be wrapped in the
JavaScript object.
- `[in] finalize_cb`: Optional native callback that can be used to free the
Expand Down Expand Up @@ -3602,13 +3601,9 @@ temporarily during async operations that require the instance to remain valid.

*Caution*: The optional returned reference (if obtained) should be deleted via
[`napi_delete_reference`][] ONLY in response to the finalize callback
invocation. (If it is deleted before then, then the finalize callback may never
be invoked.) Therefore, when obtaining a reference a finalize callback is also
required in order to enable correct proper of the reference.

This API may modify the prototype chain of the wrapper object. Afterward,
additional manipulation of the wrapper's prototype chain may cause
`napi_unwrap()` to fail.
invocation. If it is deleted before then, then the finalize callback may never
be invoked. Therefore, when obtaining a reference a finalize callback is also
required in order to enable correct disposal of the reference.

Calling `napi_wrap()` a second time on an object will return an error. To
associate another native instance with the object, use `napi_remove_wrap()`
Expand Down Expand Up @@ -3658,10 +3653,9 @@ napi_status napi_remove_wrap(napi_env env,
Returns `napi_ok` if the API succeeded.

Retrieves a native instance that was previously wrapped in the JavaScript
object `js_object` using `napi_wrap()` and removes the wrapping, thereby
restoring the JavaScript object's prototype chain. If a finalize callback was
associated with the wrapping, it will no longer be called when the JavaScript
object becomes garbage-collected.
object `js_object` using `napi_wrap()` and removes the wrapping. If a finalize
callback was associated with the wrapping, it will no longer be called when the
JavaScript object becomes garbage-collected.

## Simple Asynchronous Operations

Expand Down