From 9379bf23a9ff9a628e989c2fb0b89cd8f3a2e116 Mon Sep 17 00:00:00 2001 From: Aleksey Smolenchuk Date: Thu, 25 Apr 2019 14:29:52 -0700 Subject: [PATCH 1/9] Support Node v12.0.0 --- package.json | 10 +++++----- src/binding.cc | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 503e10b..513430d 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "byte", "64" ], - "version": "1.3.5", + "version": "2.0.0", "license": "MIT", "author": "Nathan Rajlich (http://tootallnate.net)", "repository": { @@ -27,7 +27,7 @@ "main": "./lib/ref.js", "scripts": { "docs": "node docs/compile", - "test": "mocha -gc --reporter spec --use_strict" + "test": "mocha --gc-global --expose-gc --reporter spec --use_strict" }, "dependencies": { "bindings": "1", @@ -36,10 +36,10 @@ }, "devDependencies": { "dox": "0.9.0", - "highlight.js": "1", + "highlight.js": "9", "jade": "1", - "marked": "0.5.2", + "marked": "0.6.2", "mocha": "*", - "weak": "1" + "weak": "github:lxe/node-weak#node-12" } } diff --git a/src/binding.cc b/src/binding.cc index 7075be1..35d62cf 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -219,7 +219,7 @@ NAN_METHOD(WriteObject) { Nan::Persistent* pptr = reinterpret_cast*>(ptr); Local val = info[2].As(); - bool persistent = info[3]->BooleanValue(); + bool persistent = info[3]->BooleanValue(v8::Isolate::GetCurrent()->GetCurrentContext()).ToChecked(); if (persistent) { (*pptr).Reset(val); } else { @@ -250,7 +250,7 @@ NAN_METHOD(ReadPointer) { int64_t offset = GetInt64(info[1]); char *ptr = Buffer::Data(buf.As()) + offset; - size_t size = info[2]->Uint32Value(); + size_t size = info[2]->Uint32Value(v8::Isolate::GetCurrent()->GetCurrentContext()).ToChecked(); if (ptr == NULL) { return Nan::ThrowError("readPointer: Cannot read from NULL pointer"); @@ -357,7 +357,7 @@ NAN_METHOD(WriteInt64) { } else if (in->IsString()) { char *endptr, *str; int base = 0; - String::Utf8Value _str(in); + String::Utf8Value _str(v8::Isolate::GetCurrent(), in); str = *_str; errno = 0; /* To distinguish success/failure after call */ @@ -444,7 +444,7 @@ NAN_METHOD(WriteUInt64) { } else if (in->IsString()) { char *endptr, *str; int base = 0; - String::Utf8Value _str(in); + String::Utf8Value _str(v8::Isolate::GetCurrent(), in); str = *_str; errno = 0; /* To distinguish success/failure after call */ @@ -518,7 +518,7 @@ NAN_METHOD(ReinterpretBuffer) { return Nan::ThrowError("reinterpret: Cannot reinterpret from NULL pointer"); } - size_t size = info[1]->Uint32Value(); + size_t size = info[1]->Uint32Value(v8::Isolate::GetCurrent()->GetCurrentContext()).ToChecked(); info.GetReturnValue().Set(WrapPointer(ptr, size)); } @@ -547,7 +547,7 @@ NAN_METHOD(ReinterpretBufferUntilZeros) { return Nan::ThrowError("reinterpretUntilZeros: Cannot reinterpret from NULL pointer"); } - uint32_t numZeros = info[1]->Uint32Value(); + uint32_t numZeros = info[1]->Uint32Value(v8::Isolate::GetCurrent()->GetCurrentContext()).ToChecked(); uint32_t i = 0; size_t size = 0; bool end = false; From 932cf347f078ecabff9eb2bde2b703815214e4b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Hern=C3=A1ndez?= Date: Thu, 10 Oct 2019 02:18:48 +0200 Subject: [PATCH 2/9] Use Nan::To as suggested in review comment https://github.com/TooTallNate/ref/pull/114#issuecomment-505868069 --- src/binding.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/binding.cc b/src/binding.cc index 35d62cf..10a276f 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -219,7 +219,7 @@ NAN_METHOD(WriteObject) { Nan::Persistent* pptr = reinterpret_cast*>(ptr); Local val = info[2].As(); - bool persistent = info[3]->BooleanValue(v8::Isolate::GetCurrent()->GetCurrentContext()).ToChecked(); + bool persistent = Nan::To(info[3]).FromJust(); if (persistent) { (*pptr).Reset(val); } else { From d6b8b8bb1ebab58cd1fd82e4a60406960ea89a27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Hern=C3=A1ndez?= Date: Fri, 18 Oct 2019 19:27:19 +0200 Subject: [PATCH 3/9] GPII-4140: Renamed package as @gpii/ref --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 513430d..c746ce5 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "ref", + "name": "@gpii/ref", "description": "Turn Buffer instances into \"pointers\"", "keywords": [ "native", @@ -22,7 +22,7 @@ "author": "Nathan Rajlich (http://tootallnate.net)", "repository": { "type": "git", - "url": "git://github.com/TooTallNate/ref.git" + "url": "git://github.com/GPII/ref.git" }, "main": "./lib/ref.js", "scripts": { From 00c6b3a407f21051bf42165e01c779cf2dfe089b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AC=A7=E9=98=B3=E9=92=A6=E5=8D=8E10079130?= Date: Mon, 28 Oct 2019 17:18:42 +0800 Subject: [PATCH 4/9] support node 12: modified as suggested from https://github.com/TooTallNate/ref/pull/114#issuecomment-505868069 --- src/binding.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/binding.cc b/src/binding.cc index 35d62cf..8c19a31 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -219,7 +219,7 @@ NAN_METHOD(WriteObject) { Nan::Persistent* pptr = reinterpret_cast*>(ptr); Local val = info[2].As(); - bool persistent = info[3]->BooleanValue(v8::Isolate::GetCurrent()->GetCurrentContext()).ToChecked(); + bool persistent = Nan::To(info[3]).FromJust(); if (persistent) { (*pptr).Reset(val); } else { @@ -250,7 +250,7 @@ NAN_METHOD(ReadPointer) { int64_t offset = GetInt64(info[1]); char *ptr = Buffer::Data(buf.As()) + offset; - size_t size = info[2]->Uint32Value(v8::Isolate::GetCurrent()->GetCurrentContext()).ToChecked(); + size_t size = Nan::To(info[2]).FromJust(); if (ptr == NULL) { return Nan::ThrowError("readPointer: Cannot read from NULL pointer"); @@ -357,7 +357,7 @@ NAN_METHOD(WriteInt64) { } else if (in->IsString()) { char *endptr, *str; int base = 0; - String::Utf8Value _str(v8::Isolate::GetCurrent(), in); + String::Utf8Value _str(v8::Isolate::GetCurrent(),in); str = *_str; errno = 0; /* To distinguish success/failure after call */ @@ -444,7 +444,7 @@ NAN_METHOD(WriteUInt64) { } else if (in->IsString()) { char *endptr, *str; int base = 0; - String::Utf8Value _str(v8::Isolate::GetCurrent(), in); + String::Utf8Value _str(v8::Isolate::GetCurrent(),in); str = *_str; errno = 0; /* To distinguish success/failure after call */ @@ -518,7 +518,7 @@ NAN_METHOD(ReinterpretBuffer) { return Nan::ThrowError("reinterpret: Cannot reinterpret from NULL pointer"); } - size_t size = info[1]->Uint32Value(v8::Isolate::GetCurrent()->GetCurrentContext()).ToChecked(); + size_t size = Nan::To(info[1]).FromJust(); info.GetReturnValue().Set(WrapPointer(ptr, size)); } @@ -547,7 +547,7 @@ NAN_METHOD(ReinterpretBufferUntilZeros) { return Nan::ThrowError("reinterpretUntilZeros: Cannot reinterpret from NULL pointer"); } - uint32_t numZeros = info[1]->Uint32Value(v8::Isolate::GetCurrent()->GetCurrentContext()).ToChecked(); + uint32_t numZeros = Nan::To(info[1]).FromJust(); uint32_t i = 0; size_t size = 0; bool end = false; From f0a233ee618f0e03a829a279f19ccb4f0e9688e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AC=A7=E9=98=B3=E9=92=A6=E5=8D=8E10079130?= Date: Wed, 20 Nov 2019 10:05:01 +0800 Subject: [PATCH 5/9] fix when required multiple times:https://github.com/TooTallNate/ref/pull/101 --- lib/ref.js | 54 -------------------------------------------------- src/binding.cc | 20 +++++++++---------- 2 files changed, 10 insertions(+), 64 deletions(-) diff --git a/lib/ref.js b/lib/ref.js index 77530a6..79a992c 100644 --- a/lib/ref.js +++ b/lib/ref.js @@ -676,19 +676,6 @@ exports._attach = function _attach (buf, obj) { buf._refs.push(obj) } -/** - * Same as `ref.writeObject()`, except that this version does not _attach_ the - * Object to the Buffer, which is potentially unsafe if the garbage collector - * runs. - * - * @param {Buffer} buffer A Buffer instance to write _object_ to. - * @param {Number} offset The offset on the Buffer to start writing at. - * @param {Object} object The Object to be written into _buffer_. - * @api private - */ - -exports._writeObject = exports.writeObject - /** * Writes a pointer to _object_ into _buffer_ at the specified _offset. * @@ -712,19 +699,6 @@ exports.writeObject = function writeObject (buf, offset, obj, persistent) { exports._attach(buf, obj) } -/** - * Same as `ref.writePointer()`, except that this version does not attach - * _pointer_ to _buffer_, which is potentially unsafe if the garbage collector - * runs. - * - * @param {Buffer} buffer A Buffer instance to write _pointer to. - * @param {Number} offset The offset on the Buffer to start writing at. - * @param {Buffer} pointer The Buffer instance whose memory address will be written to _buffer_. - * @api private - */ - -exports._writePointer = exports.writePointer - /** * Writes the memory address of _pointer_ to _buffer_ at the specified _offset_. * @@ -748,20 +722,6 @@ exports.writePointer = function writePointer (buf, offset, ptr) { exports._attach(buf, ptr) } -/** - * Same as `ref.reinterpret()`, except that this version does not attach - * _buffer_ to the returned Buffer, which is potentially unsafe if the - * garbage collector runs. - * - * @param {Buffer} buffer A Buffer instance to base the returned Buffer off of. - * @param {Number} size The `length` property of the returned Buffer. - * @param {Number} offset The offset of the Buffer to begin from. - * @return {Buffer} A new Buffer instance with the same memory address as _buffer_, and the requested _size_. - * @api private - */ - -exports._reinterpret = exports.reinterpret - /** * Returns a new Buffer instance with the specified _size_, with the same memory * address as _buffer_. @@ -782,20 +742,6 @@ exports.reinterpret = function reinterpret (buffer, size, offset) { return rtn } -/** - * Same as `ref.reinterpretUntilZeros()`, except that this version does not - * attach _buffer_ to the returned Buffer, which is potentially unsafe if the - * garbage collector runs. - * - * @param {Buffer} buffer A Buffer instance to base the returned Buffer off of. - * @param {Number} size The number of sequential, aligned `NULL` bytes that are required to terminate the buffer. - * @param {Number} offset The offset of the Buffer to begin from. - * @return {Buffer} A new Buffer instance with the same memory address as _buffer_, and a variable `length` that is terminated by _size_ NUL bytes. - * @api private - */ - -exports._reinterpretUntilZeros = exports.reinterpretUntilZeros - /** * Accepts a `Buffer` instance and a number of `NULL` bytes to read from the * pointer. This function will scan past the boundary of the Buffer's `length` diff --git a/src/binding.cc b/src/binding.cc index 8c19a31..b10e03d 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -219,7 +219,7 @@ NAN_METHOD(WriteObject) { Nan::Persistent* pptr = reinterpret_cast*>(ptr); Local val = info[2].As(); - bool persistent = Nan::To(info[3]).FromJust(); + bool persistent = info[3]->BooleanValue(); if (persistent) { (*pptr).Reset(val); } else { @@ -250,7 +250,7 @@ NAN_METHOD(ReadPointer) { int64_t offset = GetInt64(info[1]); char *ptr = Buffer::Data(buf.As()) + offset; - size_t size = Nan::To(info[2]).FromJust(); + size_t size = info[2]->Uint32Value(); if (ptr == NULL) { return Nan::ThrowError("readPointer: Cannot read from NULL pointer"); @@ -357,7 +357,7 @@ NAN_METHOD(WriteInt64) { } else if (in->IsString()) { char *endptr, *str; int base = 0; - String::Utf8Value _str(v8::Isolate::GetCurrent(),in); + String::Utf8Value _str(in); str = *_str; errno = 0; /* To distinguish success/failure after call */ @@ -444,7 +444,7 @@ NAN_METHOD(WriteUInt64) { } else if (in->IsString()) { char *endptr, *str; int base = 0; - String::Utf8Value _str(v8::Isolate::GetCurrent(),in); + String::Utf8Value _str(in); str = *_str; errno = 0; /* To distinguish success/failure after call */ @@ -518,7 +518,7 @@ NAN_METHOD(ReinterpretBuffer) { return Nan::ThrowError("reinterpret: Cannot reinterpret from NULL pointer"); } - size_t size = Nan::To(info[1]).FromJust(); + size_t size = info[1]->Uint32Value(); info.GetReturnValue().Set(WrapPointer(ptr, size)); } @@ -547,7 +547,7 @@ NAN_METHOD(ReinterpretBufferUntilZeros) { return Nan::ThrowError("reinterpretUntilZeros: Cannot reinterpret from NULL pointer"); } - uint32_t numZeros = Nan::To(info[1]).FromJust(); + uint32_t numZeros = info[1]->Uint32Value(); uint32_t i = 0; size_t size = 0; bool end = false; @@ -648,15 +648,15 @@ NAN_MODULE_INIT(init) { Nan::SetMethod(target, "hexAddress", HexAddress); Nan::SetMethod(target, "isNull", IsNull); Nan::SetMethod(target, "readObject", ReadObject); - Nan::SetMethod(target, "writeObject", WriteObject); + Nan::SetMethod(target, "_writeObject", WriteObject); Nan::SetMethod(target, "readPointer", ReadPointer); - Nan::SetMethod(target, "writePointer", WritePointer); + Nan::SetMethod(target, "_writePointer", WritePointer); Nan::SetMethod(target, "readInt64", ReadInt64); Nan::SetMethod(target, "writeInt64", WriteInt64); Nan::SetMethod(target, "readUInt64", ReadUInt64); Nan::SetMethod(target, "writeUInt64", WriteUInt64); Nan::SetMethod(target, "readCString", ReadCString); - Nan::SetMethod(target, "reinterpret", ReinterpretBuffer); - Nan::SetMethod(target, "reinterpretUntilZeros", ReinterpretBufferUntilZeros); + Nan::SetMethod(target, "_reinterpret", ReinterpretBuffer); + Nan::SetMethod(target, "_reinterpretUntilZeros", ReinterpretBufferUntilZeros); } NODE_MODULE(binding, init); From 20b24fe3d1bda78088736ea9b09a6e15943bbb65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AC=A7=E9=98=B3=E9=92=A6=E5=8D=8E10079130?= Date: Wed, 20 Nov 2019 10:49:14 +0800 Subject: [PATCH 6/9] fix when required multiple times:revert mistakenly modified codes in previous commit --- src/binding.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/binding.cc b/src/binding.cc index b10e03d..4fde597 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -219,7 +219,7 @@ NAN_METHOD(WriteObject) { Nan::Persistent* pptr = reinterpret_cast*>(ptr); Local val = info[2].As(); - bool persistent = info[3]->BooleanValue(); + bool persistent = Nan::To(info[3]).FromJust(); if (persistent) { (*pptr).Reset(val); } else { @@ -250,7 +250,7 @@ NAN_METHOD(ReadPointer) { int64_t offset = GetInt64(info[1]); char *ptr = Buffer::Data(buf.As()) + offset; - size_t size = info[2]->Uint32Value(); + size_t size = Nan::To(info[2]).FromJust(); if (ptr == NULL) { return Nan::ThrowError("readPointer: Cannot read from NULL pointer"); @@ -357,7 +357,7 @@ NAN_METHOD(WriteInt64) { } else if (in->IsString()) { char *endptr, *str; int base = 0; - String::Utf8Value _str(in); + String::Utf8Value _str(v8::Isolate::GetCurrent(),in); str = *_str; errno = 0; /* To distinguish success/failure after call */ @@ -444,7 +444,7 @@ NAN_METHOD(WriteUInt64) { } else if (in->IsString()) { char *endptr, *str; int base = 0; - String::Utf8Value _str(in); + String::Utf8Value _str(v8::Isolate::GetCurrent(),in); str = *_str; errno = 0; /* To distinguish success/failure after call */ @@ -518,7 +518,7 @@ NAN_METHOD(ReinterpretBuffer) { return Nan::ThrowError("reinterpret: Cannot reinterpret from NULL pointer"); } - size_t size = info[1]->Uint32Value(); + size_t size = Nan::To(info[1]).FromJust(); info.GetReturnValue().Set(WrapPointer(ptr, size)); } @@ -547,7 +547,7 @@ NAN_METHOD(ReinterpretBufferUntilZeros) { return Nan::ThrowError("reinterpretUntilZeros: Cannot reinterpret from NULL pointer"); } - uint32_t numZeros = info[1]->Uint32Value(); + uint32_t numZeros = Nan::To(info[1]).FromJust(); uint32_t i = 0; size_t size = 0; bool end = false; From b8fc6884ad5184f71743aa7434475be4837f4c17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Hern=C3=A1ndez?= Date: Sun, 10 May 2020 01:55:03 +0200 Subject: [PATCH 7/9] GPII-4140: Updated argumments to v8::Object::Set https://v8docs.nodesource.com/node-12.16/db/d85/classv8_1_1_object.html#a67604ea3734f170c66026064ea808f20 --- src/binding.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/binding.cc b/src/binding.cc index 4fde597..7c0afe8 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -578,7 +578,7 @@ NAN_MODULE_INIT(init) { Local smap = Nan::New(); // fixed sizes #define SET_SIZEOF(name, type) \ - smap->Set(Nan::New( #name ).ToLocalChecked(), Nan::New(static_cast(sizeof(type)))); + smap->Set(Nan::GetCurrentContext(), Nan::New( #name ).ToLocalChecked(), Nan::New(static_cast(sizeof(type)))); SET_SIZEOF(int8, int8_t); SET_SIZEOF(uint8, uint8_t); SET_SIZEOF(int16, int16_t); @@ -612,7 +612,7 @@ NAN_MODULE_INIT(init) { Local amap = Nan::New(); #define SET_ALIGNOF(name, type) \ struct s_##name { type a; }; \ - amap->Set(Nan::New( #name ).ToLocalChecked(), Nan::New(static_cast(__alignof__(struct s_##name)))); + amap->Set(Nan::GetCurrentContext(), Nan::New( #name ).ToLocalChecked(), Nan::New(static_cast(__alignof__(struct s_##name)))); SET_ALIGNOF(int8, int8_t); SET_ALIGNOF(uint8, uint8_t); SET_ALIGNOF(int16, int16_t); From 8e793d551617e126c42f744cc55682dfee268281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Hern=C3=A1ndez?= Date: Mon, 11 May 2020 11:44:03 +0200 Subject: [PATCH 8/9] GPII-4140: More v8 updates and addressed some deprecation warnings --- src/binding.cc | 131 +++++++++++++++++++++++++------------------------ 1 file changed, 66 insertions(+), 65 deletions(-) diff --git a/src/binding.cc b/src/binding.cc index 7c0afe8..0ab3b8e 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -357,7 +357,7 @@ NAN_METHOD(WriteInt64) { } else if (in->IsString()) { char *endptr, *str; int base = 0; - String::Utf8Value _str(v8::Isolate::GetCurrent(),in); + String::Utf8Value _str(v8::Isolate::GetCurrent(), Nan::To(in).ToLocalChecked()); str = *_str; errno = 0; /* To distinguish success/failure after call */ @@ -444,7 +444,7 @@ NAN_METHOD(WriteUInt64) { } else if (in->IsString()) { char *endptr, *str; int base = 0; - String::Utf8Value _str(v8::Isolate::GetCurrent(),in); + String::Utf8Value _str(v8::Isolate::GetCurrent(), Nan::To(in).ToLocalChecked()); str = *_str; errno = 0; /* To distinguish success/failure after call */ @@ -573,90 +573,91 @@ NAN_METHOD(ReinterpretBufferUntilZeros) { NAN_MODULE_INIT(init) { Nan::HandleScope scope; + v8::Local ctx = Nan::GetCurrentContext(); // "sizeof" map Local smap = Nan::New(); // fixed sizes -#define SET_SIZEOF(name, type) \ - smap->Set(Nan::GetCurrentContext(), Nan::New( #name ).ToLocalChecked(), Nan::New(static_cast(sizeof(type)))); - SET_SIZEOF(int8, int8_t); - SET_SIZEOF(uint8, uint8_t); - SET_SIZEOF(int16, int16_t); - SET_SIZEOF(uint16, uint16_t); - SET_SIZEOF(int32, int32_t); - SET_SIZEOF(uint32, uint32_t); - SET_SIZEOF(int64, int64_t); - SET_SIZEOF(uint64, uint64_t); - SET_SIZEOF(float, float); - SET_SIZEOF(double, double); +#define SET_SIZEOF(context, name, type) \ + smap->Set(v8::Local(context), Nan::New( #name ).ToLocalChecked(), Nan::New(static_cast(sizeof(type)))); + SET_SIZEOF(ctx, int8, int8_t); + SET_SIZEOF(ctx, uint8, uint8_t); + SET_SIZEOF(ctx, int16, int16_t); + SET_SIZEOF(ctx, uint16, uint16_t); + SET_SIZEOF(ctx, int32, int32_t); + SET_SIZEOF(ctx, uint32, uint32_t); + SET_SIZEOF(ctx, int64, int64_t); + SET_SIZEOF(ctx, uint64, uint64_t); + SET_SIZEOF(ctx, float, float); + SET_SIZEOF(ctx, double, double); // (potentially) variable sizes - SET_SIZEOF(bool, bool); - SET_SIZEOF(byte, unsigned char); - SET_SIZEOF(char, char); - SET_SIZEOF(uchar, unsigned char); - SET_SIZEOF(short, short); - SET_SIZEOF(ushort, unsigned short); - SET_SIZEOF(int, int); - SET_SIZEOF(uint, unsigned int); - SET_SIZEOF(long, long); - SET_SIZEOF(ulong, unsigned long); - SET_SIZEOF(longlong, long long); - SET_SIZEOF(ulonglong, unsigned long long); - SET_SIZEOF(pointer, char *); - SET_SIZEOF(size_t, size_t); - SET_SIZEOF(wchar_t, wchar_t); + SET_SIZEOF(ctx, bool, bool); + SET_SIZEOF(ctx, byte, unsigned char); + SET_SIZEOF(ctx, char, char); + SET_SIZEOF(ctx, uchar, unsigned char); + SET_SIZEOF(ctx, short, short); + SET_SIZEOF(ctx, ushort, unsigned short); + SET_SIZEOF(ctx, int, int); + SET_SIZEOF(ctx, uint, unsigned int); + SET_SIZEOF(ctx, long, long); + SET_SIZEOF(ctx, ulong, unsigned long); + SET_SIZEOF(ctx, longlong, long long); + SET_SIZEOF(ctx, ulonglong, unsigned long long); + SET_SIZEOF(ctx, pointer, char *); + SET_SIZEOF(ctx, size_t, size_t); + SET_SIZEOF(ctx, wchar_t, wchar_t); // size of a Persistent handle to a JS object - SET_SIZEOF(Object, Nan::Persistent); + SET_SIZEOF(ctx, Object, Nan::Persistent); // "alignof" map Local amap = Nan::New(); -#define SET_ALIGNOF(name, type) \ +#define SET_ALIGNOF(context, name, type) \ struct s_##name { type a; }; \ - amap->Set(Nan::GetCurrentContext(), Nan::New( #name ).ToLocalChecked(), Nan::New(static_cast(__alignof__(struct s_##name)))); - SET_ALIGNOF(int8, int8_t); - SET_ALIGNOF(uint8, uint8_t); - SET_ALIGNOF(int16, int16_t); - SET_ALIGNOF(uint16, uint16_t); - SET_ALIGNOF(int32, int32_t); - SET_ALIGNOF(uint32, uint32_t); - SET_ALIGNOF(int64, int64_t); - SET_ALIGNOF(uint64, uint64_t); - SET_ALIGNOF(float, float); - SET_ALIGNOF(double, double); - SET_ALIGNOF(bool, bool); - SET_ALIGNOF(char, char); - SET_ALIGNOF(uchar, unsigned char); - SET_ALIGNOF(short, short); - SET_ALIGNOF(ushort, unsigned short); - SET_ALIGNOF(int, int); - SET_ALIGNOF(uint, unsigned int); - SET_ALIGNOF(long, long); - SET_ALIGNOF(ulong, unsigned long); - SET_ALIGNOF(longlong, long long); - SET_ALIGNOF(ulonglong, unsigned long long); - SET_ALIGNOF(pointer, char *); - SET_ALIGNOF(size_t, size_t); - SET_ALIGNOF(wchar_t, wchar_t); - SET_ALIGNOF(Object, Nan::Persistent); + amap->Set(v8::Local(context), Nan::New( #name ).ToLocalChecked(), Nan::New(static_cast(__alignof__(struct s_##name)))); + SET_ALIGNOF(ctx, int8, int8_t); + SET_ALIGNOF(ctx, uint8, uint8_t); + SET_ALIGNOF(ctx, int16, int16_t); + SET_ALIGNOF(ctx, uint16, uint16_t); + SET_ALIGNOF(ctx, int32, int32_t); + SET_ALIGNOF(ctx, uint32, uint32_t); + SET_ALIGNOF(ctx, int64, int64_t); + SET_ALIGNOF(ctx, uint64, uint64_t); + SET_ALIGNOF(ctx, float, float); + SET_ALIGNOF(ctx, double, double); + SET_ALIGNOF(ctx, bool, bool); + SET_ALIGNOF(ctx, char, char); + SET_ALIGNOF(ctx, uchar, unsigned char); + SET_ALIGNOF(ctx, short, short); + SET_ALIGNOF(ctx, ushort, unsigned short); + SET_ALIGNOF(ctx, int, int); + SET_ALIGNOF(ctx, uint, unsigned int); + SET_ALIGNOF(ctx, long, long); + SET_ALIGNOF(ctx, ulong, unsigned long); + SET_ALIGNOF(ctx, longlong, long long); + SET_ALIGNOF(ctx, ulonglong, unsigned long long); + SET_ALIGNOF(ctx, pointer, char *); + SET_ALIGNOF(ctx, size_t, size_t); + SET_ALIGNOF(ctx, wchar_t, wchar_t); + SET_ALIGNOF(ctx, Object, Nan::Persistent); // exports - target->Set(Nan::New("sizeof").ToLocalChecked(), smap); - target->Set(Nan::New("alignof").ToLocalChecked(), amap); - Nan::ForceSet(target, Nan::New("endianness").ToLocalChecked(), Nan::New(CheckEndianness()).ToLocalChecked(), static_cast(ReadOnly|DontDelete)); - Nan::ForceSet(target, Nan::New("NULL").ToLocalChecked(), WrapNullPointer(), static_cast(ReadOnly|DontDelete)); + target->Set(ctx, Nan::New("sizeof").ToLocalChecked(), smap); + target->Set(ctx, Nan::New("alignof").ToLocalChecked(), amap); + Nan::DefineOwnProperty(target, Nan::New("endianness").ToLocalChecked(), Nan::New(CheckEndianness()).ToLocalChecked(), static_cast(ReadOnly|DontDelete)); + Nan::DefineOwnProperty(target, Nan::New("NULL").ToLocalChecked(), WrapNullPointer(), static_cast(ReadOnly|DontDelete)); Nan::SetMethod(target, "address", Address); Nan::SetMethod(target, "hexAddress", HexAddress); Nan::SetMethod(target, "isNull", IsNull); Nan::SetMethod(target, "readObject", ReadObject); - Nan::SetMethod(target, "_writeObject", WriteObject); + Nan::SetMethod(target, "writeObject", WriteObject); Nan::SetMethod(target, "readPointer", ReadPointer); - Nan::SetMethod(target, "_writePointer", WritePointer); + Nan::SetMethod(target, "writePointer", WritePointer); Nan::SetMethod(target, "readInt64", ReadInt64); Nan::SetMethod(target, "writeInt64", WriteInt64); Nan::SetMethod(target, "readUInt64", ReadUInt64); Nan::SetMethod(target, "writeUInt64", WriteUInt64); Nan::SetMethod(target, "readCString", ReadCString); - Nan::SetMethod(target, "_reinterpret", ReinterpretBuffer); - Nan::SetMethod(target, "_reinterpretUntilZeros", ReinterpretBufferUntilZeros); + Nan::SetMethod(target, "reinterpret", ReinterpretBuffer); + Nan::SetMethod(target, "reinterpretUntilZeros", ReinterpretBufferUntilZeros); } NODE_MODULE(binding, init); From 64b0509c2340d2151e261e20decfd1a8502fabe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Hern=C3=A1ndez?= Date: Mon, 11 May 2020 18:00:53 +0200 Subject: [PATCH 9/9] GPII-4140: Reverted SetMethod values --- src/binding.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/binding.cc b/src/binding.cc index 0ab3b8e..ed0c74c 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -649,15 +649,15 @@ NAN_MODULE_INIT(init) { Nan::SetMethod(target, "hexAddress", HexAddress); Nan::SetMethod(target, "isNull", IsNull); Nan::SetMethod(target, "readObject", ReadObject); - Nan::SetMethod(target, "writeObject", WriteObject); + Nan::SetMethod(target, "_writeObject", WriteObject); Nan::SetMethod(target, "readPointer", ReadPointer); - Nan::SetMethod(target, "writePointer", WritePointer); + Nan::SetMethod(target, "_writePointer", WritePointer); Nan::SetMethod(target, "readInt64", ReadInt64); Nan::SetMethod(target, "writeInt64", WriteInt64); Nan::SetMethod(target, "readUInt64", ReadUInt64); Nan::SetMethod(target, "writeUInt64", WriteUInt64); Nan::SetMethod(target, "readCString", ReadCString); - Nan::SetMethod(target, "reinterpret", ReinterpretBuffer); - Nan::SetMethod(target, "reinterpretUntilZeros", ReinterpretBufferUntilZeros); + Nan::SetMethod(target, "_reinterpret", ReinterpretBuffer); + Nan::SetMethod(target, "_reinterpretUntilZeros", ReinterpretBufferUntilZeros); } NODE_MODULE(binding, init);