From 457cc6f1eed08ada68f147f6347cdf884fb5e775 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Mon, 17 May 2021 17:29:38 +0800 Subject: [PATCH] refactor: change more generic constraint from NapiValue => NapiRaw --- napi/src/env.rs | 10 +++++----- napi/src/js_values/bigint.rs | 2 +- napi/src/js_values/escapable_handle_scope.rs | 8 ++++---- napi/src/promise.rs | 10 +++++----- napi/src/threadsafe_function.rs | 8 ++++---- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/napi/src/env.rs b/napi/src/env.rs index 717aa8cd..46e4aa44 100644 --- a/napi/src/env.rs +++ b/napi/src/env.rs @@ -520,7 +520,7 @@ impl Env { pub fn create_function_from_closure(&self, name: &str, callback: F) -> Result where F: 'static + Send + Sync + Fn(crate::CallContext<'_>) -> Result, - R: NapiValue, + R: NapiRaw, { use crate::CallContext; let boxed_callback = Box::new(callback); @@ -535,7 +535,7 @@ impl Env { name.as_ptr(), len, Some({ - unsafe extern "C" fn trampoline) -> Result>( + unsafe extern "C" fn trampoline) -> Result>( raw_env: sys::napi_env, cb_info: sys::napi_callback_info, ) -> sys::napi_value { @@ -862,7 +862,7 @@ impl Env { /// This API create a new reference with the specified reference count to the Object passed in. pub fn create_reference(&self, value: T) -> Result> where - T: NapiValue, + T: NapiRaw, { let mut raw_ref = ptr::null_mut(); let initial_ref_count = 1; @@ -1066,7 +1066,7 @@ impl Env { #[inline] pub fn create_threadsafe_function< T: Send, - V: NapiValue, + V: NapiRaw, R: 'static + Send + FnMut(ThreadSafeCallContext) -> Result>, >( &self, @@ -1305,7 +1305,7 @@ impl Env { #[inline] /// This API represents the invocation of the Strict Equality algorithm as defined in [Section 7.2.14](https://tc39.es/ecma262/#sec-strict-equality-comparison) of the ECMAScript Language Specification. - pub fn strict_equals(&self, a: A, b: B) -> Result { + pub fn strict_equals(&self, a: A, b: B) -> Result { let mut result = false; check_status!(unsafe { sys::napi_strict_equals(self.0, a.raw(), b.raw(), &mut result) })?; Ok(result) diff --git a/napi/src/js_values/bigint.rs b/napi/src/js_values/bigint.rs index 993054f1..8adaa0ee 100644 --- a/napi/src/js_values/bigint.rs +++ b/napi/src/js_values/bigint.rs @@ -114,7 +114,7 @@ impl JsBigint { } #[inline] - pub fn instanceof(&self, constructor: Constructor) -> Result { + pub fn instanceof(&self, constructor: Constructor) -> Result { let mut result = false; check_status!(unsafe { sys::napi_instanceof(self.raw.env, self.raw.value, constructor.raw(), &mut result) diff --git a/napi/src/js_values/escapable_handle_scope.rs b/napi/src/js_values/escapable_handle_scope.rs index b7282191..a224ea09 100644 --- a/napi/src/js_values/escapable_handle_scope.rs +++ b/napi/src/js_values/escapable_handle_scope.rs @@ -2,14 +2,14 @@ use std::ops::Deref; use std::ptr; use crate::check_status; -use crate::{sys, Env, NapiRaw, NapiValue, Result}; +use crate::{sys, Env, NapiRaw, Result}; -pub struct EscapableHandleScope { +pub struct EscapableHandleScope { handle_scope: sys::napi_escapable_handle_scope, value: T, } -impl EscapableHandleScope { +impl EscapableHandleScope { #[inline] pub fn open(env: sys::napi_env, value: T) -> Result { let mut handle_scope = ptr::null_mut(); @@ -29,7 +29,7 @@ impl EscapableHandleScope { } } -impl Deref for EscapableHandleScope { +impl Deref for EscapableHandleScope { type Target = T; fn deref(&self) -> &T { diff --git a/napi/src/promise.rs b/napi/src/promise.rs index 5875c7c4..cd32f739 100644 --- a/napi/src/promise.rs +++ b/napi/src/promise.rs @@ -3,9 +3,9 @@ use std::ptr; use futures::prelude::*; -use crate::{check_status, sys, Env, JsError, NapiValue, Result}; +use crate::{check_status, sys, Env, JsError, NapiRaw, Result}; -pub struct FuturePromise { +pub struct FuturePromise { deferred: sys::napi_deferred, env: sys::napi_env, tsfn: sys::napi_threadsafe_function, @@ -13,9 +13,9 @@ pub struct FuturePromise { resolver: Box Result>, } -unsafe impl Send for FuturePromise {} +unsafe impl Send for FuturePromise {} -impl FuturePromise { +impl FuturePromise { #[inline] pub fn create( env: sys::napi_env, @@ -95,7 +95,7 @@ pub(crate) async fn resolve_from_future>>( .expect("Failed to release thread safe function"); } -unsafe extern "C" fn call_js_cb( +unsafe extern "C" fn call_js_cb( raw_env: sys::napi_env, _js_callback: sys::napi_value, context: *mut c_void, diff --git a/napi/src/threadsafe_function.rs b/napi/src/threadsafe_function.rs index b82a7e6c..483fb910 100644 --- a/napi/src/threadsafe_function.rs +++ b/napi/src/threadsafe_function.rs @@ -6,7 +6,7 @@ use std::ptr; use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; use std::sync::Arc; -use crate::{check_status, sys, Env, Error, JsError, JsFunction, NapiValue, Result, Status}; +use crate::{check_status, sys, Env, Error, JsError, JsFunction, NapiRaw, Result, Status}; use sys::napi_threadsafe_function_call_mode; @@ -181,7 +181,7 @@ impl ThreadsafeFunction { /// for more information. #[inline] pub fn create< - V: NapiValue, + V: NapiRaw, R: 'static + Send + FnMut(ThreadSafeCallContext) -> Result>, >( env: sys::napi_env, @@ -326,7 +326,7 @@ impl Drop for ThreadsafeFunction { } } -unsafe extern "C" fn thread_finalize_cb( +unsafe extern "C" fn thread_finalize_cb( _raw_env: sys::napi_env, finalize_data: *mut c_void, _finalize_hint: *mut c_void, @@ -337,7 +337,7 @@ unsafe extern "C" fn thread_finalize_cb( drop(Box::::from_raw(finalize_data.cast())); } -unsafe extern "C" fn call_js_cb( +unsafe extern "C" fn call_js_cb( raw_env: sys::napi_env, js_callback: sys::napi_value, context: *mut c_void,