From 4981b02b96b7adb0747474a6014b7d6c099bea96 Mon Sep 17 00:00:00 2001 From: Benjamin Byholm Date: Mon, 26 Aug 2024 15:31:56 +0300 Subject: [PATCH 1/5] declare NativeProperyDeleter as a function pointer --- nan.h | 2 +- nan_callbacks_12_inl.h | 2 +- nan_callbacks_pre_12_inl.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/nan.h b/nan.h index decc804c..7fc14a30 100644 --- a/nan.h +++ b/nan.h @@ -2686,7 +2686,7 @@ inline void SetNamedPropertyHandler( setter ? imp::PropertySetterCallbackWrapper : 0; imp::NativePropertyQuery query_ = query ? imp::PropertyQueryCallbackWrapper : 0; - imp::NativePropertyDeleter *deleter_ = + imp::NativePropertyDeleter deleter_ = deleter ? imp::PropertyDeleterCallbackWrapper : 0; imp::NativePropertyEnumerator enumerator_ = enumerator ? imp::PropertyEnumeratorCallbackWrapper : 0; diff --git a/nan_callbacks_12_inl.h b/nan_callbacks_12_inl.h index bbcde4d6..f0351e97 100644 --- a/nan_callbacks_12_inl.h +++ b/nan_callbacks_12_inl.h @@ -323,7 +323,7 @@ void PropertyDeleterCallbackWrapper( callback(property.As(), cbinfo); } -typedef void (NativePropertyDeleter) +typedef void (*NativePropertyDeleter) (v8::Local, const v8::PropertyCallbackInfo &); static diff --git a/nan_callbacks_pre_12_inl.h b/nan_callbacks_pre_12_inl.h index c9ba4993..dd429213 100644 --- a/nan_callbacks_pre_12_inl.h +++ b/nan_callbacks_pre_12_inl.h @@ -409,7 +409,7 @@ v8::Handle PropertyDeleterCallbackWrapper( return ReturnValueImp(cbinfo.GetReturnValue()).Value(); } -typedef v8::Handle (NativePropertyDeleter) +typedef v8::Handle (*NativePropertyDeleter) (v8::Local, const v8::AccessorInfo &); static From 5dfe88343616cd18736f6a28a353c6bc345c0829 Mon Sep 17 00:00:00 2001 From: Benjamin Byholm Date: Sat, 24 Aug 2024 05:05:35 +0300 Subject: [PATCH 2/5] deprecate IdleNotification --- README.md | 2 +- doc/v8_internals.md | 8 ++++---- nan.h | 13 ++++++++++--- 3 files changed, 15 insertions(+), 8 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 7fc14a30..f2937dbd 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 From 9fa23b764bf0863acf7267de2343a0429e37f742 Mon Sep 17 00:00:00 2001 From: Benjamin Byholm Date: Sat, 24 Aug 2024 05:29:04 +0300 Subject: [PATCH 3/5] replace SetAccessor -> SetNativeDataProperty --- nan.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/nan.h b/nan.h index f2937dbd..064edf2e 100644 --- a/nan.h +++ b/nan.h @@ -2564,7 +2564,11 @@ NAN_DEPRECATED inline void SetAccessor( obj->SetInternalField(imp::kDataIndex, data); } +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 5)) + tpl->SetNativeDataProperty( +#else tpl->SetAccessor( +#endif name , getter_ , setter_ @@ -2612,7 +2616,11 @@ inline void SetAccessor( obj->SetInternalField(imp::kDataIndex, data); } +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 12 || (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 5)) + tpl->SetNativeDataProperty( +#else tpl->SetAccessor( +#endif name , getter_ , setter_ @@ -2658,6 +2666,18 @@ inline bool SetAccessor( } #if (NODE_MODULE_VERSION >= NODE_6_0_MODULE_VERSION) +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && \ + V8_MINOR_VERSION >= 5)) + return obj->SetNativeDataProperty( + GetCurrentContext() + , name + , getter_ + , setter_ + , dataobj + , attribute).FromMaybe(false); +#else return obj->SetAccessor( GetCurrentContext() , name @@ -2666,6 +2686,7 @@ inline bool SetAccessor( , dataobj , settings , attribute).FromMaybe(false); +#endif #else return obj->SetAccessor( name From 0151569fd8ce287d675dafd3dac3eeecb59323b3 Mon Sep 17 00:00:00 2001 From: Benjamin Byholm Date: Sat, 24 Aug 2024 05:42:28 +0300 Subject: [PATCH 4/5] remove Isolate from ScriptOrigin --- nan_scriptorigin.h | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/nan_scriptorigin.h b/nan_scriptorigin.h index ce79cdf8..2d1b3c2a 100644 --- a/nan_scriptorigin.h +++ b/nan_scriptorigin.h @@ -11,7 +11,27 @@ class ScriptOrigin : public v8::ScriptOrigin { public: -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 9 || \ +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && \ + (defined(V8_MINOR_VERSION) && \ + (V8_MINOR_VERSION > 6 || \ + (V8_MINOR_VERSION == 6 && defined(V8_BUILD_NUMBER) && \ + V8_BUILD_NUMBER >= 175))))) + 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))))) From 2c18d907564fe9d7f6f4f3ac44471927afd29286 Mon Sep 17 00:00:00 2001 From: Benjamin Byholm Date: Sat, 24 Aug 2024 14:30:59 +0300 Subject: [PATCH 5/5] updated named and indexed property callbacks --- nan_callbacks_12_inl.h | 248 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 248 insertions(+) diff --git a/nan_callbacks_12_inl.h b/nan_callbacks_12_inl.h index f0351e97..ac02cf16 100644 --- a/nan_callbacks_12_inl.h +++ b/nan_callbacks_12_inl.h @@ -9,9 +9,31 @@ #ifndef NAN_CALLBACKS_12_INL_H_ #define NAN_CALLBACKS_12_INL_H_ +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && \ + (V8_MINOR_VERSION > 6 || \ + V8_MINOR_VERSION == 6 && V8_BUILD_NUMBER >= 74))) +template +class ReturnValue; + +namespace imp { +template +v8::Local GetReturnValue(const ReturnValue &); +} +#endif + template class ReturnValue { v8::ReturnValue value_; +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && \ + (V8_MINOR_VERSION > 6 || \ + V8_MINOR_VERSION == 6 && V8_BUILD_NUMBER >= 74))) + template + friend v8::Local imp::GetReturnValue(const ReturnValue &rv); +#endif public: template @@ -256,6 +278,39 @@ 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 > 6 || \ + V8_MINOR_VERSION == 6 && V8_BUILD_NUMBER >= 74))) + +template +inline v8::Local GetReturnValue(const ReturnValue &rv) { + return rv.value_.Get(); +} + +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())); + callback(property.As(), cbinfo); + return imp::GetReturnValue(cbinfo.GetReturnValue()) == + v8::Undefined(v8::Isolate::GetCurrent()) + ? v8::Intercepted::kNo + : v8::Intercepted::kYes; +} + +typedef v8::Intercepted (*NativePropertyGetter) + (v8::Local, const v8::PropertyCallbackInfo &); +#else static void PropertyGetterCallbackWrapper( v8::Local property @@ -272,7 +327,37 @@ void PropertyGetterCallbackWrapper( typedef void (*NativePropertyGetter) (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 > 6 || \ + V8_MINOR_VERSION == 6 && V8_BUILD_NUMBER >= 74))) +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())); + callback(property.As(), value, cbinfo); + return imp::GetReturnValue(cbinfo.GetReturnValue()) == + v8::Undefined(v8::Isolate::GetCurrent()) + ? v8::Intercepted::kNo + : v8::Intercepted::kYes; +} + +typedef v8::Intercepted (*NativePropertySetter)( + v8::Local + , v8::Local + , const v8::PropertyCallbackInfo &); +#else static void PropertySetterCallbackWrapper( v8::Local property @@ -292,6 +377,7 @@ typedef void (*NativePropertySetter)( v8::Local , v8::Local , const v8::PropertyCallbackInfo &); +#endif static void PropertyEnumeratorCallbackWrapper( @@ -309,6 +395,32 @@ 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 > 6 || \ + V8_MINOR_VERSION == 6 && V8_BUILD_NUMBER >= 74))) +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())); + callback(property.As(), cbinfo); + return imp::GetReturnValue(cbinfo.GetReturnValue()) == + v8::Undefined(v8::Isolate::GetCurrent()) + ? v8::Intercepted::kNo + : v8::Intercepted::kYes; +} + +typedef v8::Intercepted (*NativePropertyDeleter) + (v8::Local, const v8::PropertyCallbackInfo &); +#else static void PropertyDeleterCallbackWrapper( v8::Local property @@ -325,7 +437,34 @@ void PropertyDeleterCallbackWrapper( typedef void (*NativePropertyDeleter) (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 > 6 || \ + V8_MINOR_VERSION == 6 && V8_BUILD_NUMBER >= 74))) +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())); + callback(property.As(), cbinfo); + return imp::GetReturnValue(cbinfo.GetReturnValue()) == + v8::Undefined(v8::Isolate::GetCurrent()) + ? v8::Intercepted::kNo + : v8::Intercepted::kYes; +} + +typedef v8::Intercepted (*NativePropertyQuery) + (v8::Local, const v8::PropertyCallbackInfo &); +#else static void PropertyQueryCallbackWrapper( v8::Local property @@ -342,6 +481,7 @@ void PropertyQueryCallbackWrapper( typedef void (*NativePropertyQuery) (v8::Local, const v8::PropertyCallbackInfo &); +#endif #else static void PropertyGetterCallbackWrapper( @@ -431,6 +571,31 @@ 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 > 6 || \ + V8_MINOR_VERSION == 6 && V8_BUILD_NUMBER >= 74))) +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())); + callback(index, cbinfo); + return imp::GetReturnValue(cbinfo.GetReturnValue()) == + v8::Undefined(v8::Isolate::GetCurrent()) + ? v8::Intercepted::kNo + : v8::Intercepted::kYes; +} + +typedef v8::Intercepted (*NativeIndexGetter) + (uint32_t, const v8::PropertyCallbackInfo &); +#else static void IndexGetterCallbackWrapper( uint32_t index, const v8::PropertyCallbackInfo &info) { @@ -446,7 +611,37 @@ void IndexGetterCallbackWrapper( typedef void (*NativeIndexGetter) (uint32_t, const v8::PropertyCallbackInfo &); +#endif + +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && \ + (V8_MINOR_VERSION > 6 || \ + V8_MINOR_VERSION == 6 && V8_BUILD_NUMBER >= 74))) +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())); + callback(index, value, cbinfo); + return imp::GetReturnValue(cbinfo.GetReturnValue()) == + v8::Undefined(v8::Isolate::GetCurrent()) + ? v8::Intercepted::kNo + : v8::Intercepted::kYes; +} +typedef v8::Intercepted (*NativeIndexSetter)( + uint32_t + , v8::Local + , const v8::PropertyCallbackInfo &); +#else static void IndexSetterCallbackWrapper( uint32_t index @@ -466,6 +661,7 @@ typedef void (*NativeIndexSetter)( uint32_t , v8::Local , const v8::PropertyCallbackInfo &); +#endif static void IndexEnumeratorCallbackWrapper( @@ -484,6 +680,31 @@ 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 > 6 || \ + V8_MINOR_VERSION == 6 && V8_BUILD_NUMBER >= 74))) +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())); + callback(index, cbinfo); + return imp::GetReturnValue(cbinfo.GetReturnValue()) == + v8::Undefined(v8::Isolate::GetCurrent()) + ? v8::Intercepted::kNo + : v8::Intercepted::kYes; +} + +typedef v8::Intercepted (*NativeIndexDeleter) + (uint32_t, const v8::PropertyCallbackInfo &); +#else static void IndexDeleterCallbackWrapper( uint32_t index, const v8::PropertyCallbackInfo &info) { @@ -499,7 +720,33 @@ void IndexDeleterCallbackWrapper( typedef void (*NativeIndexDeleter) (uint32_t, const v8::PropertyCallbackInfo &); +#endif + +#if defined(V8_MAJOR_VERSION) && \ + (V8_MAJOR_VERSION > 12 || \ + (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) && \ + (V8_MINOR_VERSION > 6 || \ + V8_MINOR_VERSION == 6 && V8_BUILD_NUMBER >= 74))) +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())); + callback(index, cbinfo); + return imp::GetReturnValue(cbinfo.GetReturnValue()) == + v8::Undefined(v8::Isolate::GetCurrent()) + ? v8::Intercepted::kNo + : v8::Intercepted::kYes; +} +typedef v8::Intercepted (*NativeIndexQuery) + (uint32_t, const v8::PropertyCallbackInfo &); +#else static void IndexQueryCallbackWrapper( uint32_t index, const v8::PropertyCallbackInfo &info) { @@ -515,6 +762,7 @@ void IndexQueryCallbackWrapper( typedef void (*NativeIndexQuery) (uint32_t, const v8::PropertyCallbackInfo &); +#endif } // end of namespace imp #endif // NAN_CALLBACKS_12_INL_H_