node-api: test to implement native object as Proxy
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: https://github.com/nodejs/node-addon-api/issues/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