fix(napi): import name conflict

This commit is contained in:
LongYinan 2020-11-12 11:41:41 +08:00
parent 4e8a58f9d3
commit add6e2b9dc
No known key found for this signature in database
GPG key ID: A3FFE134A3E20881

View file

@ -156,27 +156,27 @@ macro_rules! register_module {
}
}
use std::ffi::CString;
use std::io::Write;
use std::os::raw::c_char;
use std::ptr;
use $crate::{sys, Env, JsObject, NapiValue};
#[cfg(all(feature = "tokio_rt", feature = "napi4"))]
use $crate::shutdown_tokio_rt;
#[no_mangle]
unsafe extern "C" fn napi_register_module_v1(
raw_env: sys::napi_env,
raw_exports: sys::napi_value,
) -> sys::napi_value {
raw_env: $crate::sys::napi_env,
raw_exports: $crate::sys::napi_value,
) -> $crate::sys::napi_value {
use std::ffi::CString;
use std::io::Write;
use std::os::raw::c_char;
use std::ptr;
use $crate::{Env, JsObject, NapiValue};
#[cfg(all(feature = "tokio_rt", feature = "napi4"))]
use $crate::shutdown_tokio_rt;
let env = Env::from_raw(raw_env);
let mut exports: JsObject = JsObject::from_raw_unchecked(raw_env, raw_exports);
let mut cjs_module = Module { env, exports };
let result = $init(&mut cjs_module);
#[cfg(all(feature = "tokio_rt", feature = "napi4"))]
let hook_result = check_status(unsafe {
sys::napi_add_env_cleanup_hook(raw_env, Some(shutdown_tokio_rt), ptr::null_mut())
$crate::sys::napi_add_env_cleanup_hook(raw_env, Some(shutdown_tokio_rt), ptr::null_mut())
});
#[cfg(not(all(feature = "tokio_rt", feature = "napi4")))]
let hook_result = Ok(());
@ -184,7 +184,7 @@ macro_rules! register_module {
Ok(_) => cjs_module.exports.raw(),
Err(e) => {
unsafe {
sys::napi_throw_error(
$crate::sys::napi_throw_error(
raw_env,
ptr::null(),
CString::from_vec_unchecked(format!("Error initializing module: {}", e).into())