Skip to content

Commit 5aab27e

Browse files
doc: add blurb about SetInstanceData
Add a blurb explaining that using `Napi::Addon<T>` entails avoiding the use of `Napi::Env::SetInstanceData()`. Fixes: #1097
1 parent e439222 commit 5aab27e

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

doc/addon.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ to either attach methods, accessors, and/or values to the `exports` object or to
9090
create its own `exports` object and attach methods, accessors, and/or values to
9191
it.
9292

93+
**Note:** `Napi::Addon<T>` uses `Napi::Env::SetInstanceData()` internally. This
94+
means that the add-on should only use `Napi::Env::GetInstanceData` explicitly to
95+
retrieve the instance of the `Napi::Addon<T>` class. Variables whose scope would
96+
otherwise be global should be stored as instance variables in the
97+
`Napi::Addon<T>` class.
98+
9399
Functions created with `Napi::Function::New()`, accessors created with
94100
`PropertyDescriptor::Accessor()`, and values can also be attached. If their
95101
implementation requires the `ExampleAddon` instance, it can be retrieved from

0 commit comments

Comments
 (0)