Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best practice to store context-aware class constructor reference #654

Closed
legendecas opened this issue Jan 19, 2020 · 2 comments
Closed

Best practice to store context-aware class constructor reference #654

legendecas opened this issue Jan 19, 2020 · 2 comments

Comments

@legendecas
Copy link
Member

I've seen many users just store the class constructor reference statically for later use. This will definitely cause issues if the addon is used in both master thread and worker threads. We shall document the best practice to prevent such pitfalls. Or was I just missed such docs?

@gabrielschulhof
Copy link
Contributor

@legendecas I was planning on writing a class Napi::Addon that would solve this problem by having all bindings be instance functions rather than static ones. However, I believe that it would be best to have nodejs/node#30537 (backport of instance data to v10.x) for that, so we can use napi_get_instance_data() for retrieving the addon instance in the implementation.

gabrielschulhof pushed a commit that referenced this issue Jan 31, 2020
Support `napi_get_instance_data()` and `napi_set_instance_data()`.
Fixes: #654
@gabrielschulhof
Copy link
Contributor

It turns out that adding such a class would mean that we'd have to pretty much duplicate the entire API for creating functions, classes, and property descriptors. So AFAICT it's best to do what #663 does, which is to make the data available on the Napi::Env.

gabrielschulhof pushed a commit to gabrielschulhof/node-addon-api that referenced this issue Feb 4, 2020
Support `napi_get_instance_data()` and `napi_set_instance_data()`.

Fixes: nodejs#654
gabrielschulhof pushed a commit to gabrielschulhof/node-addon-api that referenced this issue Feb 4, 2020
Support `napi_get_instance_data()` and `napi_set_instance_data()`.
Fixes: nodejs#654
gabrielschulhof pushed a commit to gabrielschulhof/node-addon-api that referenced this issue Mar 30, 2020
Support `napi_get_instance_data()` and `napi_set_instance_data()`.
Fixes: nodejs#654
gabrielschulhof pushed a commit to gabrielschulhof/node-addon-api that referenced this issue Apr 7, 2020
Support `napi_get_instance_data()` and `napi_set_instance_data()`.
Fixes: nodejs#654
gabrielschulhof pushed a commit to gabrielschulhof/node-addon-api that referenced this issue Apr 10, 2020
Support `napi_get_instance_data()` and `napi_set_instance_data()`.
Fixes: nodejs#654
gabrielschulhof pushed a commit to gabrielschulhof/node-addon-api that referenced this issue Apr 24, 2020
Support `napi_get_instance_data()` and `napi_set_instance_data()`.
Fixes: nodejs#654
gabrielschulhof pushed a commit to gabrielschulhof/node-addon-api that referenced this issue Apr 25, 2020
Support `napi_get_instance_data()` and `napi_set_instance_data()`.
Fixes: nodejs#654
kevindavies8 added a commit to kevindavies8/node-addon-api-Develop that referenced this issue Aug 24, 2022
Support `napi_get_instance_data()` and `napi_set_instance_data()`.

Signed-off-by: Gabriel Schulhof <[email protected]>
Fixes: nodejs/node-addon-api#654
PR-URL: nodejs/node-addon-api#663
Reviewed-By: Chengzhong Wu <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
Marlyfleitas added a commit to Marlyfleitas/node-api-addon-Development that referenced this issue Aug 26, 2022
Support `napi_get_instance_data()` and `napi_set_instance_data()`.

Signed-off-by: Gabriel Schulhof <[email protected]>
Fixes: nodejs/node-addon-api#654
PR-URL: nodejs/node-addon-api#663
Reviewed-By: Chengzhong Wu <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
wroy7860 added a commit to wroy7860/addon-api-benchmark-node that referenced this issue Sep 19, 2022
Support `napi_get_instance_data()` and `napi_set_instance_data()`.

Signed-off-by: Gabriel Schulhof <[email protected]>
Fixes: nodejs/node-addon-api#654
PR-URL: nodejs/node-addon-api#663
Reviewed-By: Chengzhong Wu <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
johnfrench3 pushed a commit to johnfrench3/node-addon-api-git that referenced this issue Aug 11, 2023
Support `napi_get_instance_data()` and `napi_set_instance_data()`.

Signed-off-by: Gabriel Schulhof <[email protected]>
Fixes: nodejs/node-addon-api#654
PR-URL: nodejs/node-addon-api#663
Reviewed-By: Chengzhong Wu <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants