Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch ArrayBuffer constructor #96

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 5 additions & 6 deletions Core/Node-API-Extensions/include/napi/pointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ namespace Napi
static Napi::Value Create(Napi::Env env, ReturnT (ClassT::*functionPtr)(ArgsT...))
{
using PointerT = decltype(functionPtr);
auto arrayBuffer = Napi::ArrayBuffer::New(env, PointerTraits<PointerT>::ByteSize);
std::memcpy(arrayBuffer.Data(), &functionPtr, sizeof(PointerT));
auto arrayBuffer = Napi::ArrayBuffer::New(env, &functionPtr, PointerTraits<PointerT>::ByteSize);
return Napi::Uint32Array::New(env, PointerTraits<PointerT>::ArraySize, arrayBuffer, 0).template As<Napi::Value>();
}
};
Expand All @@ -45,8 +44,7 @@ namespace Napi
static Napi::Value Create(Napi::Env env, const T* pointer)
{
using PointerT = T*;
auto arrayBuffer = Napi::ArrayBuffer::New(env, PointerTraits<PointerT>::ByteSize);
std::memcpy(arrayBuffer.Data(), &pointer, sizeof(PointerT));
auto arrayBuffer = Napi::ArrayBuffer::New(env, &pointer, PointerTraits<PointerT>::ByteSize);
return Napi::Uint32Array::New(env, PointerTraits<PointerT>::ArraySize, arrayBuffer, 0);
}

Expand All @@ -60,8 +58,9 @@ namespace Napi
callback();
delete reinterpret_cast<DataT*>(ptr);
};
auto arrayBuffer = Napi::ArrayBuffer::New(env, new DataT, PointerTraits<PointerT>::ByteSize, std::move(finalizer));
std::memcpy(arrayBuffer.Data(), &pointer, sizeof(PointerT));
DataT* data = new DataT;
std::memcpy(data, &pointer, sizeof(PointerT));
auto arrayBuffer = Napi::ArrayBuffer::New(env, data, PointerTraits<PointerT>::ByteSize, std::move(finalizer));
return Napi::Uint32Array::New(env, PointerTraits<PointerT>::ArraySize, arrayBuffer, 0);
}

Expand Down
Loading