Skip to content

Commit

Permalink
fix(neon-sys): Add a hack for recent electron versions on windows to …
Browse files Browse the repository at this point in the history
…use Buffer to get the contents of an ArrayBuffer

Fixes #782
  • Loading branch information
kjvalencik committed Aug 31, 2021
1 parent f2e1960 commit 33d1f44
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
4 changes: 4 additions & 0 deletions crates/neon-sys/native/binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"target_name": "neon",
"sources": [ "src/neon.cc" ],
"include_dirs": [ "<!(node -e \"require('nan')\")" ],
"variables": { "runtime%": "node" },
'conditions': [
['runtime=="electron"', { 'defines': ['NODE_RUNTIME_ELECTRON=1'] }],
],
'configurations': {
'Release': {
'msvs_settings': {
Expand Down
24 changes: 15 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,21 @@ 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
#if _MSC_VER && NODE_RUNTIME_ELECTRON && NODE_MODULE_VERSION >= 89
v8::Local<v8::Object> local;
node::Buffer::New(isolate, buffer, 0, buffer->ByteLength()).ToLocal(&local);
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

0 comments on commit 33d1f44

Please sign in to comment.