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
@@ -4717,7 +4723,8 @@ inline napi_value InstanceWrap<T>::WrappedMethod(
47174723// //////////////////////////////////////////////////////////////////////////////
47184724
47194725template <typename T>
4720- inline ObjectWrap<T>::ObjectWrap (const Napi::CallbackInfo& callbackInfo) {
4726+ inline NAPI_NO_SANITIZE_VPTR ObjectWrap<T>::ObjectWrap (
4727+ const Napi::CallbackInfo& callbackInfo) {
47214728 napi_env env = callbackInfo.Env ();
47224729 napi_value wrapper = callbackInfo.This ();
47234730 napi_status status;
@@ -4731,7 +4738,7 @@ inline ObjectWrap<T>::ObjectWrap(const Napi::CallbackInfo& callbackInfo) {
47314738}
47324739
47334740template <typename T>
4734- inline ObjectWrap<T>::~ObjectWrap () {
4741+ inline NAPI_NO_SANITIZE_VPTR ObjectWrap<T>::~ObjectWrap () {
47354742 // If the JS object still exists at this point, remove the finalizer added
47364743 // through `napi_wrap()`.
47374744 if (!IsEmpty () && !_finalized) {
@@ -4744,8 +4751,12 @@ inline ObjectWrap<T>::~ObjectWrap() {
47444751 }
47454752}
47464753
4754+ // with RTTI turned on, modern compilers check to see if virtual function
4755+ // pointers are stripped of RTTI by void casts. this is intrinsic to how Unwrap
4756+ // works, so we inject a compiler pragma to turn off that check just for the
4757+ // affected methods. this compiler check is on by default in Android NDK 29.
47474758template <typename T>
4748- inline T* ObjectWrap<T>::Unwrap (Object wrapper) {
4759+ inline NAPI_NO_SANITIZE_VPTR T* ObjectWrap<T>::Unwrap (Object wrapper) {
47494760 void * unwrapped;
47504761 napi_status status = napi_unwrap (wrapper.Env (), wrapper, &unwrapped);
47514762 NAPI_THROW_IF_FAILED (wrapper.Env (), status, nullptr );
@@ -7030,4 +7041,6 @@ inline void BasicEnv::PostFinalizer(FinalizerType finalizeCallback,
70307041
70317042} // namespace Napi
70327043
7044+ #undef NAPI_NO_SANITIZE_VPTR
7045+
70337046#endif // SRC_NAPI_INL_H_
0 commit comments