Skip to content

Commit

Permalink
doc: update wrapping-related documentation
Browse files Browse the repository at this point in the history
Update the N-API documentation to reflect that wrapping no longer
affects the object's prototype chain.

PR-URL: #22363
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
  • Loading branch information
Gabriel Schulhof committed Aug 21, 2018
1 parent 0f85e20 commit 9dae0ae
Showing 1 changed file with 7 additions and 13 deletions.
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

0 comments on commit 9dae0ae

Please sign in to comment.