From bdcb5d2d42786b1ef36b9247b210daeb0827bb0a Mon Sep 17 00:00:00 2001 From: Felipe Gomes de Melo Date: Fri, 22 Jan 2021 15:18:06 -0300 Subject: [PATCH 01/19] [GZNode] Change v8::Handle to v8::Local This is a pure cosmetical change. From the docs, "Handle is an alias for Local for historical reasons" https://v8docs.nodesource.com/node-10.15/d4/da0/v8_8h_source.html#l00428 --- gzbridge/GZNode.cc | 4 ++-- gzbridge/GZNode.hh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gzbridge/GZNode.cc b/gzbridge/GZNode.cc index f6cdad0d..64bdb219 100644 --- a/gzbridge/GZNode.cc +++ b/gzbridge/GZNode.cc @@ -47,7 +47,7 @@ GZNode::~GZNode() }; ///////////////////////////////////////////////// -void GZNode::Init(Handle exports) +void GZNode::Init(Local exports) { Isolate* isolate = exports->GetIsolate(); // Prepare constructor template @@ -286,7 +286,7 @@ void GZNode::GetPoseMsgFilterMinimumAge(const } ///////////////////////////////////////////////// -void InitAll(Handle exports) +void InitAll(Local exports) { GZNode::Init(exports); } diff --git a/gzbridge/GZNode.hh b/gzbridge/GZNode.hh index 74872df1..2c3aedf0 100644 --- a/gzbridge/GZNode.hh +++ b/gzbridge/GZNode.hh @@ -33,7 +33,7 @@ namespace gzweb class GZNode : public node::ObjectWrap { - public: static void Init(v8::Handle exports); + public: static void Init(v8::Local exports); private: GZNode(); From 229acb5e19b80cffcc26ad690e0d0c6f18e9046d Mon Sep 17 00:00:00 2001 From: Felipe Gomes de Melo Date: Fri, 22 Jan 2021 15:33:54 -0300 Subject: [PATCH 02/19] [GZNode] Fix compilation errors w/ node 12 Several API calls from V8 were deprecated in version 7.0 (that ships w/ node 12), this commit replaces then Refs: https://github.com/nodejs/node/issues/23122 https://github.com/nodejs/node/pull/23159 https://github.com/bcoin-org/bcrypto/issues/7 --- gzbridge/GZNode.cc | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/gzbridge/GZNode.cc b/gzbridge/GZNode.cc index 64bdb219..8e7444bc 100644 --- a/gzbridge/GZNode.cc +++ b/gzbridge/GZNode.cc @@ -51,8 +51,12 @@ void GZNode::Init(Local exports) { Isolate* isolate = exports->GetIsolate(); // Prepare constructor template + Local class_name = String::NewFromUtf8(isolate, "GZNode", + NewStringType::kInternalized).ToLocalChecked(); + Local tpl = FunctionTemplate::New(isolate, New); - tpl->SetClassName(String::NewFromUtf8(isolate, "GZNode")); + + tpl->SetClassName(class_name); tpl->InstanceTemplate()->SetInternalFieldCount(1); // Prototype NODE_SET_PROTOTYPE_METHOD(tpl, "loadMaterialScripts", LoadMaterialScripts); @@ -80,8 +84,8 @@ void GZNode::Init(Local exports) NODE_SET_PROTOTYPE_METHOD(tpl, "getMaterialScriptsMessage", GetMaterialScriptsMessage); - exports->Set(String::NewFromUtf8(isolate, "GZNode"), - tpl->GetFunction()); + Local context = isolate->GetCurrentContext(); + exports->Set(context, class_name, tpl->GetFunction(context).ToLocalChecked()).Check(); } ///////////////////////////////////////////////// @@ -116,7 +120,7 @@ void GZNode::LoadMaterialScripts(const FunctionCallbackInfo& args) GZNode* obj = ObjectWrap::Unwrap(args.This()); - String::Utf8Value path(args[0]->ToString()); + String::Utf8Value path(isolate, args[0]); obj->gzIface->LoadMaterialScripts(std::string(*path)); return; @@ -125,8 +129,10 @@ void GZNode::LoadMaterialScripts(const FunctionCallbackInfo& args) ///////////////////////////////////////////////// void GZNode::SetConnected(const FunctionCallbackInfo& args) { + Isolate* isolate = args.GetIsolate(); + GZNode *obj = ObjectWrap::Unwrap(args.This()); - bool value = args[0]->BooleanValue(); + bool value = args[0]->BooleanValue(isolate); obj->gzIface->SetConnected(value); return; @@ -160,7 +166,7 @@ void GZNode::GetMaterialScriptsMessage(const FunctionCallbackInfo& args) return; } - String::Utf8Value path(args[0]->ToString()); + String::Utf8Value path(isolate, args[0]); OgreMaterialParser materialParser; materialParser.Load(std::string(*path)); @@ -258,7 +264,7 @@ void GZNode::Request(const FunctionCallbackInfo& args) GZNode* obj = ObjectWrap::Unwrap(args.This()); - String::Utf8Value request(args[0]->ToString()); + String::Utf8Value request(isolate, args[0]); obj->gzIface->PushRequest(std::string(*request)); return; From c3cdedea1e1830ee2cbbcafc31a11b0e9dd4733f Mon Sep 17 00:00:00 2001 From: Felipe Gomes de Melo Date: Fri, 22 Jan 2021 15:50:35 -0300 Subject: [PATCH 03/19] [binding.gyp] Add -std=c++17 flag Sdf format version 9.0 requires c++17 to be compiled https://github.com/osrf/sdformat/pull/251 --- gzbridge/binding.gyp | 1 + 1 file changed, 1 insertion(+) diff --git a/gzbridge/binding.gyp b/gzbridge/binding.gyp index 53d0cad3..cb5efc36 100644 --- a/gzbridge/binding.gyp +++ b/gzbridge/binding.gyp @@ -9,6 +9,7 @@ "OgreMaterialParser.cc", "OgreMaterialParser.hh"], 'cflags_cc!': [ '-fno-rtti', '-fno-exceptions' ], 'cflags!': [ '-fno-exceptions' ], + "cflags_cc": [ '-std=c++17' ], "conditions": [ ['OS=="linux"', { 'cflags': [ From 9b8de9be3b066c66c08e72428cad69896de9a294 Mon Sep 17 00:00:00 2001 From: Felipe Gomes de Melo Date: Fri, 22 Jan 2021 16:10:46 -0300 Subject: [PATCH 04/19] [ci] Update node version in Github CI --- .github/workflows/ci.yaml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 94c25502..f2f8275d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -5,11 +5,11 @@ on: [push, pull_request] jobs: build: - runs-on: ubuntu-16.04 + runs-on: ubuntu-20.04 strategy: matrix: - node-version: [8.x, 10.x] + node-version: [12.x] steps: - uses: actions/checkout@v2 @@ -17,8 +17,10 @@ jobs: uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} + - run: sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list' + - run: wget https://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add - - run: sudo apt update - - run: sudo apt install -y libjansson-dev libboost-dev imagemagick libtinyxml-dev git cmake build-essential wget libgazebo7-dev + - run: sudo apt install -y libjansson-dev libboost-dev imagemagick libtinyxml-dev git cmake build-essential wget libgazebo11-dev - run: sudo npm install -g grunt # - run: sudo bash -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/chrome.list' # - run: sudo wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - From 0b00c7a721a184db0690a19b59095522fb54c182 Mon Sep 17 00:00:00 2001 From: Felipe Gomes de Melo Date: Thu, 28 Jan 2021 10:05:30 -0300 Subject: [PATCH 05/19] Change v8 API calls to Maybe version --- gzbridge/GZNode.cc | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/gzbridge/GZNode.cc b/gzbridge/GZNode.cc index 8e7444bc..fbb21744 100644 --- a/gzbridge/GZNode.cc +++ b/gzbridge/GZNode.cc @@ -107,14 +107,18 @@ void GZNode::LoadMaterialScripts(const FunctionCallbackInfo& args) if (args.Length() < 1) { isolate->ThrowException(Exception::TypeError( - String::NewFromUtf8(isolate, "Wrong number of arguments"))); + String::NewFromUtf8(isolate, + "Wrong number of arguments", + NewStringType::kNormal).ToLocalChecked())); return; } if (!args[0]->IsString()) { isolate->ThrowException(Exception::TypeError( - String::NewFromUtf8(isolate, "Wrong argument type. String expected."))); + String::NewFromUtf8(isolate, + "Wrong argument type. String expected.", + NewStringType::kNormal).ToLocalChecked())); return; } @@ -155,14 +159,18 @@ void GZNode::GetMaterialScriptsMessage(const FunctionCallbackInfo& args) if (args.Length() < 1) { isolate->ThrowException(Exception::TypeError( - String::NewFromUtf8(isolate, "Wrong number of arguments"))); + String::NewFromUtf8(isolate, + "Wrong number of arguments", + NewStringType::kNormal).ToLocalChecked())); return; } if (!args[0]->IsString()) { isolate->ThrowException(Exception::TypeError( - String::NewFromUtf8(isolate, "Wrong argument type. String expected."))); + String::NewFromUtf8(isolate, + "Wrong argument type. String expected.", + NewStringType::kNormal).ToLocalChecked())); return; } @@ -177,7 +185,10 @@ void GZNode::GetMaterialScriptsMessage(const FunctionCallbackInfo& args) msg += materialJson; msg += "}"; - args.GetReturnValue().Set(String::NewFromUtf8(isolate ,msg.c_str())); + args.GetReturnValue().Set( + String::NewFromUtf8(isolate, + msg.c_str(), + NewStringType::kNormal).ToLocalChecked()); } ///////////////////////////////////////////////// @@ -229,6 +240,7 @@ void GZNode::GetPoseMsgFilterMinimumQuaternionSquared(const void GZNode::GetMessages(const FunctionCallbackInfo& args) { Isolate* isolate = args.GetIsolate(); + Local context = isolate->GetCurrentContext(); GZNode* obj = ObjectWrap::Unwrap(args.This()); @@ -236,7 +248,12 @@ void GZNode::GetMessages(const FunctionCallbackInfo& args) // args.GetReturnValue().Set(Number::New(isolate ,msgs.size())); Local arguments = Array::New(isolate, msgs.size()); for (unsigned int i = 0; i < msgs.size(); ++i) { - arguments->Set(i ,String::NewFromUtf8(isolate, msgs[i].c_str())); + MaybeLocal v8_msg = String::NewFromUtf8(isolate, msgs[i].c_str(), NewStringType::kNormal); + bool sucess = arguments->Set(context, i, v8_msg.ToLocalChecked()).FromJust(); + if(!sucess){ + //TODO handle failure + return; + } } args.GetReturnValue().Set(arguments); @@ -251,14 +268,18 @@ void GZNode::Request(const FunctionCallbackInfo& args) if (args.Length() < 1) { isolate->ThrowException(Exception::TypeError( - String::NewFromUtf8(isolate, "Wrong number of arguments"))); + String::NewFromUtf8(isolate, + "Wrong number of arguments", + NewStringType::kNormal).ToLocalChecked())); return; } if (!args[0]->IsString()) { isolate->ThrowException(Exception::TypeError( - String::NewFromUtf8(isolate, "Wrong argument type. String expected."))); + String::NewFromUtf8(isolate, + "Wrong argument type. String expected.", + NewStringType::kNormal).ToLocalChecked())); return; } From 57812ae68bf89d26fd9475255bb84a285424b28f Mon Sep 17 00:00:00 2001 From: Felipe Gomes de Melo Date: Thu, 28 Jan 2021 10:05:56 -0300 Subject: [PATCH 06/19] Change InitAll signature to match node standard --- gzbridge/GZNode.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gzbridge/GZNode.cc b/gzbridge/GZNode.cc index fbb21744..5bc0c958 100644 --- a/gzbridge/GZNode.cc +++ b/gzbridge/GZNode.cc @@ -313,7 +313,7 @@ void GZNode::GetPoseMsgFilterMinimumAge(const } ///////////////////////////////////////////////// -void InitAll(Local exports) +void InitAll(Local exports, Local module, void* priv) { GZNode::Init(exports); } From 28bdff9e9a5dd8518f0e389a088255d14d8724d1 Mon Sep 17 00:00:00 2001 From: Felipe Gomes de Melo Date: Thu, 28 Jan 2021 10:07:20 -0300 Subject: [PATCH 07/19] Fix sign-compare gcc warning --- tools/gzcoarse.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/gzcoarse.cc b/tools/gzcoarse.cc index 54b01a42..9fb2948d 100644 --- a/tools/gzcoarse.cc +++ b/tools/gzcoarse.cc @@ -134,7 +134,7 @@ void ExportTextureSource(const gazebo::common::SubMesh *_outSubMesh, std::vector result_index(num_results); std::vector out_dist_sqr(num_results); static const int offset[] = {1,2,-1,1,-2,-1}; - for (int i = 0; i < outTriIndexCount; ++i) + for (unsigned int i = 0; i < outTriIndexCount; ++i) { unsigned int outIndex = _outSubMesh->GetIndex(i); ignition::math::Vector3d outVertex = _outSubMesh->Vertex(outIndex); @@ -146,7 +146,7 @@ void ExportTextureSource(const gazebo::common::SubMesh *_outSubMesh, std::vector closestIndices; double closestDistance = 1000; - for (int j = 0; j < num_results; ++j) + for (unsigned int j = 0; j < num_results; ++j) { inVertex = _inSubMesh->Vertex(result_index[j]); @@ -214,7 +214,7 @@ void ExportTextureSource(const gazebo::common::SubMesh *_outSubMesh, // Find the closest direction among all triangles containing overlapping // vertices - for (int k = 1; k < closestIndices.size(); ++k) + for (unsigned int k = 1; k < closestIndices.size(); ++k) { // Current vertex size_t currentIndex = closestIndices[k]; @@ -1246,7 +1246,7 @@ int main(int argc, char **argv) gazebo::common::Mesh *outGz = new gazebo::common::Mesh(); - for (int s = 0; s < inGz->GetSubMeshCount(); ++s) + for (unsigned int s = 0; s < inGz->GetSubMeshCount(); ++s) { const gazebo::common::SubMesh *inSubMesh = inGz->GetSubMesh(s); From c69a67e79784ae03371e31f6f61a5093ebffd57b Mon Sep 17 00:00:00 2001 From: Felipe Gomes de Melo Date: Thu, 28 Jan 2021 10:08:25 -0300 Subject: [PATCH 08/19] Add node 10 and 14 LTS to github ci --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f2f8275d..1195d25b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -9,7 +9,7 @@ jobs: strategy: matrix: - node-version: [12.x] + node-version: [10.x, 12.x, 14.x] steps: - uses: actions/checkout@v2 From 6757476c13636cbf494a061cf48c02256194983c Mon Sep 17 00:00:00 2001 From: Felipe Gomes de Melo Date: Mon, 1 Feb 2021 17:30:56 -0300 Subject: [PATCH 09/19] Add -Wall flag to enable all compilation warnings --- gzbridge/binding.gyp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gzbridge/binding.gyp b/gzbridge/binding.gyp index cb5efc36..7b53e7a6 100644 --- a/gzbridge/binding.gyp +++ b/gzbridge/binding.gyp @@ -9,7 +9,7 @@ "OgreMaterialParser.cc", "OgreMaterialParser.hh"], 'cflags_cc!': [ '-fno-rtti', '-fno-exceptions' ], 'cflags!': [ '-fno-exceptions' ], - "cflags_cc": [ '-std=c++17' ], + "cflags_cc": [ '-std=c++17', '-Wall'], "conditions": [ ['OS=="linux"', { 'cflags': [ From 4d1d63eb8dd772d42083542068f16e532c3470c5 Mon Sep 17 00:00:00 2001 From: Felipe Gomes de Melo Date: Mon, 1 Feb 2021 17:31:08 -0300 Subject: [PATCH 10/19] Fix node 10 compilation errors --- gzbridge/GZNode.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gzbridge/GZNode.cc b/gzbridge/GZNode.cc index 5bc0c958..7f0c9f71 100644 --- a/gzbridge/GZNode.cc +++ b/gzbridge/GZNode.cc @@ -85,7 +85,7 @@ void GZNode::Init(Local exports) GetMaterialScriptsMessage); Local context = isolate->GetCurrentContext(); - exports->Set(context, class_name, tpl->GetFunction(context).ToLocalChecked()).Check(); + exports->Set(context, class_name, tpl->GetFunction(context).ToLocalChecked()).ToChecked(); } ///////////////////////////////////////////////// @@ -136,7 +136,13 @@ void GZNode::SetConnected(const FunctionCallbackInfo& args) Isolate* isolate = args.GetIsolate(); GZNode *obj = ObjectWrap::Unwrap(args.This()); + +#if NODE_MAJOR_VERSION<=10 + Local context = isolate->GetCurrentContext(); + bool value = args[0]->BooleanValue(context).ToChecked(); +#else bool value = args[0]->BooleanValue(isolate); +#endif obj->gzIface->SetConnected(value); return; From 6036cd904d01c46cfe6e47b9bf3707b2c953e1ae Mon Sep 17 00:00:00 2001 From: Felipe Gomes de Melo Date: Tue, 2 Feb 2021 11:37:01 -0300 Subject: [PATCH 11/19] Change functions signature --- gzbridge/GZNode.cc | 32 +++++++++++++------------------- gzbridge/GZNode.hh | 38 ++++++++++++++------------------------ 2 files changed, 27 insertions(+), 43 deletions(-) diff --git a/gzbridge/GZNode.cc b/gzbridge/GZNode.cc index 7f0c9f71..e1477621 100644 --- a/gzbridge/GZNode.cc +++ b/gzbridge/GZNode.cc @@ -89,7 +89,7 @@ void GZNode::Init(Local exports) } ///////////////////////////////////////////////// -void GZNode::New(const FunctionCallbackInfo& args) +NAN_METHOD(GZNode::New) { if (args.IsConstructCall()) { // Invoked as constructor: `new MyObject(...)` @@ -100,7 +100,7 @@ void GZNode::New(const FunctionCallbackInfo& args) } ///////////////////////////////////////////////// -void GZNode::LoadMaterialScripts(const FunctionCallbackInfo& args) +NAN_METHOD(GZNode::LoadMaterialScripts) { Isolate* isolate = args.GetIsolate(); @@ -131,7 +131,7 @@ void GZNode::LoadMaterialScripts(const FunctionCallbackInfo& args) } ///////////////////////////////////////////////// -void GZNode::SetConnected(const FunctionCallbackInfo& args) +NAN_METHOD(GZNode::SetConnected) { Isolate* isolate = args.GetIsolate(); @@ -149,7 +149,7 @@ void GZNode::SetConnected(const FunctionCallbackInfo& args) } ///////////////////////////////////////////////// -void GZNode::GetIsGzServerConnected(const FunctionCallbackInfo& args) +NAN_METHOD(GZNode::GetIsGzServerConnected) { GZNode *obj = ObjectWrap::Unwrap(args.This()); bool value = obj->isGzServerConnected; @@ -158,7 +158,7 @@ void GZNode::GetIsGzServerConnected(const FunctionCallbackInfo& args) } ///////////////////////////////////////////////// -void GZNode::GetMaterialScriptsMessage(const FunctionCallbackInfo& args) +NAN_METHOD(GZNode::GetMaterialScriptsMessage) { Isolate* isolate = args.GetIsolate(); @@ -198,8 +198,7 @@ void GZNode::GetMaterialScriptsMessage(const FunctionCallbackInfo& args) } ///////////////////////////////////////////////// -void GZNode::SetPoseMsgFilterMinimumDistanceSquared(const - FunctionCallbackInfo& args) +NAN_METHOD(GZNode::SetPoseMsgFilterMinimumDistanceSquared) { GZNode *obj = ObjectWrap::Unwrap(args.This()); @@ -211,8 +210,7 @@ void GZNode::SetPoseMsgFilterMinimumDistanceSquared(const } ///////////////////////////////////////////////// -void GZNode::GetPoseMsgFilterMinimumDistanceSquared(const - FunctionCallbackInfo& args) +NAN_METHOD(GZNode::GetPoseMsgFilterMinimumDistanceSquared) { Isolate* isolate = args.GetIsolate(); GZNode *obj = ObjectWrap::Unwrap(args.This()); @@ -221,8 +219,7 @@ void GZNode::GetPoseMsgFilterMinimumDistanceSquared(const } ///////////////////////////////////////////////////// -void GZNode::SetPoseMsgFilterMinimumQuaternionSquared(const - FunctionCallbackInfo& args) +NAN_METHOD(GZNode::SetPoseMsgFilterMinimumQuaternionSquared) { GZNode *obj = ObjectWrap::Unwrap(args.This()); Local v = Local::Cast(args[0]); @@ -233,8 +230,7 @@ void GZNode::SetPoseMsgFilterMinimumQuaternionSquared(const } ///////////////////////////////////////////////// -void GZNode::GetPoseMsgFilterMinimumQuaternionSquared(const - FunctionCallbackInfo& args) +NAN_METHOD(GZNode::GetPoseMsgFilterMinimumQuaternionSquared) { Isolate* isolate = args.GetIsolate(); GZNode *obj = ObjectWrap::Unwrap(args.This()); @@ -243,7 +239,7 @@ void GZNode::GetPoseMsgFilterMinimumQuaternionSquared(const } ///////////////////////////////////////////////// -void GZNode::GetMessages(const FunctionCallbackInfo& args) +NAN_METHOD(GZNode::GetMessages) { Isolate* isolate = args.GetIsolate(); Local context = isolate->GetCurrentContext(); @@ -267,7 +263,7 @@ void GZNode::GetMessages(const FunctionCallbackInfo& args) //////////////////////////////////////////////// -void GZNode::Request(const FunctionCallbackInfo& args) +NAN_METHOD(GZNode::Request) { Isolate* isolate = args.GetIsolate(); @@ -298,8 +294,7 @@ void GZNode::Request(const FunctionCallbackInfo& args) } ///////////////////////////////////////////////// -void GZNode::SetPoseMsgFilterMinimumAge(const - FunctionCallbackInfo& args) +NAN_METHOD(GZNode::SetPoseMsgFilterMinimumAge) { GZNode* obj = ObjectWrap::Unwrap(args.This()); Local v = Local::Cast(args[0]); @@ -310,8 +305,7 @@ void GZNode::SetPoseMsgFilterMinimumAge(const } ///////////////////////////////////////////////// -void GZNode::GetPoseMsgFilterMinimumAge(const - FunctionCallbackInfo& args) +NAN_METHOD(GZNode::GetPoseMsgFilterMinimumAge) { GZNode* obj = ObjectWrap::Unwrap(args.This()); double value = obj->gzIface->GetPoseFilterMinimumMsgAge(); diff --git a/gzbridge/GZNode.hh b/gzbridge/GZNode.hh index 2c3aedf0..f87710c9 100644 --- a/gzbridge/GZNode.hh +++ b/gzbridge/GZNode.hh @@ -33,47 +33,37 @@ namespace gzweb class GZNode : public node::ObjectWrap { - public: static void Init(v8::Local exports); + public: static NAN_MODULE_INIT(Init); private: GZNode(); private: ~GZNode(); - private: static void New(const FunctionCallbackInfo& args); + private: static NAN_METHOD(New); - private: static void LoadMaterialScripts( - const FunctionCallbackInfo& args); + private: static NAN_METHOD(LoadMaterialScripts); - private: static void SetConnected( - const FunctionCallbackInfo& args); + private: static NAN_METHOD(SetConnected); - private: static void GetIsGzServerConnected( - const FunctionCallbackInfo& args); + private: static NAN_METHOD(GetIsGzServerConnected); - private: static void GetMaterialScriptsMessage( - const FunctionCallbackInfo& args); + private: static NAN_METHOD(GetMaterialScriptsMessage); - private: static void SetPoseMsgFilterMinimumDistanceSquared( - const FunctionCallbackInfo& args); + private: static NAN_METHOD(SetPoseMsgFilterMinimumDistanceSquared); - private: static void GetPoseMsgFilterMinimumDistanceSquared( - const FunctionCallbackInfo& args); + private: static NAN_METHOD(GetPoseMsgFilterMinimumDistanceSquared); - private: static void SetPoseMsgFilterMinimumQuaternionSquared( - const FunctionCallbackInfo& args); + private: static NAN_METHOD(SetPoseMsgFilterMinimumQuaternionSquared); - private: static void GetPoseMsgFilterMinimumQuaternionSquared( - const FunctionCallbackInfo& args); + private: static NAN_METHOD(GetPoseMsgFilterMinimumQuaternionSquared); - private: static void GetMessages(const FunctionCallbackInfo& args); + private: static NAN_METHOD(GetMessages); - private: static void Request(const FunctionCallbackInfo& args); + private: static NAN_METHOD(Request); - private: static void SetPoseMsgFilterMinimumAge( - const FunctionCallbackInfo& args); + private: static NAN_METHOD(SetPoseMsgFilterMinimumAge); - private: static void GetPoseMsgFilterMinimumAge( - const FunctionCallbackInfo& args); + private: static NAN_METHOD(GetPoseMsgFilterMinimumAge); private: GazeboInterface* gzIface = nullptr; From 03fcd02366d451db226119d1b3e92f4fb78a65b2 Mon Sep 17 00:00:00 2001 From: Felipe Gomes de Melo Date: Tue, 2 Feb 2021 11:43:59 -0300 Subject: [PATCH 12/19] Replace "args" w/ "info" The NAN_METHOD macro defines the argument as "info" instead of "args" https://github.com/nodejs/nan/blob/v2.14.2/nan.h#L1567-L1568 --- gzbridge/GZNode.cc | 84 +++++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/gzbridge/GZNode.cc b/gzbridge/GZNode.cc index e1477621..3c84985b 100644 --- a/gzbridge/GZNode.cc +++ b/gzbridge/GZNode.cc @@ -91,20 +91,20 @@ void GZNode::Init(Local exports) ///////////////////////////////////////////////// NAN_METHOD(GZNode::New) { - if (args.IsConstructCall()) { + if (info.IsConstructCall()) { // Invoked as constructor: `new MyObject(...)` GZNode* obj = new GZNode(); - obj->Wrap(args.This()); - args.GetReturnValue().Set(args.This()); + obj->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); } } ///////////////////////////////////////////////// NAN_METHOD(GZNode::LoadMaterialScripts) { - Isolate* isolate = args.GetIsolate(); + Isolate* isolate = info.GetIsolate(); - if (args.Length() < 1) + if (info.Length() < 1) { isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, @@ -113,7 +113,7 @@ NAN_METHOD(GZNode::LoadMaterialScripts) return; } - if (!args[0]->IsString()) + if (!info[0]->IsString()) { isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, @@ -122,9 +122,9 @@ NAN_METHOD(GZNode::LoadMaterialScripts) return; } - GZNode* obj = ObjectWrap::Unwrap(args.This()); + GZNode* obj = ObjectWrap::Unwrap(info.This()); - String::Utf8Value path(isolate, args[0]); + String::Utf8Value path(isolate, info[0]); obj->gzIface->LoadMaterialScripts(std::string(*path)); return; @@ -133,15 +133,15 @@ NAN_METHOD(GZNode::LoadMaterialScripts) ///////////////////////////////////////////////// NAN_METHOD(GZNode::SetConnected) { - Isolate* isolate = args.GetIsolate(); + Isolate* isolate = info.GetIsolate(); - GZNode *obj = ObjectWrap::Unwrap(args.This()); + GZNode *obj = ObjectWrap::Unwrap(info.This()); #if NODE_MAJOR_VERSION<=10 Local context = isolate->GetCurrentContext(); - bool value = args[0]->BooleanValue(context).ToChecked(); + bool value = info[0]->BooleanValue(context).ToChecked(); #else - bool value = args[0]->BooleanValue(isolate); + bool value = info[0]->BooleanValue(isolate); #endif obj->gzIface->SetConnected(value); @@ -151,18 +151,18 @@ NAN_METHOD(GZNode::SetConnected) ///////////////////////////////////////////////// NAN_METHOD(GZNode::GetIsGzServerConnected) { - GZNode *obj = ObjectWrap::Unwrap(args.This()); + GZNode *obj = ObjectWrap::Unwrap(info.This()); bool value = obj->isGzServerConnected; - args.GetReturnValue().Set(value); + info.GetReturnValue().Set(value); } ///////////////////////////////////////////////// NAN_METHOD(GZNode::GetMaterialScriptsMessage) { - Isolate* isolate = args.GetIsolate(); + Isolate* isolate = info.GetIsolate(); - if (args.Length() < 1) + if (info.Length() < 1) { isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, @@ -171,7 +171,7 @@ NAN_METHOD(GZNode::GetMaterialScriptsMessage) return; } - if (!args[0]->IsString()) + if (!info[0]->IsString()) { isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, @@ -180,7 +180,7 @@ NAN_METHOD(GZNode::GetMaterialScriptsMessage) return; } - String::Utf8Value path(isolate, args[0]); + String::Utf8Value path(isolate, info[0]); OgreMaterialParser materialParser; materialParser.Load(std::string(*path)); @@ -191,7 +191,7 @@ NAN_METHOD(GZNode::GetMaterialScriptsMessage) msg += materialJson; msg += "}"; - args.GetReturnValue().Set( + info.GetReturnValue().Set( String::NewFromUtf8(isolate, msg.c_str(), NewStringType::kNormal).ToLocalChecked()); @@ -200,9 +200,9 @@ NAN_METHOD(GZNode::GetMaterialScriptsMessage) ///////////////////////////////////////////////// NAN_METHOD(GZNode::SetPoseMsgFilterMinimumDistanceSquared) { - GZNode *obj = ObjectWrap::Unwrap(args.This()); + GZNode *obj = ObjectWrap::Unwrap(info.This()); - Local v = Local::Cast(args[0]); + Local v = Local::Cast(info[0]); double value = v->Value(); obj->gzIface->SetPoseFilterMinimumDistanceSquared(value); @@ -212,17 +212,17 @@ NAN_METHOD(GZNode::SetPoseMsgFilterMinimumDistanceSquared) ///////////////////////////////////////////////// NAN_METHOD(GZNode::GetPoseMsgFilterMinimumDistanceSquared) { - Isolate* isolate = args.GetIsolate(); - GZNode *obj = ObjectWrap::Unwrap(args.This()); + Isolate* isolate = info.GetIsolate(); + GZNode *obj = ObjectWrap::Unwrap(info.This()); double value = obj->gzIface->GetPoseFilterMinimumDistanceSquared(); - args.GetReturnValue().Set(Number::New(isolate ,value)); + info.GetReturnValue().Set(Number::New(isolate ,value)); } ///////////////////////////////////////////////////// NAN_METHOD(GZNode::SetPoseMsgFilterMinimumQuaternionSquared) { - GZNode *obj = ObjectWrap::Unwrap(args.This()); - Local v = Local::Cast(args[0]); + GZNode *obj = ObjectWrap::Unwrap(info.This()); + Local v = Local::Cast(info[0]); double value = v->Value(); obj->gzIface->SetPoseFilterMinimumQuaternionSquared(value); @@ -232,22 +232,22 @@ NAN_METHOD(GZNode::SetPoseMsgFilterMinimumQuaternionSquared) ///////////////////////////////////////////////// NAN_METHOD(GZNode::GetPoseMsgFilterMinimumQuaternionSquared) { - Isolate* isolate = args.GetIsolate(); - GZNode *obj = ObjectWrap::Unwrap(args.This()); + Isolate* isolate = info.GetIsolate(); + GZNode *obj = ObjectWrap::Unwrap(info.This()); double value = obj->gzIface->GetPoseFilterMinimumQuaternionSquared(); - args.GetReturnValue().Set(Number::New(isolate ,value)); + info.GetReturnValue().Set(Number::New(isolate ,value)); } ///////////////////////////////////////////////// NAN_METHOD(GZNode::GetMessages) { - Isolate* isolate = args.GetIsolate(); + Isolate* isolate = info.GetIsolate(); Local context = isolate->GetCurrentContext(); - GZNode* obj = ObjectWrap::Unwrap(args.This()); + GZNode* obj = ObjectWrap::Unwrap(info.This()); std::vector msgs = obj->gzIface->PopOutgoingMessages(); - // args.GetReturnValue().Set(Number::New(isolate ,msgs.size())); + // info.GetReturnValue().Set(Number::New(isolate ,msgs.size())); Local arguments = Array::New(isolate, msgs.size()); for (unsigned int i = 0; i < msgs.size(); ++i) { MaybeLocal v8_msg = String::NewFromUtf8(isolate, msgs[i].c_str(), NewStringType::kNormal); @@ -258,16 +258,16 @@ NAN_METHOD(GZNode::GetMessages) } } - args.GetReturnValue().Set(arguments); + info.GetReturnValue().Set(arguments); } //////////////////////////////////////////////// NAN_METHOD(GZNode::Request) { - Isolate* isolate = args.GetIsolate(); + Isolate* isolate = info.GetIsolate(); - if (args.Length() < 1) + if (info.Length() < 1) { isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, @@ -276,7 +276,7 @@ NAN_METHOD(GZNode::Request) return; } - if (!args[0]->IsString()) + if (!info[0]->IsString()) { isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, @@ -285,9 +285,9 @@ NAN_METHOD(GZNode::Request) return; } - GZNode* obj = ObjectWrap::Unwrap(args.This()); + GZNode* obj = ObjectWrap::Unwrap(info.This()); - String::Utf8Value request(isolate, args[0]); + String::Utf8Value request(isolate, info[0]); obj->gzIface->PushRequest(std::string(*request)); return; @@ -296,8 +296,8 @@ NAN_METHOD(GZNode::Request) ///////////////////////////////////////////////// NAN_METHOD(GZNode::SetPoseMsgFilterMinimumAge) { - GZNode* obj = ObjectWrap::Unwrap(args.This()); - Local v = Local::Cast(args[0]); + GZNode* obj = ObjectWrap::Unwrap(info.This()); + Local v = Local::Cast(info[0]); double value = v->Value(); obj->gzIface->SetPoseFilterMinimumMsgAge(value); @@ -307,9 +307,9 @@ NAN_METHOD(GZNode::SetPoseMsgFilterMinimumAge) ///////////////////////////////////////////////// NAN_METHOD(GZNode::GetPoseMsgFilterMinimumAge) { - GZNode* obj = ObjectWrap::Unwrap(args.This()); + GZNode* obj = ObjectWrap::Unwrap(info.This()); double value = obj->gzIface->GetPoseFilterMinimumMsgAge(); - args.GetReturnValue().Set(value); + info.GetReturnValue().Set(value); } ///////////////////////////////////////////////// From 5d427f4440624f3e523ece96044c930758b5cea2 Mon Sep 17 00:00:00 2001 From: Felipe Gomes de Melo Date: Tue, 2 Feb 2021 11:49:14 -0300 Subject: [PATCH 13/19] Change includes from node.h to nan.h --- gzbridge/GZNode.cc | 2 +- gzbridge/GZNode.hh | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/gzbridge/GZNode.cc b/gzbridge/GZNode.cc index 3c84985b..6f636e84 100644 --- a/gzbridge/GZNode.cc +++ b/gzbridge/GZNode.cc @@ -15,7 +15,7 @@ * */ -#include +#include #include "GZNode.hh" #include "GazeboInterface.hh" diff --git a/gzbridge/GZNode.hh b/gzbridge/GZNode.hh index f87710c9..1fcdee79 100644 --- a/gzbridge/GZNode.hh +++ b/gzbridge/GZNode.hh @@ -18,8 +18,7 @@ #ifndef GZBRIDGE_GZNODE_HH_ #define GZBRIDGE_GZNODE_HH_ -#include -#include +#include namespace gzweb { @@ -31,7 +30,7 @@ namespace gzweb class GazeboInterface; - class GZNode : public node::ObjectWrap + class GZNode : public Nan::ObjectWrap { public: static NAN_MODULE_INIT(Init); From 2d3a773cdc7b61c464ea87c80f97dbf1053ec108 Mon Sep 17 00:00:00 2001 From: Felipe Gomes de Melo Date: Tue, 2 Feb 2021 11:50:31 -0300 Subject: [PATCH 14/19] Replace NODE_SET_PROTOTYPE_METHOD w/ Nan func --- gzbridge/GZNode.cc | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/gzbridge/GZNode.cc b/gzbridge/GZNode.cc index 6f636e84..c444b3db 100644 --- a/gzbridge/GZNode.cc +++ b/gzbridge/GZNode.cc @@ -59,29 +59,29 @@ void GZNode::Init(Local exports) tpl->SetClassName(class_name); tpl->InstanceTemplate()->SetInternalFieldCount(1); // Prototype - NODE_SET_PROTOTYPE_METHOD(tpl, "loadMaterialScripts", LoadMaterialScripts); + Nan::SetPrototypeMethod(tpl, "loadMaterialScripts", LoadMaterialScripts); - NODE_SET_PROTOTYPE_METHOD(tpl, "setConnected", SetConnected); + Nan::SetPrototypeMethod(tpl, "setConnected", SetConnected); - NODE_SET_PROTOTYPE_METHOD(tpl, "setPoseMsgFilterMinimumDistanceSquared", SetPoseMsgFilterMinimumDistanceSquared); - NODE_SET_PROTOTYPE_METHOD(tpl, "getPoseMsgFilterMinimumDistanceSquared", GetPoseMsgFilterMinimumDistanceSquared); - NODE_SET_PROTOTYPE_METHOD(tpl, "setPoseMsgFilterMinimumQuaternionSquared", SetPoseMsgFilterMinimumQuaternionSquared); - NODE_SET_PROTOTYPE_METHOD(tpl, "getPoseMsgFilterMinimumQuaternionSquared", GetPoseMsgFilterMinimumQuaternionSquared); + Nan::SetPrototypeMethod(tpl, "setPoseMsgFilterMinimumDistanceSquared", SetPoseMsgFilterMinimumDistanceSquared); + Nan::SetPrototypeMethod(tpl, "getPoseMsgFilterMinimumDistanceSquared", GetPoseMsgFilterMinimumDistanceSquared); + Nan::SetPrototypeMethod(tpl, "setPoseMsgFilterMinimumQuaternionSquared", SetPoseMsgFilterMinimumQuaternionSquared); + Nan::SetPrototypeMethod(tpl, "getPoseMsgFilterMinimumQuaternionSquared", GetPoseMsgFilterMinimumQuaternionSquared); - NODE_SET_PROTOTYPE_METHOD(tpl, "getPoseMsgFilterMinimumAge", + Nan::SetPrototypeMethod(tpl, "getPoseMsgFilterMinimumAge", GetPoseMsgFilterMinimumAge); - NODE_SET_PROTOTYPE_METHOD(tpl, "setPoseMsgFilterMinimumAge", + Nan::SetPrototypeMethod(tpl, "setPoseMsgFilterMinimumAge", SetPoseMsgFilterMinimumAge); - NODE_SET_PROTOTYPE_METHOD(tpl, "getMessages", GetMessages); + Nan::SetPrototypeMethod(tpl, "getMessages", GetMessages); - NODE_SET_PROTOTYPE_METHOD(tpl, "request", Request); + Nan::SetPrototypeMethod(tpl, "request", Request); - NODE_SET_PROTOTYPE_METHOD(tpl, "getIsGzServerConnected", + Nan::SetPrototypeMethod(tpl, "getIsGzServerConnected", GetIsGzServerConnected); - NODE_SET_PROTOTYPE_METHOD(tpl, "getMaterialScriptsMessage", + Nan::SetPrototypeMethod(tpl, "getMaterialScriptsMessage", GetMaterialScriptsMessage); Local context = isolate->GetCurrentContext(); From 84a207609024653fb223c2f585c6abfebb7add89 Mon Sep 17 00:00:00 2001 From: Felipe Gomes de Melo Date: Tue, 2 Feb 2021 11:52:15 -0300 Subject: [PATCH 15/19] Simplify errors w/ Nan methods --- gzbridge/GZNode.cc | 38 ++++++++------------------------------ 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/gzbridge/GZNode.cc b/gzbridge/GZNode.cc index c444b3db..5af25cb9 100644 --- a/gzbridge/GZNode.cc +++ b/gzbridge/GZNode.cc @@ -96,6 +96,8 @@ NAN_METHOD(GZNode::New) GZNode* obj = new GZNode(); obj->Wrap(info.This()); info.GetReturnValue().Set(info.This()); + }else{ + return Nan::ThrowTypeError("GZNode::New - called without new keyword"); } } @@ -106,20 +108,12 @@ NAN_METHOD(GZNode::LoadMaterialScripts) if (info.Length() < 1) { - isolate->ThrowException(Exception::TypeError( - String::NewFromUtf8(isolate, - "Wrong number of arguments", - NewStringType::kNormal).ToLocalChecked())); - return; + return Nan::ThrowTypeError("GZNode::LoadMaterialScripts - Wrong number of arguments. One arg expected"); } if (!info[0]->IsString()) { - isolate->ThrowException(Exception::TypeError( - String::NewFromUtf8(isolate, - "Wrong argument type. String expected.", - NewStringType::kNormal).ToLocalChecked())); - return; + return Nan::ThrowTypeError("GZNode::LoadMaterialScripts - Wrong argument type. String expected."); } GZNode* obj = ObjectWrap::Unwrap(info.This()); @@ -164,20 +158,12 @@ NAN_METHOD(GZNode::GetMaterialScriptsMessage) if (info.Length() < 1) { - isolate->ThrowException(Exception::TypeError( - String::NewFromUtf8(isolate, - "Wrong number of arguments", - NewStringType::kNormal).ToLocalChecked())); - return; + return Nan::ThrowTypeError("GZNode::GetMaterialScriptsMessage - Wrong number of arguments. One arg expected."); } if (!info[0]->IsString()) { - isolate->ThrowException(Exception::TypeError( - String::NewFromUtf8(isolate, - "Wrong argument type. String expected.", - NewStringType::kNormal).ToLocalChecked())); - return; + return Nan::ThrowTypeError("GZNode::GetMaterialScriptsMessage - Wrong argument type. String expected."); } String::Utf8Value path(isolate, info[0]); @@ -269,20 +255,12 @@ NAN_METHOD(GZNode::Request) if (info.Length() < 1) { - isolate->ThrowException(Exception::TypeError( - String::NewFromUtf8(isolate, - "Wrong number of arguments", - NewStringType::kNormal).ToLocalChecked())); - return; + return Nan::ThrowTypeError("GZNode::Request - Wrong number of arguments. One arg expected."); } if (!info[0]->IsString()) { - isolate->ThrowException(Exception::TypeError( - String::NewFromUtf8(isolate, - "Wrong argument type. String expected.", - NewStringType::kNormal).ToLocalChecked())); - return; + return Nan::ThrowTypeError("GZNode::Request - Wrong argument type. String expected."); } GZNode* obj = ObjectWrap::Unwrap(info.This()); From aff877759933d21857df6178bf2c5b40f2bcaa79 Mon Sep 17 00:00:00 2001 From: Felipe Gomes de Melo Date: Tue, 2 Feb 2021 11:57:24 -0300 Subject: [PATCH 16/19] Refactor code w/ Nan methods --- gzbridge/GZNode.cc | 44 +++++++++++++------------------------------- 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/gzbridge/GZNode.cc b/gzbridge/GZNode.cc index 5af25cb9..5497cdb7 100644 --- a/gzbridge/GZNode.cc +++ b/gzbridge/GZNode.cc @@ -84,8 +84,9 @@ void GZNode::Init(Local exports) Nan::SetPrototypeMethod(tpl, "getMaterialScriptsMessage", GetMaterialScriptsMessage); - Local context = isolate->GetCurrentContext(); - exports->Set(context, class_name, tpl->GetFunction(context).ToLocalChecked()).ToChecked(); + target->Set(Nan::GetCurrentContext(), class_name, + tpl->GetFunction(Nan::GetCurrentContext()).ToLocalChecked() + ).ToChecked(); } ///////////////////////////////////////////////// @@ -127,16 +128,9 @@ NAN_METHOD(GZNode::LoadMaterialScripts) ///////////////////////////////////////////////// NAN_METHOD(GZNode::SetConnected) { - Isolate* isolate = info.GetIsolate(); GZNode *obj = ObjectWrap::Unwrap(info.This()); - -#if NODE_MAJOR_VERSION<=10 - Local context = isolate->GetCurrentContext(); - bool value = info[0]->BooleanValue(context).ToChecked(); -#else - bool value = info[0]->BooleanValue(isolate); -#endif + bool value = Nan::To(info[0]).ToChecked(); obj->gzIface->SetConnected(value); return; @@ -177,10 +171,7 @@ NAN_METHOD(GZNode::GetMaterialScriptsMessage) msg += materialJson; msg += "}"; - info.GetReturnValue().Set( - String::NewFromUtf8(isolate, - msg.c_str(), - NewStringType::kNormal).ToLocalChecked()); + info.GetReturnValue().Set(Nan::New(msg.c_str()).ToLocalChecked()); } ///////////////////////////////////////////////// @@ -188,7 +179,7 @@ NAN_METHOD(GZNode::SetPoseMsgFilterMinimumDistanceSquared) { GZNode *obj = ObjectWrap::Unwrap(info.This()); - Local v = Local::Cast(info[0]); + Local v = Nan::To(info[0]).ToLocalChecked(); double value = v->Value(); obj->gzIface->SetPoseFilterMinimumDistanceSquared(value); @@ -198,17 +189,16 @@ NAN_METHOD(GZNode::SetPoseMsgFilterMinimumDistanceSquared) ///////////////////////////////////////////////// NAN_METHOD(GZNode::GetPoseMsgFilterMinimumDistanceSquared) { - Isolate* isolate = info.GetIsolate(); GZNode *obj = ObjectWrap::Unwrap(info.This()); double value = obj->gzIface->GetPoseFilterMinimumDistanceSquared(); - info.GetReturnValue().Set(Number::New(isolate ,value)); + info.GetReturnValue().Set(Nan::New(value)); } ///////////////////////////////////////////////////// NAN_METHOD(GZNode::SetPoseMsgFilterMinimumQuaternionSquared) { GZNode *obj = ObjectWrap::Unwrap(info.This()); - Local v = Local::Cast(info[0]); + Local v = Nan::To(info[0]).ToLocalChecked(); double value = v->Value(); obj->gzIface->SetPoseFilterMinimumQuaternionSquared(value); @@ -218,30 +208,22 @@ NAN_METHOD(GZNode::SetPoseMsgFilterMinimumQuaternionSquared) ///////////////////////////////////////////////// NAN_METHOD(GZNode::GetPoseMsgFilterMinimumQuaternionSquared) { - Isolate* isolate = info.GetIsolate(); GZNode *obj = ObjectWrap::Unwrap(info.This()); double value = obj->gzIface->GetPoseFilterMinimumQuaternionSquared(); - info.GetReturnValue().Set(Number::New(isolate ,value)); + info.GetReturnValue().Set(Nan::New(value)); } ///////////////////////////////////////////////// NAN_METHOD(GZNode::GetMessages) { - Isolate* isolate = info.GetIsolate(); - Local context = isolate->GetCurrentContext(); GZNode* obj = ObjectWrap::Unwrap(info.This()); std::vector msgs = obj->gzIface->PopOutgoingMessages(); - // info.GetReturnValue().Set(Number::New(isolate ,msgs.size())); - Local arguments = Array::New(isolate, msgs.size()); + Local arguments = Nan::New(msgs.size()); for (unsigned int i = 0; i < msgs.size(); ++i) { - MaybeLocal v8_msg = String::NewFromUtf8(isolate, msgs[i].c_str(), NewStringType::kNormal); - bool sucess = arguments->Set(context, i, v8_msg.ToLocalChecked()).FromJust(); - if(!sucess){ - //TODO handle failure - return; - } + Local v8_msg = Nan::New(msgs[i].c_str()).ToLocalChecked(); + Nan::Set(arguments, i, v8_msg); } info.GetReturnValue().Set(arguments); @@ -275,7 +257,7 @@ NAN_METHOD(GZNode::Request) NAN_METHOD(GZNode::SetPoseMsgFilterMinimumAge) { GZNode* obj = ObjectWrap::Unwrap(info.This()); - Local v = Local::Cast(info[0]); + Local v = Nan::To(info[0]).ToLocalChecked(); double value = v->Value(); obj->gzIface->SetPoseFilterMinimumMsgAge(value); From 1982ba78539a55c401a0d8a8ba5b7bde8acc7094 Mon Sep 17 00:00:00 2001 From: Felipe Gomes de Melo Date: Tue, 2 Feb 2021 11:57:59 -0300 Subject: [PATCH 17/19] Refactor GZNode init signature --- gzbridge/GZNode.cc | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/gzbridge/GZNode.cc b/gzbridge/GZNode.cc index 5497cdb7..db1b853f 100644 --- a/gzbridge/GZNode.cc +++ b/gzbridge/GZNode.cc @@ -47,14 +47,12 @@ GZNode::~GZNode() }; ///////////////////////////////////////////////// -void GZNode::Init(Local exports) +NAN_MODULE_INIT(GZNode::Init) { - Isolate* isolate = exports->GetIsolate(); // Prepare constructor template - Local class_name = String::NewFromUtf8(isolate, "GZNode", - NewStringType::kInternalized).ToLocalChecked(); + Local class_name = Nan::New("GZNode").ToLocalChecked(); - Local tpl = FunctionTemplate::New(isolate, New); + Local tpl = Nan::New(GZNode::New); tpl->SetClassName(class_name); tpl->InstanceTemplate()->SetInternalFieldCount(1); From 6f40610897e33925299c781aae459df380d7a042 Mon Sep 17 00:00:00 2001 From: Felipe Gomes de Melo Date: Tue, 2 Feb 2021 11:58:09 -0300 Subject: [PATCH 18/19] Remove unused code --- gzbridge/GZNode.hh | 5 ----- 1 file changed, 5 deletions(-) diff --git a/gzbridge/GZNode.hh b/gzbridge/GZNode.hh index 1fcdee79..8b561836 100644 --- a/gzbridge/GZNode.hh +++ b/gzbridge/GZNode.hh @@ -22,11 +22,6 @@ namespace gzweb { - using v8::FunctionCallbackInfo; - using v8::Value; - using v8::FunctionTemplate; - using v8::Object; - using v8::Persistent; class GazeboInterface; From 8a6a7d6ad34cb5a1d7aea702a05e640fdbe66ca2 Mon Sep 17 00:00:00 2001 From: Felipe Gomes de Melo Date: Tue, 2 Feb 2021 11:58:38 -0300 Subject: [PATCH 19/19] Add Nan as dependency --- gzbridge/binding.gyp | 3 +++ package.json | 1 + 2 files changed, 4 insertions(+) diff --git a/gzbridge/binding.gyp b/gzbridge/binding.gyp index 7b53e7a6..936725c5 100644 --- a/gzbridge/binding.gyp +++ b/gzbridge/binding.gyp @@ -7,6 +7,9 @@ "pb2json.cc", "pb2json.hh", "ConfigLoader.cc", "ConfigLoader.hh", "OgreMaterialParser.cc", "OgreMaterialParser.hh"], + "include_dirs" : [ + "