Skip to content

Commit

Permalink
make V8 version dependent
Browse files Browse the repository at this point in the history
  • Loading branch information
gpetrov committed Nov 20, 2021
1 parent a52402a commit 1bbd4e2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/conversions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ void InitConversions(Local<Object> exports) {
end_position_key.Reset(Nan::Persistent<String>(Nan::New("endPosition").ToLocalChecked()));

point_transfer_buffer = static_cast<uint32_t *>(malloc(2 * sizeof(uint32_t)));

#if V8_MAJOR_VERSION >= 8
auto backing_store = ArrayBuffer::NewBackingStore(point_transfer_buffer, 2 * sizeof(uint32_t), BackingStore::EmptyDeleter, nullptr);
auto js_point_transfer_buffer = ArrayBuffer::New(Isolate::GetCurrent(), std::move(backing_store));
#else
auto js_point_transfer_buffer = ArrayBuffer::New(Isolate::GetCurrent(), point_transfer_buffer, 2 * sizeof(uint32_t));
#endif

Nan::Set(exports, Nan::New("pointTransferArray").ToLocalChecked(), Uint32Array::New(js_point_transfer_buffer, 0, 2));
}

Expand Down
6 changes: 6 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ static inline void setup_transfer_buffer(uint32_t node_count) {
}
transfer_buffer_length = new_length;
transfer_buffer = static_cast<uint32_t *>(malloc(transfer_buffer_length * sizeof(uint32_t)));

#if V8_MAJOR_VERSION >= 8
auto backing_store = ArrayBuffer::NewBackingStore(transfer_buffer, transfer_buffer_length * sizeof(uint32_t), BackingStore::EmptyDeleter, nullptr);
auto js_transfer_buffer = ArrayBuffer::New(Isolate::GetCurrent(), std::move(backing_store));
#else
auto js_transfer_buffer = ArrayBuffer::New(Isolate::GetCurrent(), transfer_buffer, transfer_buffer_length * sizeof(uint32_t));
#endif

Nan::Set(
Nan::New(module_exports),
Nan::New("nodeTransferArray").ToLocalChecked(),
Expand Down

0 comments on commit 1bbd4e2

Please sign in to comment.