chore(napi): remove unsafe from CallContext::this_unchecked
This commit is contained in:
parent
89d507d522
commit
e337a58714
4 changed files with 7 additions and 7 deletions
|
@ -74,7 +74,7 @@ impl<'env> CallContext<'env> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn this_unchecked<T: NapiValue>(&self) -> T {
|
||||
T::from_raw_unchecked(self.env.0, self.raw_this)
|
||||
pub fn this_unchecked<T: NapiValue>(&self) -> T {
|
||||
unsafe { T::from_raw_unchecked(self.env.0, self.raw_this) }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ fn create_test_class(ctx: CallContext) -> Result<JsFunction> {
|
|||
#[js_function(1)]
|
||||
fn test_class_constructor(ctx: CallContext) -> Result<JsUndefined> {
|
||||
let count: i32 = ctx.get::<JsNumber>(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<JsUndefined> {
|
|||
#[js_function(1)]
|
||||
fn add_count(ctx: CallContext) -> Result<JsUndefined> {
|
||||
let add: i32 = ctx.get::<JsNumber>(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::<JsNumber>("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<JsUndefined> {
|
|||
#[js_function(1)]
|
||||
fn add_native_count(ctx: CallContext) -> Result<JsNumber> {
|
||||
let add: i32 = ctx.get::<JsNumber>(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)
|
||||
|
|
|
@ -13,7 +13,7 @@ pub fn call_function(ctx: CallContext) -> Result<JsNull> {
|
|||
|
||||
#[js_function(1)]
|
||||
pub fn call_function_with_this(ctx: CallContext) -> Result<JsNull> {
|
||||
let js_this: JsObject = unsafe { ctx.this_unchecked() };
|
||||
let js_this: JsObject = ctx.this_unchecked();
|
||||
let js_func = ctx.get::<JsFunction>(0)?;
|
||||
|
||||
js_func.call(Some(&js_this), &[])?;
|
||||
|
|
|
@ -146,7 +146,7 @@ fn test_define_properties(ctx: CallContext) -> Result<JsUndefined> {
|
|||
|
||||
#[js_function(1)]
|
||||
fn add(ctx: CallContext) -> Result<JsUndefined> {
|
||||
let mut this: JsObject = unsafe { ctx.this_unchecked() };
|
||||
let mut this: JsObject = ctx.this_unchecked();
|
||||
let count: i32 = this.get_named_property::<JsNumber>("count")?.try_into()?;
|
||||
let value_to_add: i32 = ctx.get::<JsNumber>(0)?.try_into()?;
|
||||
this.set_named_property("count", ctx.env.create_int32(count + value_to_add)?)?;
|
||||
|
|
Loading…
Reference in a new issue