From 2c18d907564fe9d7f6f4f3ac44471927afd29286 Mon Sep 17 00:00:00 2001 From: Benjamin Byholm Date: Sat, 24 Aug 2024 14:30:59 +0300 Subject: [PATCH] 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_