Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Node API upgrade to V8 >= 8 #94

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
25 changes: 21 additions & 4 deletions src/bindings/text-buffer-wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,11 @@ static Local<Value> encode_ranges(const vector<Range> &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;
}
Expand Down Expand Up @@ -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<uint32_t *>(positions_buffer->GetContents().Data());
#if (V8_MAJOR_VERSION < 8)
uint32_t *positions_data = reinterpret_cast<uint32_t *>(positions_buffer->GetContents().Data());
#else
uint32_t *positions_data = reinterpret_cast<uint32_t *>(positions_buffer->GetBackingStore()->Data());
#endif

uint32_t positions_array_index = 0;
for (size_t i = 0; i < result.size() && i < max_count; i++) {
Expand Down Expand Up @@ -935,7 +943,11 @@ void TextBufferWrapper::load(const Nan::FunctionCallbackInfo<Value> &info) {
if (!force && text_buffer.is_modified()) {
Local<Value> argv[] = {Nan::Null(), Nan::Null()};
auto callback = info[0].As<Function>();
Nan::Call(callback, callback->CreationContext()->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
return;
}

Expand Down Expand Up @@ -1039,7 +1051,12 @@ void TextBufferWrapper::base_text_matches_file(const Nan::FunctionCallbackInfo<V
bool result = std::equal(file_contents.begin(), file_contents.end(), text_buffer.base_text().begin());
Local<Value> argv[] = {Nan::Null(), Nan::New<Boolean>(result)};
auto callback = info[0].As<Function>();
Nan::Call(callback, callback->CreationContext()->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
}
}

Expand Down