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 <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
  • Loading branch information
Gabriel Schulhof authored and targos committed Sep 3, 2018
1 parent 611f423 commit 282a45d
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 282a45d

Please sign in to comment.