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

Napi-JSI ObjectWrap should extend Reference<Object> #1030

Open
Alex-MSFT opened this issue Mar 14, 2022 · 1 comment
Open

Napi-JSI ObjectWrap should extend Reference<Object> #1030

Alex-MSFT opened this issue Mar 14, 2022 · 1 comment
Milestone

Comments

@Alex-MSFT
Copy link
Contributor

Is your feature request related to a problem? Please describe.
Currently the ObjectWrap implementation does not extend Reference, which leads to API differences between Napi-JSI and Napi-Direct implementations. For example you cannot call Value() to get access to the JS Object from the context of the C++ class.

Describe the solution you'd like
We should change ObjectWrap to extend Reference to match the implementation in Napi-Direct. Here is an example of the proposed change: b213bea

This change needs to be updated to either make Reference to use a weak reference via JSI::WeakObject or otherwise handle cleanup to allow for GC to clean up stale JS objects.

Describe alternatives you've considered
Currently we can set properties via the InstanceAccessor or by storing a persistent reference to the object in the constructor. The first approach has performance issues for heavily accessed code paths as it requires marshalling to and from the JS context repeatedly, and the second requires managing the lifetime of the reference natively and does not allow JS GC to run.

@bghgary
Copy link
Contributor

bghgary commented Mar 14, 2022

See #1029 for how the CI is failing when the proposed change.

@thomlucc thomlucc added the 6.0 label Sep 23, 2022
@thomlucc thomlucc added this to the 6.0 milestone Sep 23, 2022
@thomlucc thomlucc removed the 6.0 label Sep 23, 2022
@bghgary bghgary modified the milestones: 6.0, Future Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants