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