fix(napi): dropping Error should not call napi-sys if feature is set to noop (#1477)

This commit is contained in:
Hana 2023-02-07 15:45:56 +08:00 committed by GitHub
parent c70c76d8f3
commit 31015652b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -162,13 +162,16 @@ impl From<std::io::Error> for Error {
impl Drop for Error {
fn drop(&mut self) {
if !self.maybe_env.is_null() && !self.maybe_raw.is_null() {
let delete_reference_status =
unsafe { sys::napi_delete_reference(self.maybe_env, self.maybe_raw) };
debug_assert!(
delete_reference_status == sys::Status::napi_ok,
"Delete Error Reference failed"
);
#[cfg(not(feature = "noop"))]
{
if !self.maybe_env.is_null() && !self.maybe_raw.is_null() {
let delete_reference_status =
unsafe { sys::napi_delete_reference(self.maybe_env, self.maybe_raw) };
debug_assert!(
delete_reference_status == sys::Status::napi_ok,
"Delete Error Reference failed"
);
}
}
}
}