From 4dc05a97734a44a96638d5015d4acba2398a63e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi?= Date: Thu, 22 Oct 2026 15:17:00 +0200 Subject: [PATCH] Fix compile errors for Electron 45 (V8 15.6) V8 15.6 removed two things that were only deprecated in V8 15.2: * PropertyCallbackInfo::HolderV2() is gone (only Holder() remains), so v8this() had no valid overload for property callbacks. It now falls back to Holder() when neither HolderV2() nor This() exists. * NamedPropertyHandlerConfiguration / IndexedPropertyHandlerConfiguration only accept setter callbacks taking PropertyCallbackInfo (NamedPropertySetterCallbackV2 / IndexedPropertySetterCallback). PropertyCallbackInfoSetter is now PropertyCallbackInfo for V8 >= 15 (V8 15.0 and 15.2 already accept it, as well). --- src/utils.h | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/utils.h b/src/utils.h index d22efbb..2d701bf 100644 --- a/src/utils.h +++ b/src/utils.h @@ -25,7 +25,13 @@ #if (V8_MAJOR_VERSION >= 12) #define NODE_INTERCEPTED typedef PropertyCallbackInfo PropertyCallbackInfoGetter; +#if (V8_MAJOR_VERSION >= 15) +// V8 15.6 (Electron 45) only accepts setter callbacks taking PropertyCallbackInfo +// (NamedPropertySetterCallbackV2 / IndexedPropertySetterCallback). It is already accepted by 15.0 and 15.2. +typedef PropertyCallbackInfo PropertyCallbackInfoSetter; +#else typedef PropertyCallbackInfo PropertyCallbackInfoSetter; +#endif #else typedef PropertyCallbackInfo PropertyCallbackInfoGetter; typedef PropertyCallbackInfo PropertyCallbackInfoSetter; @@ -62,16 +68,24 @@ inline Local v8str(Isolate *isolate, const wchar_t *text) { return v8str(isolate, (const uint16_t *)text); } +// Object targeted by a callback: This() for a FunctionCallbackInfo, HolderV2() for a PropertyCallbackInfo +// while it exists (up to V8 15.2 at least), and Holder() for a PropertyCallbackInfo once HolderV2() is gone (V8 15.6). +template +struct has_holder_v2 : std::false_type {}; template -using is_holder_v2 = std::is_member_function_pointer; - -template -inline std::enable_if::value, Local>::type -v8this(const T& args) { return args.This(); } +struct has_holder_v2().HolderV2())>> : std::true_type {}; + +template +struct has_this : std::false_type {}; +template +struct has_this().This())>> : std::true_type {}; template -inline std::enable_if::value, Local>::type -v8this(const T& args) { return args.HolderV2(); } +inline Local v8this(const T& args) { + if constexpr (has_holder_v2::value) { return args.HolderV2(); } + else if constexpr (has_this::value) { return args.This(); } + else { return args.Holder(); } +} //------------------------------------------------------------------------------------------------------- #ifndef USE_ATL