Skip to content

Commit

Permalink
fix: memcpy array data for non-direct java bytebuffers (#1740)
Browse files Browse the repository at this point in the history
  • Loading branch information
vmutafov committed Nov 18, 2022
1 parent 66f30ca commit 1c0214a
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions test-app/runtime/src/main/cpp/ArrayBufferHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,21 @@ void ArrayBufferHelper::CreateFromCallbackImpl(const FunctionCallbackInfo<Value>
jbyteArray byteArray = env.NewByteArray(bufferRemainingSize);
env.CallObjectMethod(obj, m_getMethodID, byteArray, 0, bufferRemainingSize);

auto buffer = env.GetByteArrayElements(byteArray, 0);
auto byteArrayElements = env.GetByteArrayElements(byteArray, 0);

void* data[bufferRemainingSize];
memcpy(data, byteArrayElements, bufferRemainingSize);

std::shared_ptr<v8::BackingStore> store = ArrayBuffer::NewBackingStore(buffer, bufferRemainingSize,
[](void* data, size_t length, void* deleter_data) {
free(data);
},
buffer);
std::shared_ptr<v8::BackingStore> store = ArrayBuffer::NewBackingStore(
byteArrayElements,
bufferRemainingSize,
[](void *data, size_t length, void *deleter_data) {
free(data);
},
nullptr);

arrayBuffer = ArrayBuffer::New(isolate, store);
env.ReleaseByteArrayElements(byteArray, byteArrayElements, 0);
}

auto ctx = isolate->GetCurrentContext();
Expand Down

0 comments on commit 1c0214a

Please sign in to comment.