2121#include < type_traits>
2222#include < utility>
2323
24+ #if defined(__clang__) || defined(__GNUC__)
25+ #define NAPI_NO_SANITIZE_VPTR __attribute__ ((no_sanitize(" vptr" )))
26+ #else
27+ #define NAPI_NO_SANITIZE_VPTR
28+ #endif
29+
2430namespace Napi {
2531
2632#ifdef NAPI_CPP_CUSTOM_NAMESPACE
@@ -4779,7 +4785,8 @@ inline napi_value InstanceWrap<T>::WrappedMethod(
47794785// //////////////////////////////////////////////////////////////////////////////
47804786
47814787template <typename T>
4782- inline ObjectWrap<T>::ObjectWrap (const Napi::CallbackInfo& callbackInfo) {
4788+ inline NAPI_NO_SANITIZE_VPTR ObjectWrap<T>::ObjectWrap (
4789+ const Napi::CallbackInfo& callbackInfo) {
47834790 napi_env env = callbackInfo.Env ();
47844791 napi_value wrapper = callbackInfo.This ();
47854792 napi_status status;
@@ -4793,7 +4800,7 @@ inline ObjectWrap<T>::ObjectWrap(const Napi::CallbackInfo& callbackInfo) {
47934800}
47944801
47954802template <typename T>
4796- inline ObjectWrap<T>::~ObjectWrap () {
4803+ inline NAPI_NO_SANITIZE_VPTR ObjectWrap<T>::~ObjectWrap () {
47974804 // If the JS object still exists at this point, remove the finalizer added
47984805 // through `napi_wrap()`.
47994806 if (!IsEmpty () && !_finalized) {
@@ -4806,8 +4813,12 @@ inline ObjectWrap<T>::~ObjectWrap() {
48064813 }
48074814}
48084815
4816+ // with RTTI turned on, modern compilers check to see if virtual function
4817+ // pointers are stripped of RTTI by void casts. this is intrinsic to how Unwrap
4818+ // works, so we inject a compiler pragma to turn off that check just for the
4819+ // affected methods. this compiler check is on by default in Android NDK 29.
48094820template <typename T>
4810- inline T* ObjectWrap<T>::Unwrap (Object wrapper) {
4821+ inline NAPI_NO_SANITIZE_VPTR T* ObjectWrap<T>::Unwrap (Object wrapper) {
48114822 void * unwrapped;
48124823 napi_status status = napi_unwrap (wrapper.Env (), wrapper, &unwrapped);
48134824 NAPI_THROW_IF_FAILED (wrapper.Env (), status, nullptr );
@@ -7092,4 +7103,6 @@ inline void BasicEnv::PostFinalizer(FinalizerType finalizeCallback,
70927103
70937104} // namespace Napi
70947105
7106+ #undef NAPI_NO_SANITIZE_VPTR
7107+
70957108#endif // SRC_NAPI_INL_H_
0 commit comments