diff --git a/Core/Node-API-Extensions/include/napi/pointer.h b/Core/Node-API-Extensions/include/napi/pointer.h index bc16614a..e41827d0 100644 --- a/Core/Node-API-Extensions/include/napi/pointer.h +++ b/Core/Node-API-Extensions/include/napi/pointer.h @@ -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::ByteSize); - std::memcpy(arrayBuffer.Data(), &functionPtr, sizeof(PointerT)); + auto arrayBuffer = Napi::ArrayBuffer::New(env, &functionPtr, PointerTraits::ByteSize); return Napi::Uint32Array::New(env, PointerTraits::ArraySize, arrayBuffer, 0).template As(); } }; @@ -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::ByteSize); - std::memcpy(arrayBuffer.Data(), &pointer, sizeof(PointerT)); + auto arrayBuffer = Napi::ArrayBuffer::New(env, &pointer, PointerTraits::ByteSize); return Napi::Uint32Array::New(env, PointerTraits::ArraySize, arrayBuffer, 0); } @@ -60,8 +58,9 @@ namespace Napi callback(); delete reinterpret_cast(ptr); }; - auto arrayBuffer = Napi::ArrayBuffer::New(env, new DataT, PointerTraits::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::ByteSize, std::move(finalizer)); return Napi::Uint32Array::New(env, PointerTraits::ArraySize, arrayBuffer, 0); }