Skip to content

Commit 49b71bc

Browse files
committed
Fix build error for old nodejs version
1 parent be63274 commit 49b71bc

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bridjs",
3-
"version": "0.3.4-2",
3+
"version": "0.3.4-3",
44
"description": "V8 bindings for dyncall, and BridJ-like API for nodejs.",
55
"keywords": [
66
"dyncall",

src/dyncall_v8_utils.cc

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "pointer_v8.h"
3535
#include <iostream>
3636
#include <cstring>
37+
#include <node_version.h>
3738

3839
extern "C"
3940
{
@@ -221,6 +222,36 @@ void bridjs::Utils::PointerToString(const v8::FunctionCallbackInfo<v8::Value>& a
221222
args.GetReturnValue().Set(str);
222223
}
223224

225+
#if NODE_MAJOR_VERSION<4
226+
227+
Local<Value> bridjs::Utils::wrapPointerToBuffer(Isolate* isolate, const void* ptr) {
228+
v8::EscapableHandleScope scope(isolate);
229+
Handle<Value> result;
230+
231+
if (ptr != NULL) {
232+
v8::Local<v8::Object> buf = node::Buffer::New(isolate, (char*) (&ptr), sizeof (void*));
233+
result = scope.Escape(buf);
234+
} else {
235+
result = scope.Escape(v8::Local<Primitive>::New(isolate, v8::Null(isolate)));
236+
}
237+
238+
return result;
239+
240+
//memcpy(&pptr,node::Buffer::Data(buf), sizeof(void*));
241+
242+
243+
}
244+
245+
void* bridjs::Utils::unwrapBufferToPointer(v8::Local<v8::Value> value){
246+
void* ptr;
247+
248+
memcpy(&ptr, node::Buffer::Data(value->ToObject()), sizeof(void*));
249+
250+
return ptr;
251+
}
252+
253+
#else
254+
224255
Local<Value> bridjs::Utils::wrapPointerToBuffer(Isolate* isolate, const void* ptr) {
225256
v8::EscapableHandleScope scope(isolate);
226257

@@ -236,7 +267,6 @@ Local<Value> bridjs::Utils::wrapPointerToBuffer(Isolate* isolate, const void* pt
236267
}
237268
}
238269

239-
240270
void* bridjs::Utils::unwrapBufferToPointer(v8::Local<v8::Value> value){
241271
void* ptr;
242272
void* bufferPtr;
@@ -254,6 +284,8 @@ void* bridjs::Utils::unwrapBufferToPointer(v8::Local<v8::Value> value){
254284
return ptr;
255285
}
256286

287+
#endif
288+
257289
Local<v8::Value> bridjs::Utils::wrapPointer(v8::Isolate* isolate,const void* ptr){
258290
v8::EscapableHandleScope scope(isolate);
259291

0 commit comments

Comments
 (0)