3434#include " pointer_v8.h"
3535#include < iostream>
3636#include < cstring>
37+ #include < node_version.h>
3738
3839extern " 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+
224255Local<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-
240270void * 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+
257289Local<v8::Value> bridjs::Utils::wrapPointer (v8::Isolate* isolate,const void * ptr){
258290 v8::EscapableHandleScope scope (isolate);
259291
0 commit comments