Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: change more generic constraint from NapiValue => NapiRaw #565

Merged
merged 1 commit into from May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions napi/src/env.rs
Expand Up @@ -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);
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion napi/src/js_values/bigint.rs
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions napi/src/js_values/escapable_handle_scope.rs
Expand Up @@ -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();
Expand All @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions napi/src/promise.rs
Expand Up @@ -3,19 +3,19 @@ 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,
async_resource_name: sys::napi_value,
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,
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions napi/src/threadsafe_function.rs
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down