From c0dc8a3ddaa67d0a1a6c89f08f1cbeb48ecc3f87 Mon Sep 17 00:00:00 2001 From: David Krutsko Date: Sun, 9 Apr 2017 19:41:20 -0400 Subject: [PATCH] Added support for Node ^7.0.0 (#14, fixes #5, #16) --- Native/Addon/Common.h | 39 ++++++++++++++++++++++++++++++++++---- Native/Addon/Makefile | 4 ++-- Native/Addon/Process.cc | 8 ++++---- Native/Addon/Robot.vcxproj | 4 ++-- Native/Makefile | 2 +- 5 files changed, 44 insertions(+), 13 deletions(-) diff --git a/Native/Addon/Common.h b/Native/Addon/Common.h index e53463f..26095f6 100644 --- a/Native/Addon/Common.h +++ b/Native/Addon/Common.h @@ -189,9 +189,25 @@ enum RobotType //////////////////////////////////////////////////////////////////////////////// -#define REGISTER_ROBOT_TYPE \ - args.This()->SetHiddenValue (NEW_STR \ - ("_ROBOT_TYPE"), NEW_INT (ClassType)); +#if NODE_MODULE_VERSION >= 48 + + #define REGISTER_ROBOT_TYPE \ + { \ + auto context = isolate->GetCurrentContext(); \ + auto privateKeyValue = Private::ForApi \ + (isolate, NEW_STR ("_ROBOT_TYPE")); \ + \ + args.This()->SetPrivate (context, \ + privateKeyValue, NEW_INT (ClassType)); \ + } + +#else + + #define REGISTER_ROBOT_TYPE \ + args.This()->SetHiddenValue (NEW_STR \ + ("_ROBOT_TYPE"), NEW_INT (ClassType)); + +#endif //////////////////////////////////////////////////////////////////////////////// @@ -204,11 +220,26 @@ inline T* UnwrapRobot (Handle value) // Value needs to be at least an object if (!value->IsObject()) return nullptr; + // Retrieve the local object + auto obj = value->ToObject(); + +#if NODE_MODULE_VERSION >= 48 + + auto context = isolate->GetCurrentContext(); + auto privateKeyValue = Private::ForApi + (isolate, NEW_STR ("_ROBOT_TYPE")); + + auto type = obj->GetPrivate (context, + privateKeyValue).ToLocalChecked(); + +#else + // Convert and get hidden type - auto obj = value->ToObject(); auto type = obj->GetHiddenValue (NEW_STR ("_ROBOT_TYPE")); +#endif + // The value must contain a handle if (type.IsEmpty()) return nullptr; diff --git a/Native/Addon/Makefile b/Native/Addon/Makefile index 708b3d9..304bdf6 100644 --- a/Native/Addon/Makefile +++ b/Native/Addon/Makefile @@ -19,12 +19,12 @@ LBITS = $(shell getconf LONG_BIT) ifdef nodeVersion NODE_VERSION = $(nodeVersion) else - NODE_VERSION = 0.12.13 + NODE_VERSION = 7.8.0 endif ifdef nodeModules NODE_MODULES = $(nodeModules) else - NODE_MODULES = 14 + NODE_MODULES = 51 endif ifeq ($(UNAME), Darwin) diff --git a/Native/Addon/Process.cc b/Native/Addon/Process.cc index 2fa51f7..1a772f3 100644 --- a/Native/Addon/Process.cc +++ b/Native/Addon/Process.cc @@ -280,10 +280,10 @@ void ProcessWrap::GetSegments (const FunctionCallbackInfo& args) auto ctor = Local:: New (isolate, JsSegment); - // Synthesize new module - Module module (*mProcess, - "", "", (uintptr) - args[1]->NumberValue(), 0); + // Create new module + Robot::Module module + (*mProcess, "", "", (uintptr) + args[1]->NumberValue(), 0); // Retrieve the list of segments auto list = module.GetSegments(); diff --git a/Native/Addon/Robot.vcxproj b/Native/Addon/Robot.vcxproj index e5a2ea9..6bc9816 100644 --- a/Native/Addon/Robot.vcxproj +++ b/Native/Addon/Robot.vcxproj @@ -275,8 +275,8 @@ - 0.12.13 - 14 + 7.8.0 + 51 $(SolutionDir)\Binaries\Win32\ diff --git a/Native/Makefile b/Native/Makefile index 7625be6..37d479d 100644 --- a/Native/Makefile +++ b/Native/Makefile @@ -32,7 +32,7 @@ help: @echo @echo "NODE" @echo " This project can be built for multiple versions of Node" - @echo " By default, this project is built using Node 0.12.13" + @echo " By default, this project is built using Node 7.8.0" @echo " nodeVersion: represents the node version to compile with" @echo " nodeModules: represents the NODE_MODULE_VERSION constant" @echo " $$ make nodeVersion=4.4.0 nodeModules=46 "