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

fix(neon-sys): Add a hack for recent electron versions on windows #785

Merged
merged 1 commit into from
Sep 15, 2021
Merged
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
30 changes: 21 additions & 9 deletions crates/neon-sys/native/src/neon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,27 @@ extern "C" bool Neon_ArrayBuffer_New(v8::Local<v8::ArrayBuffer> *out, v8::Isolat


extern "C" size_t Neon_ArrayBuffer_Data(v8::Isolate *isolate, void **base_out, v8::Local<v8::ArrayBuffer> buffer) {
#if (V8_MAJOR_VERSION >= 8)
auto contents = buffer->GetBackingStore();
*base_out = contents->Data();
return contents->ByteLength();
#else
v8::ArrayBuffer::Contents contents = buffer->GetContents();
*base_out = contents.Data();
return contents.ByteLength();
#endif
// HACK: `v8::ArrayBuffer::Contents` leaks `std::shared_ptr` in the function signature
// Since recent versions of Electron are built with `clang`, `neon-sys` will fail to compile with MSVC
// As a workaround, when building with MSVC on recent versions of Node, create a temporary `Buffer` to extra
// the contents.
//
// https://github.com/electron/electron/issues/29893
#if _MSC_VER && NODE_MODULE_VERSION >= 89
v8::Local<v8::Object> local;
node::Buffer::New(isolate, buffer, 0, buffer->ByteLength()).ToLocal(&local);
kjvalencik marked this conversation as resolved.
Show resolved Hide resolved
return Neon_Buffer_Data(isolate, base_out, local);
#else
#if (V8_MAJOR_VERSION >= 8)
auto contents = buffer->GetBackingStore();
*base_out = contents->Data();
return contents->ByteLength();
#else
v8::ArrayBuffer::Contents contents = buffer->GetContents();
*base_out = contents.Data();
return contents.ByteLength();
#endif
#endif
}

extern "C" bool Neon_Tag_IsArrayBuffer(v8::Isolate *isolate, v8::Local<v8::Value> value) {
Expand Down