From 9e1106ab7b7036d262df7f430eee3bff33757e9a Mon Sep 17 00:00:00 2001 From: agracio Date: Thu, 10 Jul 2025 18:59:50 +0100 Subject: [PATCH 1/7] using WriteUtf8V2() method for v8 version 13.4 and higher --- .github/workflows/ci.yml | 2 ++ appveyor.yml | 11 ----------- nan.h | 9 ++++++++- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5e8872af..387bc4e7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,6 +35,8 @@ jobs: os: ubuntu-24.04-arm # Linux on arm64 - node-version: lts/* os: windows-2025 + - node-version: lts/* + os: windows-11-arm # Windows on arm64 runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 diff --git a/appveyor.yml b/appveyor.yml index 338a8d5b..b00b646c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -14,17 +14,6 @@ image: environment: NODE_GYP_FORCE_PYTHON: C:\Python39-x64\python.exe matrix: # Test against these versions of Io.js and Node.js. - - nodejs_version: "24" - - nodejs_version: "23" - - nodejs_version: "22" - - nodejs_version: "22" - NODE_GYP_FORCE_PYTHON: C:\Python312-x64\python.exe - - nodejs_version: "21" - - nodejs_version: "20" - - nodejs_version: "19" - - nodejs_version: "18" - - nodejs_version: "17" - - nodejs_version: "16" - nodejs_version: "14" APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 - nodejs_version: "12" diff --git a/nan.h b/nan.h index f0bfc0c6..6e659ffe 100644 --- a/nan.h +++ b/nan.h @@ -1170,8 +1170,15 @@ class Utf8String { const int flags = v8::String::NO_NULL_TERMINATION | imp::kReplaceInvalidUtf8; #if NODE_MAJOR_VERSION >= 11 - length_ = string->WriteUtf8(v8::Isolate::GetCurrent(), str_, +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 13 || \ + (V8_MAJOR_VERSION == 13 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 3)) + length_ = string->WriteUtf8V2(v8::Isolate::GetCurrent(), str_, + static_cast(len), imp::kReplaceInvalidUtf8); +#else + length_ = string->WriteUtf8(v8::Isolate::GetCurrent(), str_, static_cast(len), 0, flags); +#endif + #else // See https://github.com/nodejs/nan/issues/832. // Disable the warning as there is no way around it. From 982c0c8caad4eb5d4317c71ec5b277367f202987 Mon Sep 17 00:00:00 2001 From: agracio Date: Thu, 10 Jul 2025 19:20:12 +0100 Subject: [PATCH 2/7] using SetPrototypeV2() method for v8 version 14.0 and higher --- nan_maybe_43_inl.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/nan_maybe_43_inl.h b/nan_maybe_43_inl.h index f37ce973..e5dc9ee9 100644 --- a/nan_maybe_43_inl.h +++ b/nan_maybe_43_inl.h @@ -207,7 +207,12 @@ inline Maybe SetPrototype( , v8::Local prototype) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::HandleScope scope(isolate); - return obj->SetPrototype(isolate->GetCurrentContext(), prototype); +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 14 || \ + (V8_MAJOR_VERSION == 14 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 0)) + return obj->SetPrototypeV2(isolate->GetCurrentContext(), prototype); +#else + return obj->SetPrototype(isolate->GetCurrentContext(), prototype); +#endif } inline MaybeLocal ObjectProtoToString( From d8337b0349363ff44afedb69f2ebd67ea2cccae6 Mon Sep 17 00:00:00 2001 From: agracio Date: Fri, 11 Jul 2025 15:22:52 +0100 Subject: [PATCH 3/7] using SetPrototypeV2() method for v8 version 14.0 and higher --- nan_maybe_43_inl.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/nan_maybe_43_inl.h b/nan_maybe_43_inl.h index e5dc9ee9..48b62e9d 100644 --- a/nan_maybe_43_inl.h +++ b/nan_maybe_43_inl.h @@ -207,8 +207,7 @@ inline Maybe SetPrototype( , v8::Local prototype) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::HandleScope scope(isolate); -#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 14 || \ - (V8_MAJOR_VERSION == 14 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 0)) +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION >= 14) return obj->SetPrototypeV2(isolate->GetCurrentContext(), prototype); #else return obj->SetPrototype(isolate->GetCurrentContext(), prototype); From 3716df9eace7e23e43dd036d252f9364a5cf98ef Mon Sep 17 00:00:00 2001 From: agracio Date: Fri, 17 Oct 2025 22:52:40 +0100 Subject: [PATCH 4/7] adding Node.js 25 to CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 387bc4e7..9532f184 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,7 @@ jobs: strategy: fail-fast: false matrix: - node-version: [24.x, 23.x, 22.x, 21.x, 20.x, 19.x, 18.x, 17.x, 16.x] + node-version: [25.x, 24.x, 23.x, 22.x, 21.x, 20.x, 19.x, 18.x, 17.x, 16.x] os: [windows-latest] include: - node-version: lts/* From ca2fd3c093c135a6701b40b712ff0e082b251ef7 Mon Sep 17 00:00:00 2001 From: agracio Date: Fri, 17 Oct 2025 23:09:58 +0100 Subject: [PATCH 5/7] updating WriteUtf8V2 method --- nan.h | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/nan.h b/nan.h index 6e659ffe..d24468e0 100644 --- a/nan.h +++ b/nan.h @@ -427,15 +427,11 @@ template class WeakCallbackInfo; namespace imp { static const size_t kMaxLength = 0x3fffffff; - // v8::String::REPLACE_INVALID_UTF8 was introduced - // in node.js v0.10.29 and v0.8.27. -#if NODE_MAJOR_VERSION > 0 || \ - NODE_MINOR_VERSION > 10 || \ - NODE_MINOR_VERSION == 10 && NODE_PATCH_VERSION >= 29 || \ - NODE_MINOR_VERSION == 8 && NODE_PATCH_VERSION >= 27 - static const unsigned kReplaceInvalidUtf8 = v8::String::REPLACE_INVALID_UTF8; +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 13 || \ + (V8_MAJOR_VERSION == 13 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 4)) + static const unsigned kReplaceInvalidUtf8 = v8::String::WriteFlags::kReplaceInvalidUtf8; #else - static const unsigned kReplaceInvalidUtf8 = 0; + static const unsigned kReplaceInvalidUtf8 = v8::String::REPLACE_INVALID_UTF8; #endif } // end of namespace imp @@ -1167,14 +1163,14 @@ class Utf8String { str_ = static_cast(malloc(len)); assert(str_ != 0); } - const int flags = - v8::String::NO_NULL_TERMINATION | imp::kReplaceInvalidUtf8; #if NODE_MAJOR_VERSION >= 11 #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 13 || \ - (V8_MAJOR_VERSION == 13 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 3)) + (V8_MAJOR_VERSION == 13 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 4)) length_ = string->WriteUtf8V2(v8::Isolate::GetCurrent(), str_, static_cast(len), imp::kReplaceInvalidUtf8); #else + const int flags = + v8::String::NO_NULL_TERMINATION | imp::kReplaceInvalidUtf8; length_ = string->WriteUtf8(v8::Isolate::GetCurrent(), str_, static_cast(len), 0, flags); #endif @@ -1190,7 +1186,9 @@ class Utf8String { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #endif - length_ = string->WriteUtf8(str_, static_cast(len), 0, flags); + const int flags = + v8::String::NO_NULL_TERMINATION | imp::kReplaceInvalidUtf8; + length_ = string->WriteUtf8(str_, static_cast(len), 0, flags); #ifdef __GNUC__ #pragma GCC diagnostic pop #endif From a44a99843bfe9e3f4c3e9781a3d7692dd11c3b61 Mon Sep 17 00:00:00 2001 From: agracio Date: Fri, 17 Oct 2025 23:13:12 +0100 Subject: [PATCH 6/7] splitting line to satisfy cpplint requirements --- nan.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nan.h b/nan.h index d24468e0..215fbc71 100644 --- a/nan.h +++ b/nan.h @@ -429,7 +429,8 @@ namespace imp { static const size_t kMaxLength = 0x3fffffff; #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 13 || \ (V8_MAJOR_VERSION == 13 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 4)) - static const unsigned kReplaceInvalidUtf8 = v8::String::WriteFlags::kReplaceInvalidUtf8; + static const unsigned kReplaceInvalidUtf8 + = v8::String::WriteFlags::kReplaceInvalidUtf8; #else static const unsigned kReplaceInvalidUtf8 = v8::String::REPLACE_INVALID_UTF8; #endif From cb93c9e0581721700cf28c039b95c333d2881796 Mon Sep 17 00:00:00 2001 From: agracio Date: Tue, 28 Oct 2025 14:54:47 +0000 Subject: [PATCH 7/7] Fixing an issue with SetAccessor() method passing incorrect parameter in v8 12.0 --- nan.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nan.h b/nan.h index 215fbc71..fd2b2b24 100644 --- a/nan.h +++ b/nan.h @@ -2632,7 +2632,9 @@ NAN_DEPRECATED inline void SetAccessor( , getter_ , setter_ , obj -#if !defined(V8_MAJOR_VERSION) || V8_MAJOR_VERSION < 12 +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION < 12 \ + || (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) \ + && V8_MINOR_VERSION == 0)) , settings #endif , attribute @@ -2686,7 +2688,9 @@ inline void SetAccessor( , getter_ , setter_ , obj -#if !defined(V8_MAJOR_VERSION) || V8_MAJOR_VERSION < 12 +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION < 12 \ + || (V8_MAJOR_VERSION == 12 && defined(V8_MINOR_VERSION) \ + && V8_MINOR_VERSION == 0)) , settings #endif , attribute