refactor: change more generic constraint from NapiValue => NapiRaw
This commit is contained in:
parent
07a60125d5
commit
457cc6f1ee
5 changed files with 19 additions and 19 deletions
|
@ -520,7 +520,7 @@ impl Env {
|
|||
pub fn create_function_from_closure<R, F>(&self, name: &str, callback: F) -> Result<JsFunction>
|
||||
where
|
||||
F: 'static + Send + Sync + Fn(crate::CallContext<'_>) -> Result<R>,
|
||||
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<R: NapiValue, F: Fn(CallContext<'_>) -> Result<R>>(
|
||||
unsafe extern "C" fn trampoline<R: NapiRaw, F: Fn(CallContext<'_>) -> Result<R>>(
|
||||
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<T>(&self, value: T) -> Result<Ref<()>>
|
||||
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<T>) -> Result<Vec<V>>,
|
||||
>(
|
||||
&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<A: NapiValue, B: NapiValue>(&self, a: A, b: B) -> Result<bool> {
|
||||
pub fn strict_equals<A: NapiRaw, B: NapiRaw>(&self, a: A, b: B) -> Result<bool> {
|
||||
let mut result = false;
|
||||
check_status!(unsafe { sys::napi_strict_equals(self.0, a.raw(), b.raw(), &mut result) })?;
|
||||
Ok(result)
|
||||
|
|
|
@ -114,7 +114,7 @@ impl JsBigint {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn instanceof<Constructor: NapiValue>(&self, constructor: Constructor) -> Result<bool> {
|
||||
pub fn instanceof<Constructor: NapiRaw>(&self, constructor: Constructor) -> Result<bool> {
|
||||
let mut result = false;
|
||||
check_status!(unsafe {
|
||||
sys::napi_instanceof(self.raw.env, self.raw.value, constructor.raw(), &mut result)
|
||||
|
|
|
@ -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<T: NapiValue> {
|
||||
pub struct EscapableHandleScope<T: NapiRaw> {
|
||||
handle_scope: sys::napi_escapable_handle_scope,
|
||||
value: T,
|
||||
}
|
||||
|
||||
impl<T: NapiValue> EscapableHandleScope<T> {
|
||||
impl<T: NapiRaw> EscapableHandleScope<T> {
|
||||
#[inline]
|
||||
pub fn open(env: sys::napi_env, value: T) -> Result<Self> {
|
||||
let mut handle_scope = ptr::null_mut();
|
||||
|
@ -29,7 +29,7 @@ impl<T: NapiValue> EscapableHandleScope<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: NapiValue> Deref for EscapableHandleScope<T> {
|
||||
impl<T: NapiRaw> Deref for EscapableHandleScope<T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &T {
|
||||
|
|
|
@ -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<T, V: NapiValue> {
|
||||
pub struct FuturePromise<T, V: NapiRaw> {
|
||||
deferred: sys::napi_deferred,
|
||||
env: sys::napi_env,
|
||||
tsfn: sys::napi_threadsafe_function,
|
||||
|
@ -13,9 +13,9 @@ pub struct FuturePromise<T, V: NapiValue> {
|
|||
resolver: Box<dyn FnOnce(&mut Env, T) -> Result<V>>,
|
||||
}
|
||||
|
||||
unsafe impl<T, V: NapiValue> Send for FuturePromise<T, V> {}
|
||||
unsafe impl<T, V: NapiRaw> Send for FuturePromise<T, V> {}
|
||||
|
||||
impl<T, V: NapiValue> FuturePromise<T, V> {
|
||||
impl<T, V: NapiRaw> FuturePromise<T, V> {
|
||||
#[inline]
|
||||
pub fn create(
|
||||
env: sys::napi_env,
|
||||
|
@ -95,7 +95,7 @@ pub(crate) async fn resolve_from_future<T: Send, F: Future<Output = Result<T>>>(
|
|||
.expect("Failed to release thread safe function");
|
||||
}
|
||||
|
||||
unsafe extern "C" fn call_js_cb<T, V: NapiValue>(
|
||||
unsafe extern "C" fn call_js_cb<T, V: NapiRaw>(
|
||||
raw_env: sys::napi_env,
|
||||
_js_callback: sys::napi_value,
|
||||
context: *mut c_void,
|
||||
|
|
|
@ -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<T: 'static, ES: ErrorStrategy::T> ThreadsafeFunction<T, ES> {
|
|||
/// for more information.
|
||||
#[inline]
|
||||
pub fn create<
|
||||
V: NapiValue,
|
||||
V: NapiRaw,
|
||||
R: 'static + Send + FnMut(ThreadSafeCallContext<T>) -> Result<Vec<V>>,
|
||||
>(
|
||||
env: sys::napi_env,
|
||||
|
@ -326,7 +326,7 @@ impl<T: 'static, ES: ErrorStrategy::T> Drop for ThreadsafeFunction<T, ES> {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe extern "C" fn thread_finalize_cb<T: 'static, V: NapiValue, R>(
|
||||
unsafe extern "C" fn thread_finalize_cb<T: 'static, V: NapiRaw, R>(
|
||||
_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<T: 'static, V: NapiValue, R>(
|
|||
drop(Box::<R>::from_raw(finalize_data.cast()));
|
||||
}
|
||||
|
||||
unsafe extern "C" fn call_js_cb<T: 'static, V: NapiValue, R, ES>(
|
||||
unsafe extern "C" fn call_js_cb<T: 'static, V: NapiRaw, R, ES>(
|
||||
raw_env: sys::napi_env,
|
||||
js_callback: sys::napi_value,
|
||||
context: *mut c_void,
|
||||
|
|
Loading…
Reference in a new issue