Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions napi-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
#include <type_traits>
#include <utility>

#if defined(__clang__) || defined(__GNUC__)
#define NAPI_NO_SANITIZE_VPTR __attribute__((no_sanitize("vptr")))
#else
#define NAPI_NO_SANITIZE_VPTR
#endif

namespace Napi {

#ifdef NAPI_CPP_CUSTOM_NAMESPACE
Expand Down Expand Up @@ -4717,7 +4723,8 @@ inline napi_value InstanceWrap<T>::WrappedMethod(
////////////////////////////////////////////////////////////////////////////////

template <typename T>
inline ObjectWrap<T>::ObjectWrap(const Napi::CallbackInfo& callbackInfo) {
inline NAPI_NO_SANITIZE_VPTR ObjectWrap<T>::ObjectWrap(
const Napi::CallbackInfo& callbackInfo) {
napi_env env = callbackInfo.Env();
napi_value wrapper = callbackInfo.This();
napi_status status;
Expand All @@ -4731,7 +4738,7 @@ inline ObjectWrap<T>::ObjectWrap(const Napi::CallbackInfo& callbackInfo) {
}

template <typename T>
inline ObjectWrap<T>::~ObjectWrap() {
inline NAPI_NO_SANITIZE_VPTR ObjectWrap<T>::~ObjectWrap() {
// If the JS object still exists at this point, remove the finalizer added
// through `napi_wrap()`.
if (!IsEmpty() && !_finalized) {
Expand All @@ -4744,8 +4751,12 @@ inline ObjectWrap<T>::~ObjectWrap() {
}
}

// with RTTI turned on, modern compilers check to see if virtual function
// pointers are stripped of RTTI by void casts. this is intrinsic to how Unwrap
// works, so we inject a compiler pragma to turn off that check just for the
// affected methods. this compiler check is on by default in Android NDK 29.
template <typename T>
inline T* ObjectWrap<T>::Unwrap(Object wrapper) {
inline NAPI_NO_SANITIZE_VPTR T* ObjectWrap<T>::Unwrap(Object wrapper) {
void* unwrapped;
napi_status status = napi_unwrap(wrapper.Env(), wrapper, &unwrapped);
NAPI_THROW_IF_FAILED(wrapper.Env(), status, nullptr);
Expand Down Expand Up @@ -7030,4 +7041,6 @@ inline void BasicEnv::PostFinalizer(FinalizerType finalizeCallback,

} // namespace Napi

#undef NAPI_NO_SANITIZE_VPTR

#endif // SRC_NAPI_INL_H_