-
Notifications
You must be signed in to change notification settings - Fork 288
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
Add APIs that convert between Context
and napi_env
#801
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@patr0nus Thanks for the PR! Can you share a little more details about how you see with_raw_env
being used? My concern is that it locks Neon into fairly strict stability guarantees. Neon would no longer be able to guarantee it's the entry point and therefore needs to be careful about destructive operations performed when the scope drops.
If the only current need is for testing purposes, we should be able to test using some neon_runtime
APIs directly.
src/context/mod.rs
Outdated
@@ -294,6 +294,12 @@ impl<'a> Lock<'a> { | |||
/// | |||
/// A context has a lifetime `'a`, which ensures the safety of handles managed by the JS garbage collector. All handles created during the lifetime of a context are kept alive for that duration and cannot outlive the context. | |||
pub trait Context<'a>: ContextInternal<'a> { | |||
/// Get the underlying `napi-env` of the context | |||
#[cfg(feature = "napi-1")] | |||
fn to_raw_env(&self) -> *mut c_void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would favor a more idiomatic name on the public API instead of matching internal naming. What do you think of as_mut_ptr
?
Additionally, this function should take &mut self
. Even though the caller still needs to uphold borrow rules, it would always be undefined behavior to use the napi_env
while a mutable reference to Context
is held.
My usage of
I want to use neon in both the shared libraries. But "b.dll" isn't the entry point, so to create I understand your concern about the entry point but for my case it's not a problem (neon is still used as the entry point in a.node). What do you think we remove the mentions of |
That's an interesting use case. Unfortunately, In your example, it seems like one crate could own all Neon functions while the other exposes C FFI, but I'm sure the actual code is much more complicated. |
Yeah it's not practical for my case to isolate neon in one crate :( But I think I come up with a solution. The general idea is to represent I have pushed the commits. Let me know what you think :) |
Closes #611.
with_raw_env
is useful when neon is not used as the "entry" of a native module, so after getting a rawnapi_env
we need the unsafe API to bootstrap aneon::Context
.