From a7df36eda8a7fe8581c00a18590f5e4faafca7ae Mon Sep 17 00:00:00 2001 From: Toshiyuki Ogawa Date: Thu, 10 Oct 2024 08:39:41 +0900 Subject: [PATCH] Support for node version 20.17.0 (#976) * Support for electron 32 refs #973 --- README.md | 2 +- doc/v8_internals.md | 8 +-- nan.h | 64 ++++++++++++++++- nan_callbacks.h | 38 +++++++++- nan_callbacks_12_inl.h | 158 ++++++++++++++++++++++++++++++++++++++++- nan_scriptorigin.h | 19 ++++- 6 files changed, 278 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index b800945d..7f70a135 100644 --- a/README.md +++ b/README.md @@ -297,7 +297,7 @@ The hooks to access V8 internals—including GC and statistics—are different a - Nan::SetCounterFunction() - Nan::SetCreateHistogramFunction() - Nan::SetAddHistogramSampleFunction() - - Nan::IdleNotification() + - Nan::IdleNotification() - Nan::LowMemoryNotification() - Nan::ContextDisposedNotification() - Nan::GetInternalFieldPointer() diff --git a/doc/v8_internals.md b/doc/v8_internals.md index 08dd6d04..2e7c918b 100644 --- a/doc/v8_internals.md +++ b/doc/v8_internals.md @@ -11,7 +11,7 @@ The hooks to access V8 internals—including GC and statistics—are different a - Nan::SetCounterFunction() - Nan::SetCreateHistogramFunction() - Nan::SetAddHistogramSampleFunction() - - Nan::IdleNotification() + - Nan::IdleNotification() - Nan::LowMemoryNotification() - Nan::ContextDisposedNotification() - Nan::GetInternalFieldPointer() @@ -128,15 +128,15 @@ void Nan::SetAddHistogramSampleFunction(v8::AddHistogramSampleCallback cb) Calls V8's [`SetAddHistogramSampleFunction()`](https://v8docs.nodesource.com/node-8.16/d5/dda/classv8_1_1_isolate.html#aeb420b690bc2c216882d6fdd00ddd3ea). -### Nan::IdleNotification() +### Nan::IdleNotification() Signature: ```c++ -bool Nan::IdleNotification(int idle_time_in_ms) +NAN_DEPRECATED bool Nan::IdleNotification(int idle_time_in_ms) ``` -Calls V8's [`IdleNotification()` or `IdleNotificationDeadline()`](https://v8docs.nodesource.com/node-8.16/d5/dda/classv8_1_1_isolate.html#ad6a2a02657f5425ad460060652a5a118) depending on V8 version. +Calls V8's [`IdleNotification()` or `IdleNotificationDeadline()`](https://v8docs.nodesource.com/node-8.16/d5/dda/classv8_1_1_isolate.html#ad6a2a02657f5425ad460060652a5a118) depending on V8 version. Removed in V8 12.7.41. ### Nan::LowMemoryNotification() diff --git a/nan.h b/nan.h index decc804c..ca11a77a 100644 --- a/nan.h +++ b/nan.h @@ -694,14 +694,21 @@ inline uv_loop_t* GetCurrentEventLoop() { v8::Isolate::GetCurrent()->SetAddHistogramSampleFunction(cb); } -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION >= 7)) + NAN_DEPRECATED inline bool IdleNotification(int) { + return true; + } +# elif defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) - inline bool IdleNotification(int idle_time_in_ms) { + NAN_DEPRECATED inline bool IdleNotification(int idle_time_in_ms) { return v8::Isolate::GetCurrent()->IdleNotificationDeadline( idle_time_in_ms * 0.001); } # else - inline bool IdleNotification(int idle_time_in_ms) { + NAN_DEPRECATED inline bool IdleNotification(int idle_time_in_ms) { return v8::Isolate::GetCurrent()->IdleNotification(idle_time_in_ms); } #endif @@ -1546,11 +1553,23 @@ typedef void NAN_SETTER_RETURN_TYPE; typedef const PropertyCallbackInfo& NAN_PROPERTY_GETTER_ARGS_TYPE; +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4)) +typedef v8::Intercepted NAN_PROPERTY_GETTER_RETURN_TYPE; +#else typedef void NAN_PROPERTY_GETTER_RETURN_TYPE; +#endif +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4)) +typedef const PropertyCallbackInfo& + NAN_PROPERTY_SETTER_ARGS_TYPE; +typedef v8::Intercepted NAN_PROPERTY_SETTER_RETURN_TYPE; +#else typedef const PropertyCallbackInfo& NAN_PROPERTY_SETTER_ARGS_TYPE; typedef void NAN_PROPERTY_SETTER_RETURN_TYPE; +#endif typedef const PropertyCallbackInfo& NAN_PROPERTY_ENUMERATOR_ARGS_TYPE; @@ -1558,29 +1577,68 @@ typedef void NAN_PROPERTY_ENUMERATOR_RETURN_TYPE; typedef const PropertyCallbackInfo& NAN_PROPERTY_DELETER_ARGS_TYPE; + +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4)) +typedef v8::Intercepted NAN_PROPERTY_DELETER_RETURN_TYPE; +#else typedef void NAN_PROPERTY_DELETER_RETURN_TYPE; +#endif + typedef const PropertyCallbackInfo& NAN_PROPERTY_QUERY_ARGS_TYPE; +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4)) +typedef v8::Intercepted NAN_PROPERTY_QUERY_RETURN_TYPE; +#else typedef void NAN_PROPERTY_QUERY_RETURN_TYPE; +#endif typedef const PropertyCallbackInfo& NAN_INDEX_GETTER_ARGS_TYPE; +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4)) +typedef v8::Intercepted NAN_INDEX_GETTER_RETURN_TYPE; +#else typedef void NAN_INDEX_GETTER_RETURN_TYPE; +#endif + +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4)) +typedef const PropertyCallbackInfo& NAN_INDEX_SETTER_ARGS_TYPE; +typedef v8::Intercepted NAN_INDEX_SETTER_RETURN_TYPE; +#else typedef const PropertyCallbackInfo& NAN_INDEX_SETTER_ARGS_TYPE; typedef void NAN_INDEX_SETTER_RETURN_TYPE; +#endif typedef const PropertyCallbackInfo& NAN_INDEX_ENUMERATOR_ARGS_TYPE; +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4)) +typedef v8::Intercepted NAN_INDEX_ENUMERATOR_RETURN_TYPE; +#else typedef void NAN_INDEX_ENUMERATOR_RETURN_TYPE; +#endif typedef const PropertyCallbackInfo& NAN_INDEX_DELETER_ARGS_TYPE; +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4)) +typedef v8::Intercepted NAN_INDEX_DELETER_RETURN_TYPE; +#else typedef void NAN_INDEX_DELETER_RETURN_TYPE; +#endif typedef const PropertyCallbackInfo& NAN_INDEX_QUERY_ARGS_TYPE; +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4)) +typedef v8::Intercepted NAN_INDEX_QUERY_RETURN_TYPE; +#else typedef void NAN_INDEX_QUERY_RETURN_TYPE; +#endif #define NAN_METHOD(name) \ Nan::NAN_METHOD_RETURN_TYPE name(Nan::NAN_METHOD_ARGS_TYPE info) diff --git a/nan_callbacks.h b/nan_callbacks.h index 93eb2ab4..2c54857f 100644 --- a/nan_callbacks.h +++ b/nan_callbacks.h @@ -20,6 +20,17 @@ typedef void(*SetterCallback)( v8::Local, v8::Local, const PropertyCallbackInfo&); + +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4)) +typedef v8::Intercepted(*PropertyGetterCallback)( + v8::Local, + const PropertyCallbackInfo&); +typedef v8::Intercepted(*PropertySetterCallback)( + v8::Local, + v8::Local, + const PropertyCallbackInfo&); +#else typedef void(*PropertyGetterCallback)( v8::Local, const PropertyCallbackInfo&); @@ -27,8 +38,33 @@ typedef void(*PropertySetterCallback)( v8::Local, v8::Local, const PropertyCallbackInfo&); +#endif typedef void(*PropertyEnumeratorCallback) (const PropertyCallbackInfo&); +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4)) +typedef v8::Intercepted(*PropertyDeleterCallback)( + v8::Local, + const PropertyCallbackInfo&); +typedef v8::Intercepted(*PropertyQueryCallback)( + v8::Local, + const PropertyCallbackInfo&); +typedef v8::Intercepted(*IndexGetterCallback)( + uint32_t, + const PropertyCallbackInfo&); +typedef v8::Intercepted(*IndexSetterCallback)( + uint32_t, + v8::Local, + const PropertyCallbackInfo&); +typedef v8::Intercepted(*IndexEnumeratorCallback) + (const PropertyCallbackInfo&); +typedef v8::Intercepted(*IndexDeleterCallback)( + uint32_t, + const PropertyCallbackInfo&); +typedef v8::Intercepted(*IndexQueryCallback)( + uint32_t, + const PropertyCallbackInfo&); +#else typedef void(*PropertyDeleterCallback)( v8::Local, const PropertyCallbackInfo&); @@ -50,7 +86,7 @@ typedef void(*IndexDeleterCallback)( typedef void(*IndexQueryCallback)( uint32_t, const PropertyCallbackInfo&); - +#endif namespace imp { #if (NODE_MODULE_VERSION < NODE_16_0_MODULE_VERSION) typedef v8::Local Sig; diff --git a/nan_callbacks_12_inl.h b/nan_callbacks_12_inl.h index bbcde4d6..f953989a 100644 --- a/nan_callbacks_12_inl.h +++ b/nan_callbacks_12_inl.h @@ -256,6 +256,47 @@ typedef void (*NativeSetter)( #endif #if NODE_MODULE_VERSION > NODE_0_12_MODULE_VERSION + +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4)) +static +v8::Intercepted PropertyGetterCallbackWrapper( + v8::Local property + , const v8::PropertyCallbackInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex).As()); + PropertyGetterCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kPropertyGetterIndex) + .As().As()->Value())); + return callback(property.As(), cbinfo); +} + +typedef v8::Intercepted (*NativePropertyGetter) + (v8::Local, const v8::PropertyCallbackInfo &); + +static +v8::Intercepted PropertySetterCallbackWrapper( + v8::Local property + , v8::Local value + , const v8::PropertyCallbackInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex).As()); + PropertySetterCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kPropertySetterIndex) + .As().As()->Value())); + return callback(property.As(), value, cbinfo); +} + +typedef v8::Intercepted (*NativePropertySetter)( + v8::Local + , v8::Local + , const v8::PropertyCallbackInfo &); + +#else static void PropertyGetterCallbackWrapper( v8::Local property @@ -292,6 +333,7 @@ typedef void (*NativePropertySetter)( v8::Local , v8::Local , const v8::PropertyCallbackInfo &); +#endif static void PropertyEnumeratorCallbackWrapper( @@ -309,6 +351,43 @@ void PropertyEnumeratorCallbackWrapper( typedef void (*NativePropertyEnumerator) (const v8::PropertyCallbackInfo &); +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4)) +static +v8::Intercepted PropertyDeleterCallbackWrapper( + v8::Local property + , const v8::PropertyCallbackInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex).As()); + PropertyDeleterCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kPropertyDeleterIndex) + .As().As()->Value())); + return callback(property.As(), cbinfo); +} + +typedef v8::Intercepted (NativePropertyDeleter) + (v8::Local, const v8::PropertyCallbackInfo &); + + +static +v8::Intercepted PropertyQueryCallbackWrapper( + v8::Local property + , const v8::PropertyCallbackInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex).As()); + PropertyQueryCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kPropertyQueryIndex) + .As().As()->Value())); + return callback(property.As(), cbinfo); +} + +typedef v8::Intercepted (*NativePropertyQuery) + (v8::Local, const v8::PropertyCallbackInfo &); +#else static void PropertyDeleterCallbackWrapper( v8::Local property @@ -342,6 +421,7 @@ void PropertyQueryCallbackWrapper( typedef void (*NativePropertyQuery) (v8::Local, const v8::PropertyCallbackInfo &); +#endif #else static void PropertyGetterCallbackWrapper( @@ -431,6 +511,45 @@ typedef void (*NativePropertyQuery) (v8::Local, const v8::PropertyCallbackInfo &); #endif +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4)) +static +v8::Intercepted IndexGetterCallbackWrapper( + uint32_t index, const v8::PropertyCallbackInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex).As()); + IndexGetterCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kIndexPropertyGetterIndex) + .As().As()->Value())); + return callback(index, cbinfo); +} + +typedef v8::Intercepted (*NativeIndexGetter) + (uint32_t, const v8::PropertyCallbackInfo &); + +static +v8::Intercepted IndexSetterCallbackWrapper( + uint32_t index + , v8::Local value + , const v8::PropertyCallbackInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex).As()); + IndexSetterCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kIndexPropertySetterIndex) + .As().As()->Value())); + return callback(index, value, cbinfo); +} + +typedef v8::Intercepted (*NativeIndexSetter)( + uint32_t + , v8::Local + , const v8::PropertyCallbackInfo &); + +#else static void IndexGetterCallbackWrapper( uint32_t index, const v8::PropertyCallbackInfo &info) { @@ -446,7 +565,6 @@ void IndexGetterCallbackWrapper( typedef void (*NativeIndexGetter) (uint32_t, const v8::PropertyCallbackInfo &); - static void IndexSetterCallbackWrapper( uint32_t index @@ -467,6 +585,8 @@ typedef void (*NativeIndexSetter)( , v8::Local , const v8::PropertyCallbackInfo &); +#endif + static void IndexEnumeratorCallbackWrapper( const v8::PropertyCallbackInfo &info) { @@ -484,6 +604,40 @@ void IndexEnumeratorCallbackWrapper( typedef void (*NativeIndexEnumerator) (const v8::PropertyCallbackInfo &); +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 4)) +static +v8::Intercepted IndexDeleterCallbackWrapper( + uint32_t index, const v8::PropertyCallbackInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex).As()); + IndexDeleterCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kIndexPropertyDeleterIndex) + .As().As()->Value())); + return callback(index, cbinfo); +} + +typedef v8::Intercepted (*NativeIndexDeleter) + (uint32_t, const v8::PropertyCallbackInfo &); + +static +v8::Intercepted IndexQueryCallbackWrapper( + uint32_t index, const v8::PropertyCallbackInfo &info) { + v8::Local obj = info.Data().As(); + PropertyCallbackInfo + cbinfo(info, obj->GetInternalField(kDataIndex).As()); + IndexQueryCallback callback = reinterpret_cast( + reinterpret_cast( + obj->GetInternalField(kIndexPropertyQueryIndex) + .As().As()->Value())); + return callback(index, cbinfo); +} + +typedef v8::Intercepted (*NativeIndexQuery) + (uint32_t, const v8::PropertyCallbackInfo &); +#else static void IndexDeleterCallbackWrapper( uint32_t index, const v8::PropertyCallbackInfo &info) { @@ -515,6 +669,8 @@ void IndexQueryCallbackWrapper( typedef void (*NativeIndexQuery) (uint32_t, const v8::PropertyCallbackInfo &); + +#endif } // end of namespace imp #endif // NAN_CALLBACKS_12_INL_H_ diff --git a/nan_scriptorigin.h b/nan_scriptorigin.h index ce79cdf8..04e55cf5 100644 --- a/nan_scriptorigin.h +++ b/nan_scriptorigin.h @@ -11,7 +11,24 @@ class ScriptOrigin : public v8::ScriptOrigin { public: -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 9 || \ + +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 11 \ + && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 7) + explicit ScriptOrigin(v8::Local name) : + v8::ScriptOrigin(name) {} + + ScriptOrigin(v8::Local name + , v8::Local line) : + v8::ScriptOrigin(name + , To(line).FromMaybe(0)) {} + + ScriptOrigin(v8::Local name + , v8::Local line + , v8::Local column) : + v8::ScriptOrigin(name + , To(line).FromMaybe(0) + , To(column).FromMaybe(0)) {} +#elif defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 9 || \ (V8_MAJOR_VERSION == 9 && (defined(V8_MINOR_VERSION) && (V8_MINOR_VERSION > 0\ || (V8_MINOR_VERSION == 0 && defined(V8_BUILD_NUMBER) \ && V8_BUILD_NUMBER >= 1)))))