Skip to content

Commit

Permalink
Added support for Node ^7.0.0 (#14, fixes #5, #16)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkrutsko authored Apr 9, 2017
1 parent 3c5e0ff commit c0dc8a3
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 13 deletions.
39 changes: 35 additions & 4 deletions Native/Addon/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

////////////////////////////////////////////////////////////////////////////////

Expand All @@ -204,11 +220,26 @@ inline T* UnwrapRobot (Handle<Value> 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;

Expand Down
4 changes: 2 additions & 2 deletions Native/Addon/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions Native/Addon/Process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,10 @@ void ProcessWrap::GetSegments (const FunctionCallbackInfo<Value>& args)
auto ctor = Local<Function>::
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();
Expand Down
4 changes: 2 additions & 2 deletions Native/Addon/Robot.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros">
<NodeVersion>0.12.13</NodeVersion>
<NodeModules>14</NodeModules>
<NodeVersion>7.8.0</NodeVersion>
<NodeModules>51</NodeModules>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DLL|Win32'">
<OutDir>$(SolutionDir)\Binaries\Win32\</OutDir>
Expand Down
2 changes: 1 addition & 1 deletion Native/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cmd>"
Expand Down

0 comments on commit c0dc8a3

Please sign in to comment.