diff --git a/napi/src/call_context.rs b/napi/src/call_context.rs index 4cd60c65..21c97c75 100644 --- a/napi/src/call_context.rs +++ b/napi/src/call_context.rs @@ -74,7 +74,7 @@ impl<'env> CallContext<'env> { } #[inline(always)] - pub unsafe fn this_unchecked(&self) -> T { - T::from_raw_unchecked(self.env.0, self.raw_this) + pub fn this_unchecked(&self) -> T { + unsafe { T::from_raw_unchecked(self.env.0, self.raw_this) } } } diff --git a/test_module/src/class.rs b/test_module/src/class.rs index 19ef82c8..58de0572 100644 --- a/test_module/src/class.rs +++ b/test_module/src/class.rs @@ -19,7 +19,7 @@ fn create_test_class(ctx: CallContext) -> Result { #[js_function(1)] fn test_class_constructor(ctx: CallContext) -> Result { let count: i32 = ctx.get::(0)?.try_into()?; - let mut this: JsObject = unsafe { ctx.this_unchecked() }; + let mut this: JsObject = ctx.this_unchecked(); ctx .env .wrap(&mut this, NativeClass { value: count + 100 })?; @@ -30,7 +30,7 @@ fn test_class_constructor(ctx: CallContext) -> Result { #[js_function(1)] fn add_count(ctx: CallContext) -> Result { let add: i32 = ctx.get::(0)?.try_into()?; - let mut this: JsObject = unsafe { ctx.this_unchecked() }; + let mut this: JsObject = ctx.this_unchecked(); let count: i32 = this.get_named_property::("count")?.try_into()?; this.set_named_property("count", ctx.env.create_int32(count + add)?)?; ctx.env.get_undefined() @@ -39,7 +39,7 @@ fn add_count(ctx: CallContext) -> Result { #[js_function(1)] fn add_native_count(ctx: CallContext) -> Result { let add: i32 = ctx.get::(0)?.try_into()?; - let this: JsObject = unsafe { ctx.this_unchecked() }; + let this: JsObject = ctx.this_unchecked(); let native_class: &mut NativeClass = ctx.env.unwrap(&this)?; native_class.value = native_class.value + add; ctx.env.create_int32(native_class.value) diff --git a/test_module/src/function.rs b/test_module/src/function.rs index dfbea834..94cd8c6b 100644 --- a/test_module/src/function.rs +++ b/test_module/src/function.rs @@ -13,7 +13,7 @@ pub fn call_function(ctx: CallContext) -> Result { #[js_function(1)] pub fn call_function_with_this(ctx: CallContext) -> Result { - let js_this: JsObject = unsafe { ctx.this_unchecked() }; + let js_this: JsObject = ctx.this_unchecked(); let js_func = ctx.get::(0)?; js_func.call(Some(&js_this), &[])?; diff --git a/test_module/src/object.rs b/test_module/src/object.rs index 753b05c6..fef07abc 100644 --- a/test_module/src/object.rs +++ b/test_module/src/object.rs @@ -146,7 +146,7 @@ fn test_define_properties(ctx: CallContext) -> Result { #[js_function(1)] fn add(ctx: CallContext) -> Result { - let mut this: JsObject = unsafe { ctx.this_unchecked() }; + let mut this: JsObject = ctx.this_unchecked(); let count: i32 = this.get_named_property::("count")?.try_into()?; let value_to_add: i32 = ctx.get::(0)?.try_into()?; this.set_named_property("count", ctx.env.create_int32(count + value_to_add)?)?;