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

node-api: test to implement native object as Proxy #42911

Closed
wants to merge 1 commit into from

Conversation

vmoroz
Copy link
Member

@vmoroz vmoroz commented Apr 29, 2022

A new test to show how to implement a native object as a Proxy object instead of napi_define_class.

The issue

V8 has ObjectTemplate that allows defining native objects as proxies.
If native object has many methods, then ObjectTemplate does not require to implement JavaScript property for each method.
The Node.js NAN uses ObjectTemplate to define native objects.
Since Node API does not have such API, it creates issues when we convert code from NAN to Node API.

See: nodejs/node-addon-api#1114

Solution

We discussed this issue with the Node API team.
Since we want the Node API to work with all JavaScript engines, we want to see if we can achieve the same results without adding new APIs.
In this PR I have created a new Node API unit test that shows how to use JavaScript Proxy to simulate some behavior of ObjectTemplate using existing Node API.

TODO

  • Discuss the approach with Node API team
  • Expand the test to cover more Proxy behavior
  • See if we can implement NAN-like macros

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/gyp

@vmoroz vmoroz marked this pull request as draft April 29, 2022 14:54
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test Issues and PRs related to the tests. labels Apr 29, 2022
@vmoroz
Copy link
Member Author

vmoroz commented Aug 26, 2022

This PR is replaced with a PR in the node addon examples repo: nodejs/node-addon-examples#202

@vmoroz vmoroz closed this Aug 26, 2022
@vmoroz vmoroz deleted the PR/ProxyWrapTest branch August 26, 2022 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ci PRs that need a full CI run. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants