diff --git a/crates/neon/src/context/mod.rs b/crates/neon/src/context/mod.rs index 98b9b8bf5..1c4ae2aa3 100644 --- a/crates/neon/src/context/mod.rs +++ b/crates/neon/src/context/mod.rs @@ -375,7 +375,7 @@ pub trait Context<'a>: ContextInternal<'a> { /// Lock the JavaScript engine, returning an RAII guard that keeps the lock active as long as the guard is alive. /// /// If this is not the currently active context (for example, if it was used to spawn a scoped context with `execute_scoped` or `compute_scoped`), this method will panic. - fn lock<'b>(&'b mut self) -> Lock + fn lock<'b>(&'b mut self) -> Lock<'b, Self> where 'a: 'b, { @@ -641,7 +641,7 @@ pub trait Context<'a>: ContextInternal<'a> { /// Ok(promise) /// } /// ``` - fn task<'cx, O, E>(&'cx mut self, execute: E) -> TaskBuilder + fn task<'cx, O, E>(&'cx mut self, execute: E) -> TaskBuilder<'cx, Self, E> where 'a: 'cx, O: Send + 'static, diff --git a/crates/neon/src/event/channel.rs b/crates/neon/src/event/channel.rs index 860292bc6..cc2872f29 100644 --- a/crates/neon/src/event/channel.rs +++ b/crates/neon/src/event/channel.rs @@ -1,5 +1,5 @@ use std::{ - error, fmt, mem, + error, fmt, sync::{ atomic::{AtomicUsize, Ordering}, Arc, @@ -7,9 +7,9 @@ use std::{ }; use crate::{ - context::{Context, Cx}, + context::{internal::Env, Context, Cx}, result::{NeonResult, ResultExt, Throw}, - sys::{raw::Env, tsfn::ThreadsafeFunction}, + sys::{self, tsfn::ThreadsafeFunction}, }; #[cfg(feature = "futures")] @@ -44,7 +44,7 @@ mod oneshot { } } -type Callback = Box; +type Callback = Box; /// Channel for scheduling Rust closures to execute on the JavaScript main thread. /// @@ -159,7 +159,7 @@ impl Channel { { let (tx, rx) = oneshot::channel(); let callback = Box::new(move |env| { - let env = unsafe { mem::transmute(env) }; + let env = Env::from(env); // Note: It is sufficient to use `Cx` because // N-API creates a `HandleScope` before calling the callback. @@ -409,7 +409,7 @@ impl ChannelState { } // Monomorphized trampoline funciton for calling the user provided closure - fn callback(env: Option, callback: Callback) { + fn callback(env: Option, callback: Callback) { if let Some(env) = env { callback(env); } else { diff --git a/crates/neon/src/handle/mod.rs b/crates/neon/src/handle/mod.rs index ee6a91a9c..41654b253 100644 --- a/crates/neon/src/handle/mod.rs +++ b/crates/neon/src/handle/mod.rs @@ -132,7 +132,7 @@ impl<'a, F: Value, T: Value> ResultExt> for DowncastResult<'a, F, fn or_throw<'b, C: Context<'b>>(self, cx: &mut C) -> JsResult<'a, T> { match self { Ok(v) => Ok(v), - Err(e) => cx.throw_type_error(&e.to_string()), + Err(e) => cx.throw_type_error(e.to_string()), } } } diff --git a/crates/neon/src/lifecycle.rs b/crates/neon/src/lifecycle.rs index 0a08ef922..807e1e0ce 100644 --- a/crates/neon/src/lifecycle.rs +++ b/crates/neon/src/lifecycle.rs @@ -102,7 +102,7 @@ impl LocalCell { } } - pub(crate) fn get<'cx, 'a, C>(cx: &'a mut C, id: usize) -> Option<&mut LocalCellValue> + pub(crate) fn get<'cx, 'a, C>(cx: &'a mut C, id: usize) -> Option<&'a mut LocalCellValue> where C: Context<'cx>, { @@ -113,7 +113,11 @@ impl LocalCell { } } - pub(crate) fn get_or_init<'cx, 'a, C, F>(cx: &'a mut C, id: usize, f: F) -> &mut LocalCellValue + pub(crate) fn get_or_init<'cx, 'a, C, F>( + cx: &'a mut C, + id: usize, + f: F, + ) -> &'a mut LocalCellValue where C: Context<'cx>, F: FnOnce() -> LocalCellValue, @@ -129,7 +133,7 @@ impl LocalCell { cx: &'a mut C, id: usize, f: F, - ) -> Result<&mut LocalCellValue, E> + ) -> Result<&'a mut LocalCellValue, E> where C: Context<'cx>, F: FnOnce(&mut C) -> Result, diff --git a/crates/neon/src/types_impl/boxed.rs b/crates/neon/src/types_impl/boxed.rs index 1caf8ae87..ed73fce17 100644 --- a/crates/neon/src/types_impl/boxed.rs +++ b/crates/neon/src/types_impl/boxed.rs @@ -242,7 +242,7 @@ impl JsBox { // contained value `T`. fn finalizer(env: raw::Env, data: BoxAny) { let data = *data.downcast::().unwrap(); - let env = unsafe { std::mem::transmute(env) }; + let env = Env::from(env); Cx::with_context(env, move |mut cx| data.finalize(&mut cx)); } diff --git a/crates/neon/src/types_impl/extract/json.rs b/crates/neon/src/types_impl/extract/json.rs index 0dc8930af..ee3659e9b 100644 --- a/crates/neon/src/types_impl/extract/json.rs +++ b/crates/neon/src/types_impl/extract/json.rs @@ -34,7 +34,7 @@ fn json_stringify<'cx>(cx: &mut Cx<'cx>) -> JsResult<'cx, JsFunction> { .map(|f| f.to_inner(cx)) } -fn stringify<'cx>(cx: &mut Cx<'cx>, v: Handle) -> NeonResult { +fn stringify(cx: &mut Cx, v: Handle) -> NeonResult { json_stringify(cx)? .call(cx, v, [v])? .downcast_or_throw::(cx) diff --git a/crates/neon/src/types_impl/extract/try_from_js.rs b/crates/neon/src/types_impl/extract/try_from_js.rs index d7357b224..c34959408 100644 --- a/crates/neon/src/types_impl/extract/try_from_js.rs +++ b/crates/neon/src/types_impl/extract/try_from_js.rs @@ -270,7 +270,7 @@ impl<'cx> TryFromJs<'cx> for ArrayBuffer { from_js!(); } -fn is_null_or_undefined<'cx, V>(cx: &mut Cx<'cx>, v: Handle) -> NeonResult +fn is_null_or_undefined(cx: &mut Cx, v: Handle) -> NeonResult where V: Value, { diff --git a/crates/neon/src/types_impl/mod.rs b/crates/neon/src/types_impl/mod.rs index 3f8677e51..45837cfb3 100644 --- a/crates/neon/src/types_impl/mod.rs +++ b/crates/neon/src/types_impl/mod.rs @@ -451,7 +451,7 @@ impl<'a> ResultExt> for StringResult<'a> { fn or_throw<'b, C: Context<'b>>(self, cx: &mut C) -> JsResult<'a, JsString> { match self { Ok(v) => Ok(v), - Err(e) => cx.throw_range_error(&e.to_string()), + Err(e) => cx.throw_range_error(e.to_string()), } } } diff --git a/crates/neon/src/types_impl/utf8.rs b/crates/neon/src/types_impl/utf8.rs index fe772edf4..20bc97465 100644 --- a/crates/neon/src/types_impl/utf8.rs +++ b/crates/neon/src/types_impl/utf8.rs @@ -1,6 +1,6 @@ use std::borrow::Cow; -const SMALL_MAX: usize = std::i32::MAX as usize; +const SMALL_MAX: usize = i32::MAX as usize; /// V8 APIs that take UTF-8 strings take their length in the form of 32-bit /// signed integers. This type represents a UTF-8 string that contains no diff --git a/test/napi/src/js/futures.rs b/test/napi/src/js/futures.rs index 5d2168674..3c71975bb 100644 --- a/test/napi/src/js/futures.rs +++ b/test/napi/src/js/futures.rs @@ -9,7 +9,7 @@ fn runtime<'a, C: Context<'a>>(cx: &mut C) -> NeonResult<&'static Runtime> { RUNTIME .get_or_try_init(Runtime::new) - .or_else(|err| cx.throw_error(&err.to_string())) + .or_else(|err| cx.throw_error(err.to_string())) } // Accepts two functions that take no parameters and return numbers. diff --git a/test/napi/src/js/typedarrays.rs b/test/napi/src/js/typedarrays.rs index bb8312f26..662792c22 100644 --- a/test/napi/src/js/typedarrays.rs +++ b/test/napi/src/js/typedarrays.rs @@ -216,7 +216,7 @@ where Ok(obj) } -fn detach_and_then<'cx, F>(mut cx: FunctionContext<'cx>, f: F) -> JsResult +fn detach_and_then<'cx, F>(mut cx: FunctionContext<'cx>, f: F) -> JsResult<'cx, JsObject> where F: FnOnce( &mut FunctionContext<'cx>,