[v10.x]: Backport instance data by gabrielschulhof · Pull Request #30537 · nodejs/node

@gabrielschulhof added the node-api

Issues and PRs related to the Node-API.

label

Nov 18, 2019

@nodejs-github-bot nodejs-github-bot added c++

Issues and PRs that require attention from people who are familiar with C++.

lib / src

Issues and PRs related to general changes in the lib or src directory.

v10.x labels

Nov 18, 2019

@gabrielschulhof gabrielschulhof changed the title v10.x: Backport instance data [v10.x]: Backport instance data

Nov 19, 2019

gengjiawen

These do not need to be macros.

PR-URL: nodejs#26128
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Adds `napi_set_instance_data()` and `napi_get_instance_data()`, which
allow native addons to store their data on and retrieve their data from
`napi_env`. `napi_set_instance_data()` accepts a finalizer which is
called when the `node::Environment()` is destroyed.

This entails rendering the `napi_env` local to each add-on.

Fixes: nodejs/abi-stable-node#378
PR-URL: nodejs#28682
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>

BethGriggs

BethGriggs pushed a commit that referenced this pull request

Feb 25, 2020
These do not need to be macros.

PR-URL: #26128
Backport-PR-URL: #30537
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>

BethGriggs pushed a commit that referenced this pull request

Feb 25, 2020
Adds `napi_set_instance_data()` and `napi_get_instance_data()`, which
allow native addons to store their data on and retrieve their data from
`napi_env`. `napi_set_instance_data()` accepts a finalizer which is
called when the `node::Environment()` is destroyed.

This entails rendering the `napi_env` local to each add-on.

Fixes: nodejs/abi-stable-node#378
PR-URL: #28682
Backport-PR-URL: #30537
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>