neon
neon copied to clipboard
Get a raw `napi_env` from `Context` for use in N-API methods not implemented by Neon.
I want to call a napi cleanup routine method napi_add_env_cleanup_hook(). This method gives a hook to perform any cleanup (for eg. in electron before a page is refreshed or is being navigated away).
It is available in the generated bindings but is not implemented yet in the nodejs-sys crate. Since env is not exposed to users, is there a way to call this function directly ? Or will all the methods be wrapped eventually ?
Thanks a lot 😊
@vasishath, I'm not sure what you mean by "performing any cleanup before a page is refreshed or being navigated away." Is this related to Electron? There isn't really a concept of pages in node.js.
As far as providing this method, we are happy to accept a PR either as an RFC to add this feature or with an implementation to start the discussion. However, a clean-up hook doesn't seem very "Rust-y". My preference would be to implement napi_set_instance_data and napi_get_instance_data. A Drop implementation on the instance data would provide the same functionality as napi_add_env_cleanup_hook in a more idiomatic way.
@vasishath, I'm not sure what you mean by "performing any cleanup before a page is refreshed or being navigated away." Is this related to Electron? There isn't really a concept of pages in node.js.
As far as providing this method, we are happy to accept a PR either as an RFC to add this feature or with an implementation to start the discussion. However, a clean-up hook doesn't seem very "Rust-y". My preference would be to implement
napi_set_instance_dataandnapi_get_instance_data. ADropimplementation on the instance data would provide the same functionality asnapi_add_env_cleanup_hookin a more idiomatic way.
Yes actually I meant electron. Sorry I forgot to mention that. Yea even I would prefer a rusty way for the tear down phase. I didn't knew this API existed.
Summary
Currently, neon users may only interact with the JavaScript VM in ways prescribed by neon. Users may want to leverage N-API methods before they are adopted by Neon.
Idea
Add a public method to Context to allow users access to the raw Env.
trait Context<'a> {
fn raw_env(&self) -> *mut c_void;
}
It's always safe to get a raw pointers. Users would require unsafe to use the pointer.
Removed the RFC. This is straight forward.