neon-bindings / neon

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

JsFunction should be parameterized by `T: This` #307

Open dherman opened 6 years ago

dherman commented 6 years ago

As far as I can tell, there's no reason for the type parameter of JsFunction to be T: Object, but should be T: This instead. The only place where the type parameter is used is for the call and construct methods, which I believe should be able to work with any This-compatible type. We also probably need to think carefully through all the ways a JsFunction<T> could be invoked, to make sure that there are no safety violations where we're declaring to the type system that this is for sure a T.

If I'm wrong about any of this, we should document why -- at the very least in comments.

dherman commented 6 years ago

BTW, I believe this is a backwards-compatible change, since Object implements This.

dherman commented 6 years ago

This would also make it possible for callee() to return a JsFunction<T> instead of a JsFunction<JsObject>.