From 2b0ddf4a21e66cf820e4f0efff0ea803821136c2 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Mon, 6 Nov 2023 11:00:27 +0800 Subject: [PATCH] feat(napi,sys): sync to napi9 (#1781) - Close https://github.com/napi-rs/napi-rs/issues/1600 --- crates/napi/src/env.rs | 2 +- crates/napi/src/error.rs | 4 ++-- crates/sys/src/functions.rs | 43 ++++++++++++++++++++++++++----------- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/crates/napi/src/env.rs b/crates/napi/src/env.rs index 1b5c59dd..4994393f 100644 --- a/crates/napi/src/env.rs +++ b/crates/napi/src/env.rs @@ -672,7 +672,7 @@ impl Env { } /// This API throws a JavaScript SyntaxError with the text provided. - #[cfg(feature = "experimental")] + #[cfg(feature = "napi9")] pub fn throw_syntax_error(&self, msg: &str, code: Option<&str>) -> Result<()> { let code = code.and_then(|s| CString::new(s).ok()); let msg = CString::new(msg)?; diff --git a/crates/napi/src/error.rs b/crates/napi/src/error.rs index 6f8a5d79..ce4db4cc 100644 --- a/crates/napi/src/error.rs +++ b/crates/napi/src/error.rs @@ -213,7 +213,7 @@ pub struct JsTypeError = Status>(Error); pub struct JsRangeError = Status>(Error); -#[cfg(feature = "experimental")] +#[cfg(feature = "napi9")] pub struct JsSyntaxError = Status>(Error); macro_rules! impl_object_methods { @@ -307,7 +307,7 @@ macro_rules! impl_object_methods { impl_object_methods!(JsError, sys::napi_create_error); impl_object_methods!(JsTypeError, sys::napi_create_type_error); impl_object_methods!(JsRangeError, sys::napi_create_range_error); -#[cfg(feature = "experimental")] +#[cfg(feature = "napi9")] impl_object_methods!(JsSyntaxError, sys::node_api_create_syntax_error); #[doc(hidden)] diff --git a/crates/sys/src/functions.rs b/crates/sys/src/functions.rs index 91fa2410..eafdb768 100644 --- a/crates/sys/src/functions.rs +++ b/crates/sys/src/functions.rs @@ -712,18 +712,6 @@ mod napi9 { length: usize, result: *mut napi_value, ) -> napi_status; - } - ); -} - -#[cfg(feature = "experimental")] -mod experimental { - use std::os::raw::c_char; - - use super::super::types::*; - - generate!( - extern "C" { fn node_api_get_module_file_name(env: napi_env, result: *mut *const c_char) -> napi_status; fn node_api_create_syntax_error( env: napi_env, @@ -740,6 +728,37 @@ mod experimental { ); } +#[cfg(feature = "experimental")] +mod experimental { + use std::os::raw::{c_char, c_void}; + + use super::super::types::*; + + generate!( + extern "C" { + fn node_api_create_external_string_latin1( + env: napi_env, + str_: *const c_char, + length: usize, + napi_finalize: napi_finalize, + finalize_hint: *mut c_void, + result: *mut napi_value, + copied: *mut bool, + ) -> napi_status; + + fn node_api_create_external_string_utf16( + env: napi_env, + str_: *const u16, + length: usize, + napi_finalize: napi_finalize, + finalize_hint: *mut c_void, + result: *mut napi_value, + copied: *mut bool, + ) -> napi_status; + } + ); +} + #[cfg(feature = "experimental")] pub use experimental::*; pub use napi1::*;