Skip to content

Commit

Permalink
doc: add blurb about SetInstanceData
Browse files Browse the repository at this point in the history
Add a blurb explaining that using `Napi::Addon<T>` entails avoiding the
use of `Napi::Env::SetInstanceData()`.

Fixes: #1097
  • Loading branch information
gabrielschulhof committed Nov 5, 2021
1 parent e439222 commit 5aab27e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions doc/addon.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ to either attach methods, accessors, and/or values to the `exports` object or to
create its own `exports` object and attach methods, accessors, and/or values to
it.

**Note:** `Napi::Addon<T>` uses `Napi::Env::SetInstanceData()` internally. This
means that the add-on should only use `Napi::Env::GetInstanceData` explicitly to
retrieve the instance of the `Napi::Addon<T>` class. Variables whose scope would
otherwise be global should be stored as instance variables in the
`Napi::Addon<T>` class.

Functions created with `Napi::Function::New()`, accessors created with
`PropertyDescriptor::Accessor()`, and values can also be attached. If their
implementation requires the `ExampleAddon` instance, it can be retrieved from
Expand Down

0 comments on commit 5aab27e

Please sign in to comment.