neon-bindings / neon

Rust bindings for writing safe and fast native Node.js modules.
https://www.neon-bindings.com/
Apache License 2.0
8k stars 283 forks source link

Implement `This` for `JsBox<...>`? #869

Open ErichDonGubler opened 2 years ago

ErichDonGubler commented 2 years ago

JsBox<...> appears to implement Object, and Managed. Is there a reason that it doesn't also implement This also? The lack of This implementation currently makes it impossible to have a MethodContext<'_, JsBox<...>>, which is something that was previously possible with declare_type! { ... }.

kjvalencik commented 2 years ago

There's no reason it couldn't but it would not provide value. declare_type is not implemented for the Node-API backend and will not be (it is not very ergonomic and is unsound when used with workers).

The current recommendation is to use JsBox and some glue code in JavaScript to create classes. See this example: https://github.com/neon-bindings/examples/blob/main/examples/async-sqlite/index.js

The goal is to addon classes later with a proc macro design.

https://github.com/neon-bindings/rfcs/pull/43 https://github.com/neon-bindings/neon/issues/745