From 5aab27e6e19bf189a4e0a5b8fb9c71cfd5228bae Mon Sep 17 00:00:00 2001 From: Gabriel Schulhof Date: Fri, 5 Nov 2021 08:55:20 -0700 Subject: [PATCH] doc: add blurb about SetInstanceData Add a blurb explaining that using `Napi::Addon` entails avoiding the use of `Napi::Env::SetInstanceData()`. Fixes: https://github.com/nodejs/node-addon-api/issues/1097 --- doc/addon.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/addon.md b/doc/addon.md index 96dae718d..7e5ec4791 100644 --- a/doc/addon.md +++ b/doc/addon.md @@ -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` 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` class. Variables whose scope would +otherwise be global should be stored as instance variables in the +`Napi::Addon` 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