feat(napi,sys): sync to napi9 (#1781)

- Close https://github.com/napi-rs/napi-rs/issues/1600
This commit is contained in:
LongYinan 2023-11-06 11:00:27 +08:00 committed by GitHub
parent cec062bd4b
commit 2b0ddf4a21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 15 deletions

View file

@ -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)?;

View file

@ -213,7 +213,7 @@ pub struct JsTypeError<S: AsRef<str> = Status>(Error<S>);
pub struct JsRangeError<S: AsRef<str> = Status>(Error<S>);
#[cfg(feature = "experimental")]
#[cfg(feature = "napi9")]
pub struct JsSyntaxError<S: AsRef<str> = Status>(Error<S>);
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)]

View file

@ -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::*;