diff --git a/src/prototype.h b/src/prototype.h index a6f4f4e..b99ce33 100644 --- a/src/prototype.h +++ b/src/prototype.h @@ -92,6 +92,12 @@ struct Type && void* result; if (napi_unwrap(env, value, &result) != napi_ok) return std::nullopt; + if (internal::CanCachePointer::value) { + // Check if the pointer has been released by user. + napi_value obj; + if (!InstanceData::Get(env)->GetWeakRef(result, &obj)) + return std::nullopt; + } if (!internal::IsInstanceOf(env, value)) return std::nullopt; T* ptr = internal::Unwrap::Do(result);