From 988058e12b5d8e29063d04f059a98bb0b15ed3ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Szabo?= Date: Wed, 27 Jul 2022 01:39:31 -0300 Subject: [PATCH 1/6] Node API upgrade to V8 >= 8 --- src/bindings/text-buffer-wrapper.cc | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/bindings/text-buffer-wrapper.cc b/src/bindings/text-buffer-wrapper.cc index 52e7bded..567aa2ba 100644 --- a/src/bindings/text-buffer-wrapper.cc +++ b/src/bindings/text-buffer-wrapper.cc @@ -387,7 +387,11 @@ static Local encode_ranges(const vector &ranges) { auto length = ranges.size() * 4; auto buffer = v8::ArrayBuffer::New(v8::Isolate::GetCurrent(), length * sizeof(uint32_t)); auto result = v8::Uint32Array::New(buffer, 0, length); - auto data = buffer->GetContents().Data(); + #if (V8_MAJOR_VERSION < 8) + auto data = buffer->GetContents().Data(); + #else + auto data = buffer->GetBackingStore()->Data(); + #endif memcpy(data, ranges.data(), length * sizeof(uint32_t)); return result; } @@ -611,7 +615,11 @@ void TextBufferWrapper::find_words_with_subsequence_in_range(const Nan::Function } auto positions_buffer = v8::ArrayBuffer::New(v8::Isolate::GetCurrent(), positions_buffer_size); - uint32_t *positions_data = reinterpret_cast(positions_buffer->GetContents().Data()); + #if (V8_MAJOR_VERSION < 8) + uint32_t *positions_data = reinterpret_cast(positions_buffer->GetContents().Data()); + #else + uint32_t *positions_data = reinterpret_cast(positions_buffer->GetBackingStore()->Data()); + #endif uint32_t positions_array_index = 0; for (size_t i = 0; i < result.size() && i < max_count; i++) { @@ -935,7 +943,11 @@ void TextBufferWrapper::load(const Nan::FunctionCallbackInfo &info) { if (!force && text_buffer.is_modified()) { Local argv[] = {Nan::Null(), Nan::Null()}; auto callback = info[0].As(); - Nan::Call(callback, callback->CreationContext()->Global(), 2, argv); + #if (V8_MAJOR_VERSION < 8) + Nan::Call(callback, callback->CreationContext()->Global(), 2, argv); + #else + Nan::Call(callback, callback->GetCreationContext().ToLocalChecked()->Global(), 2, argv); + #endif return; } @@ -1039,7 +1051,7 @@ void TextBufferWrapper::base_text_matches_file(const Nan::FunctionCallbackInfo argv[] = {Nan::Null(), Nan::New(result)}; auto callback = info[0].As(); - Nan::Call(callback, callback->CreationContext()->Global(), 2, argv); + Nan::Call(callback, callback->GetCreationContext().ToLocalChecked()->Global(), 2, argv); } } From cf0cff923f14f5cb2f74cef4f69b4e8f6ff67db8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Szabo?= Date: Wed, 27 Jul 2022 11:13:54 -0300 Subject: [PATCH 2/6] Trigger actions From 73de329e9162d003d89c3a2882e4988afaed2f76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Szabo?= Date: Wed, 27 Jul 2022 11:23:39 -0300 Subject: [PATCH 3/6] Fixing V8 version for callback API --- src/bindings/text-buffer-wrapper.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bindings/text-buffer-wrapper.cc b/src/bindings/text-buffer-wrapper.cc index 567aa2ba..ee2a3bb8 100644 --- a/src/bindings/text-buffer-wrapper.cc +++ b/src/bindings/text-buffer-wrapper.cc @@ -943,10 +943,10 @@ void TextBufferWrapper::load(const Nan::FunctionCallbackInfo &info) { if (!force && text_buffer.is_modified()) { Local argv[] = {Nan::Null(), Nan::Null()}; auto callback = info[0].As(); - #if (V8_MAJOR_VERSION < 8) - Nan::Call(callback, callback->CreationContext()->Global(), 2, argv); - #else + #if (V8_MAJOR_VERSION > 9 || (V8_MAJOR_VERSION == 9 && V8_MINOR_VERION <= 4)) Nan::Call(callback, callback->GetCreationContext().ToLocalChecked()->Global(), 2, argv); + #else + Nan::Call(callback, callback->CreationContext()->Global(), 2, argv); #endif return; } From 665990d7bc4158a68e6fbc333e3d3c40a10dc947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Szabo?= Date: Wed, 27 Jul 2022 11:23:46 -0300 Subject: [PATCH 4/6] Trying a new matrix of Node versions --- .github/workflows/ci.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 906ec387..79c442ee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,6 +14,10 @@ jobs: - ubuntu-latest - macos-latest - windows-latest + node_version: + - 14 + - 16 + - 18 name: Node ${{ matrix.node_version }} on ${{ matrix.os }} steps: @@ -30,7 +34,7 @@ jobs: - name: Setup node uses: actions/setup-node@v2-beta with: - node-version: 14 + node-version: ${{ matrix.node_version }} - name: Install dependencies run: npm install From aa68c23682cad7d4ef9b339bf6eeb4f4eb526cdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Szabo?= Date: Wed, 27 Jul 2022 11:30:20 -0300 Subject: [PATCH 5/6] Fix V8 version again --- src/bindings/text-buffer-wrapper.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/text-buffer-wrapper.cc b/src/bindings/text-buffer-wrapper.cc index ee2a3bb8..ec83bea1 100644 --- a/src/bindings/text-buffer-wrapper.cc +++ b/src/bindings/text-buffer-wrapper.cc @@ -943,7 +943,7 @@ void TextBufferWrapper::load(const Nan::FunctionCallbackInfo &info) { if (!force && text_buffer.is_modified()) { Local argv[] = {Nan::Null(), Nan::Null()}; auto callback = info[0].As(); - #if (V8_MAJOR_VERSION > 9 || (V8_MAJOR_VERSION == 9 && V8_MINOR_VERION <= 4)) + #if (V8_MAJOR_VERSION > 9 || (V8_MAJOR_VERSION == 9 && V8_MINOR_VERION > 4)) Nan::Call(callback, callback->GetCreationContext().ToLocalChecked()->Global(), 2, argv); #else Nan::Call(callback, callback->CreationContext()->Global(), 2, argv); From 9c4c4efd3260d704f6c800981b2db00079b595ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Szabo?= Date: Tue, 9 Aug 2022 19:34:55 -0300 Subject: [PATCH 6/6] Fixed for node versions <17 --- src/bindings/text-buffer-wrapper.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/bindings/text-buffer-wrapper.cc b/src/bindings/text-buffer-wrapper.cc index ec83bea1..3c633269 100644 --- a/src/bindings/text-buffer-wrapper.cc +++ b/src/bindings/text-buffer-wrapper.cc @@ -1051,7 +1051,12 @@ void TextBufferWrapper::base_text_matches_file(const Nan::FunctionCallbackInfo argv[] = {Nan::Null(), Nan::New(result)}; auto callback = info[0].As(); - Nan::Call(callback, callback->GetCreationContext().ToLocalChecked()->Global(), 2, argv); + + #if (V8_MAJOR_VERSION > 9 || (V8_MAJOR_VERSION == 9 && V8_MINOR_VERION > 4)) + Nan::Call(callback, callback->GetCreationContext().ToLocalChecked()->Global(), 2, argv); + #else + Nan::Call(callback, callback->CreationContext()->Global(), 2, argv); + #endif } }