Skip to content

Commit 008ebc8

Browse files
committed
Build for Node 12 / Electron 6
1 parent 3046e74 commit 008ebc8

20 files changed

+422
-404
lines changed

src/NodeClipboard.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void ClipboardWrap::SetText (const FunctionCallbackInfo<Value>& args)
5353
if (!args[0]->IsString())
5454
THROW (Type, "Invalid arguments");
5555

56-
String::Utf8Value value (args[0]);
56+
UTF8_VAR (value, args[0]);
5757
auto text = *value ? *value : "";
5858
RETURN_BOOL (Clipboard::SetText (text));
5959
}
@@ -100,7 +100,7 @@ void ClipboardWrap::GetSequence (const FunctionCallbackInfo<Value>& args)
100100

101101
////////////////////////////////////////////////////////////////////////////////
102102

103-
void ClipboardWrap::Initialize (Handle<Object> exports)
103+
void ClipboardWrap::Initialize (Local<Object> exports)
104104
{
105105
// Get the current isolated V8 instance
106106
Isolate* isolate = Isolate::GetCurrent();
@@ -121,5 +121,5 @@ void ClipboardWrap::Initialize (Handle<Object> exports)
121121
NODE_SET_METHOD (result, "getSequence", GetSequence);
122122

123123
// Export clipboard functions inside object
124-
exports->Set (NEW_STR ("Clipboard"), result);
124+
OBJECT_SET (exports, NEW_STR ("Clipboard"), result);
125125
}

src/NodeClipboard.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ class ClipboardWrap : public ObjectWrap
3838
static void GetSequence (const FunctionCallbackInfo<Value>& args);
3939

4040
public:
41-
static void Initialize (Handle<Object> exports);
41+
static void Initialize (Local<Object> exports);
4242
};

src/NodeCommon.h

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ ROBOT_NS_USE_ALL;
6262
#define NEW_INT( value ) Integer::New (isolate, value )
6363
#define NEW_NUM( value ) Number ::New (isolate, value )
6464
#define NEW_BOOL(value ) Boolean::New (isolate, value )
65+
#if NODE_MODULE_VERSION >= 67
66+
#define NEW_STR( value ) String ::NewFromUtf8 (isolate, value, v8::NewStringType::kNormal).ToLocalChecked()
67+
#else
6568
#define NEW_STR( value ) String ::NewFromUtf8 (isolate, value )
69+
#endif
6670
#define NEW_OBJ Object ::New (isolate )
6771
#define NEW_ARR( length) Array ::New (isolate, length)
6872
#define NEW_NULL Null (isolate )
@@ -109,10 +113,44 @@ ROBOT_NS_USE_ALL;
109113
NEW_INSTANCE (Local<Function>::New (isolate, JsBounds), 4, _jsArgs) \
110114
)
111115

112-
#define NEW_MODULE NEW_INSTANCE (Local<Function>::New (isolate, JsModule ), 0, NULL)
113-
#define NEW_SEGMENT NEW_INSTANCE (Local<Function>::New (isolate, JsSegment), 0, NULL)
114-
#define NEW_STATS NEW_INSTANCE (Local<Function>::New (isolate, JsStats ), 0, NULL)
115-
#define NEW_REGION NEW_INSTANCE (Local<Function>::New (isolate, JsRegion ), 0, NULL)
116+
#define NEW_MODULE NEW_INSTANCE (Local<Function>::New(isolate, JsModule ), 0, NULL)
117+
#define NEW_SEGMENT NEW_INSTANCE (Local<Function>::New(isolate, JsSegment), 0, NULL)
118+
#define NEW_STATS NEW_INSTANCE (Local<Function>::New(isolate, JsStats ), 0, NULL)
119+
#define NEW_REGION NEW_INSTANCE (Local<Function>::New(isolate, JsRegion ), 0, NULL)
120+
121+
////////////////////////////////////////////////////////////////////////////////
122+
123+
#if NODE_MODULE_VERSION >= 70
124+
#define BOOLEAN_VALUE( value ) (value->BooleanValue (isolate))
125+
#define UTF8_VAR( var, value ) String::Utf8Value var (isolate, value)
126+
#else
127+
#define BOOLEAN_VALUE( value ) (value->BooleanValue())
128+
#define UTF8_VAR( var, value ) String::Utf8Value var (value)
129+
#endif
130+
131+
#if NODE_MODULE_VERSION >= 67
132+
#define TO_OBJECT( value ) (value->ToObject (isolate->GetCurrentContext()).ToLocalChecked())
133+
#define NUMBER_VALUE( value ) (value->NumberValue (isolate->GetCurrentContext()).ToChecked())
134+
#define INT32_VALUE( value ) (value->Int32Value (isolate->GetCurrentContext()).ToChecked())
135+
#define UINT32_VALUE( value ) (value->Uint32Value (isolate->GetCurrentContext()).ToChecked())
136+
#define OBJECT_GET( map, key ) (map->Get (isolate->GetCurrentContext(), key).ToLocalChecked())
137+
#define OBJECT_SET( map, key, value ) (map->Set (isolate->GetCurrentContext(), key, value).ToChecked())
138+
#define GET_FUNCTION( tpl ) (tpl->GetFunction (isolate->GetCurrentContext()).ToLocalChecked())
139+
#else
140+
#define TO_OBJECT( value ) (value->ToObject())
141+
#define NUMBER_VALUE( value ) (value->NumberValue())
142+
#define INT32_VALUE( value ) (value->Int32Value())
143+
#define UINT32_VALUE( value ) (value->Uint32Value())
144+
#define OBJECT_GET( map, key ) (map->Get (key))
145+
#define OBJECT_SET( map, key, value ) (map->Set (key, value))
146+
#define GET_FUNCTION( tpl ) (tpl->GetFunction())
147+
#endif
148+
149+
#if NODE_MODULE_VERSION >= 48
150+
#define GET_PRIVATE( obj, key ) ((obj->GetPrivate (isolate->GetCurrentContext(), Private::ForApi (isolate, NEW_STR (key)))).ToLocalChecked())
151+
#else
152+
#define GET_PRIVATE( obj, key ) (obj->GetHiddenValue (NEW_STR (key)))
153+
#endif
116154

117155
////////////////////////////////////////////////////////////////////////////////
118156

@@ -219,7 +257,7 @@ enum RobotType
219257
////////////////////////////////////////////////////////////////////////////////
220258

221259
template <class T>
222-
inline T* UnwrapRobot (Handle<Value> value)
260+
inline T* UnwrapRobot (Local<Value> value)
223261
{
224262
// Get the current isolated V8 instance
225263
Isolate* isolate = Isolate::GetCurrent();
@@ -228,30 +266,16 @@ inline T* UnwrapRobot (Handle<Value> value)
228266
if (!value->IsObject()) return nullptr;
229267

230268
// Retrieve the local object
231-
auto obj = value->ToObject();
232-
233-
#if NODE_MODULE_VERSION >= 48
234-
235-
auto context = isolate->GetCurrentContext();
236-
auto privateKeyValue = Private::ForApi
237-
(isolate, NEW_STR ("_ROBOT_TYPE"));
238-
239-
auto type = obj->GetPrivate (context,
240-
privateKeyValue).ToLocalChecked();
241-
242-
#else
269+
auto obj = TO_OBJECT (value);
243270

244271
// Convert and get hidden type
245-
auto type = obj->GetHiddenValue
246-
(NEW_STR ("_ROBOT_TYPE"));
247-
248-
#endif
272+
auto type = GET_PRIVATE (obj, "_ROBOT_TYPE");
249273

250274
// The value must contain a handle
251275
if (type.IsEmpty()) return nullptr;
252276

253277
// Compare hidden type with class type
254-
if (type->Int32Value() != T::ClassType)
278+
if (INT32_VALUE (type) != T::ClassType)
255279
return nullptr;
256280

257281
// Return the final unwrapped class

src/NodeImage.cc

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ void ImageWrap::Create (const FunctionCallbackInfo<Value>& args)
3535
ISOWRAP (Image, args.Holder());
3636

3737
RETURN_BOOL (mImage->Create
38-
((uint16) args[0]->Int32Value(),
39-
(uint16) args[1]->Int32Value()));
38+
((uint16) INT32_VALUE (args[0]),
39+
(uint16) INT32_VALUE (args[1])));
4040
}
4141

4242
////////////////////////////////////////////////////////////////////////////////
@@ -106,8 +106,8 @@ void ImageWrap::GetPixel (const FunctionCallbackInfo<Value>& args)
106106
ISOWRAP (Image, args.Holder());
107107

108108
Color color = mImage->GetPixel
109-
((uint16) args[0]->Int32Value(),
110-
(uint16) args[1]->Int32Value());
109+
((uint16) INT32_VALUE (args[0]),
110+
(uint16) INT32_VALUE (args[1]));
111111

112112
RETURN_COLOR (color.R, color.G,
113113
color.B, color.A);
@@ -120,12 +120,12 @@ void ImageWrap::SetPixel (const FunctionCallbackInfo<Value>& args)
120120
ISOWRAP (Image, args.Holder());
121121

122122
mImage->SetPixel
123-
((uint16) args[0]->Int32Value(),
124-
(uint16) args[1]->Int32Value(),
125-
Color ((uint8 ) args[2]->Int32Value(),
126-
(uint8 ) args[3]->Int32Value(),
127-
(uint8 ) args[4]->Int32Value(),
128-
(uint8 ) args[5]->Int32Value()));
123+
((uint16) INT32_VALUE (args[0]),
124+
(uint16) INT32_VALUE (args[1]),
125+
Color ((uint8 ) INT32_VALUE (args[2]),
126+
(uint8 ) INT32_VALUE (args[3]),
127+
(uint8 ) INT32_VALUE (args[4]),
128+
(uint8 ) INT32_VALUE (args[5])));
129129
}
130130

131131
////////////////////////////////////////////////////////////////////////////////
@@ -135,10 +135,10 @@ void ImageWrap::Fill (const FunctionCallbackInfo<Value>& args)
135135
ISOWRAP (Image, args.Holder());
136136

137137
RETURN_BOOL (mImage->Fill (Color
138-
((uint8) args[0]->Int32Value(),
139-
(uint8) args[1]->Int32Value(),
140-
(uint8) args[2]->Int32Value(),
141-
(uint8) args[3]->Int32Value())));
138+
((uint8) INT32_VALUE (args[0]),
139+
(uint8) INT32_VALUE (args[1]),
140+
(uint8) INT32_VALUE (args[2]),
141+
(uint8) INT32_VALUE (args[3]))));
142142
}
143143

144144
////////////////////////////////////////////////////////////////////////////////
@@ -151,7 +151,7 @@ void ImageWrap::Swap (const FunctionCallbackInfo<Value>& args)
151151
if (!args[0]->IsString())
152152
THROW (Type, "Invalid arguments");
153153

154-
String::Utf8Value value (args[0]);
154+
UTF8_VAR (value, args[0]);
155155
auto swap = *value ? *value : "";
156156
RETURN_BOOL (mImage->Swap (swap));
157157
}
@@ -167,8 +167,8 @@ void ImageWrap::Flip (const FunctionCallbackInfo<Value>& args)
167167
!args[1]->IsBoolean())
168168
THROW (Type, "Invalid arguments");
169169

170-
bool h = args[0]->BooleanValue();
171-
bool v = args[1]->BooleanValue();
170+
bool h = BOOLEAN_VALUE (args[0]);
171+
bool v = BOOLEAN_VALUE (args[1]);
172172
RETURN_BOOL (mImage->Flip (h, v));
173173
}
174174

@@ -178,7 +178,7 @@ void ImageWrap::Equals (const FunctionCallbackInfo<Value>& args)
178178
{
179179
ISOLATE;
180180
auto* wrapper1 = ObjectWrap::Unwrap<ImageWrap> (args .Holder());
181-
auto* wrapper2 = ObjectWrap::Unwrap<ImageWrap> (args[0]->ToObject());
181+
auto* wrapper2 = ObjectWrap::Unwrap<ImageWrap> (TO_OBJECT (args[0]));
182182
RETURN_BOOL (wrapper1->mImage == wrapper2->mImage);
183183
}
184184

@@ -201,13 +201,13 @@ void ImageWrap::New (const FunctionCallbackInfo<Value>& args)
201201
{
202202
// Normalize the size argument
203203
auto s = NEW_INSTANCE(
204+
Local<Function>::New(isolate, JsSize),
204205
Local<Function>::New (isolate, JsSize),
205-
2, (_jsArgs[0] = args[0],
206-
_jsArgs[1] = args[1], _jsArgs));
206+
_jsArgs[1] = args[1], _jsArgs));
207207

208208
wrapper->mImage.Create
209-
((uint16) s->Get (NEW_STR ("w"))->Int32Value(),
210-
(uint16) s->Get (NEW_STR ("h"))->Int32Value());
209+
(INT32_VALUE ((uint16) OBJECT_GET (s, NEW_STR ("w"))),
210+
INT32_VALUE ((uint16) OBJECT_GET (s, NEW_STR ("h"))));
211211
}
212212

213213
REGISTER_ROBOT_TYPE;
@@ -226,7 +226,7 @@ void ImageWrap::New (const FunctionCallbackInfo<Value>& args)
226226

227227
////////////////////////////////////////////////////////////////////////////////
228228

229-
void ImageWrap::Initialize (Handle<Object> exports)
229+
void ImageWrap::Initialize (Local<Object> exports)
230230
{
231231
// Get the current isolated V8 instance
232232
Isolate* isolate = Isolate::GetCurrent();
@@ -256,7 +256,6 @@ void ImageWrap::Initialize (Handle<Object> exports)
256256
NODE_SET_PROTOTYPE_METHOD (tpl, "_equals", Equals );
257257

258258
// Assign function template to our class creator
259-
constructor.Reset (isolate, tpl->GetFunction());
260-
exports->Set
261-
(NEW_STR ("Image"), tpl->GetFunction());
259+
constructor.Reset (isolate, GET_FUNCTION (tpl));
260+
OBJECT_SET (exports, NEW_STR ("Image"), GET_FUNCTION (tpl));
262261
}

src/NodeImage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class ImageWrap : public ObjectWrap
4949
static void New (const FunctionCallbackInfo<Value>& args);
5050

5151
public:
52-
static void Initialize (Handle<Object> exports);
52+
static void Initialize (Local<Object> exports);
5353

5454
public:
5555
Image mImage;

src/NodeKeyboard.cc

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ void KeyboardWrap::Click (const FunctionCallbackInfo<Value>& args)
2626
{
2727
ISOWRAP (Keyboard, args.Holder());
2828

29-
mKeyboard->AutoDelay.Min = args[1]->Int32Value();
30-
mKeyboard->AutoDelay.Max = args[2]->Int32Value();
29+
mKeyboard->AutoDelay.Min = INT32_VALUE (args[1]);
30+
mKeyboard->AutoDelay.Max = INT32_VALUE (args[2]);
3131
if (args[0]->IsInt32())
32-
mKeyboard->Click ((Key) args[0]->Int32Value());
32+
mKeyboard->Click ((Key) INT32_VALUE (args[0]));
3333

3434
else
3535
{
3636
// Args should be string
3737
if (!args[0]->IsString())
3838
THROW (Type, "Invalid arguments");
3939

40-
String::Utf8Value value (args[0]);
40+
UTF8_VAR (value, args[0]);
4141
auto keys = *value ? *value : "";
4242
// Perform a series of keycode actions
4343
RETURN_BOOL (mKeyboard->Click (keys));
@@ -54,9 +54,9 @@ void KeyboardWrap::Press (const FunctionCallbackInfo<Value>& args)
5454
if (!args[0]->IsInt32())
5555
THROW (Type, "Invalid arguments");
5656

57-
mKeyboard->AutoDelay.Min = args[1]->Int32Value();
58-
mKeyboard->AutoDelay.Max = args[2]->Int32Value();
59-
mKeyboard->Press ((Key) args[0]->Int32Value());
57+
mKeyboard->AutoDelay.Min = INT32_VALUE (args[1]);
58+
mKeyboard->AutoDelay.Max = INT32_VALUE (args[2]);
59+
mKeyboard->Press ((Key) INT32_VALUE (args[0]));
6060
}
6161

6262
////////////////////////////////////////////////////////////////////////////////
@@ -69,9 +69,9 @@ void KeyboardWrap::Release (const FunctionCallbackInfo<Value>& args)
6969
if (!args[0]->IsInt32())
7070
THROW (Type, "Invalid arguments");
7171

72-
mKeyboard->AutoDelay.Min = args[1]->Int32Value();
73-
mKeyboard->AutoDelay.Max = args[2]->Int32Value();
74-
mKeyboard->Release ((Key) args[0]->Int32Value());
72+
mKeyboard->AutoDelay.Min = INT32_VALUE (args[1]);
73+
mKeyboard->AutoDelay.Max = INT32_VALUE (args[2]);
74+
mKeyboard->Release ((Key) INT32_VALUE (args[0]));
7575
}
7676

7777
////////////////////////////////////////////////////////////////////////////////
@@ -84,7 +84,7 @@ void KeyboardWrap::Compile (const FunctionCallbackInfo<Value>& args)
8484
if (!args[0]->IsString())
8585
THROW (Type, "Invalid arguments");
8686

87-
String::Utf8Value value (args[0]);
87+
UTF8_VAR (value, args[0]);
8888
auto keys = *value ? *value : "";
8989

9090
KeyList list;
@@ -97,9 +97,9 @@ void KeyboardWrap::Compile (const FunctionCallbackInfo<Value>& args)
9797
for (int i = 0; i < length; ++i)
9898
{
9999
auto obj = NEW_OBJ;
100-
obj->Set (NEW_STR ("down"), NEW_BOOL (list[i].first ));
101-
obj->Set (NEW_STR ("key" ), NEW_INT (list[i].second));
102-
res->Set (i, obj);
100+
OBJECT_SET (obj, NEW_STR ("down"), NEW_BOOL (list[i].first ));
101+
OBJECT_SET (obj, NEW_STR ("key" ), NEW_INT (list[i].second));
102+
OBJECT_SET (res, i, obj);
103103
}
104104

105105
RETURN (res);
@@ -123,7 +123,7 @@ void KeyboardWrap::GetState (const FunctionCallbackInfo<Value>& args)
123123
{
124124
// Loop every state and add it to resulting object
125125
for (auto i = state.begin(); i != state.end(); ++i)
126-
res->Set (NEW_INT (i->first), NEW_BOOL (i->second));
126+
OBJECT_SET (res, NEW_INT (i->first), NEW_BOOL (i->second));
127127
}
128128

129129
RETURN (res);
@@ -134,7 +134,7 @@ void KeyboardWrap::GetState (const FunctionCallbackInfo<Value>& args)
134134
{
135135
RETURN_BOOL (Keyboard::GetState
136136
// Get info about a single key
137-
((Key) args[0]->Int32Value()));
137+
((Key) INT32_VALUE (args[0])));
138138
}
139139

140140
THROW (Type, "Invalid arguments");
@@ -149,7 +149,7 @@ void KeyboardWrap::New (const FunctionCallbackInfo<Value>& args)
149149
if (args.IsConstructCall())
150150
{
151151
(new KeyboardWrap())->Wrap (args.This());
152-
args.This()->Set (NEW_STR ("autoDelay"),
152+
OBJECT_SET (args.This(), NEW_STR ("autoDelay"),
153153
NEW_RANGE ( 40, 90));
154154

155155
REGISTER_ROBOT_TYPE;
@@ -166,7 +166,7 @@ void KeyboardWrap::New (const FunctionCallbackInfo<Value>& args)
166166

167167
////////////////////////////////////////////////////////////////////////////////
168168

169-
void KeyboardWrap::Initialize (Handle<Object> exports)
169+
void KeyboardWrap::Initialize (Local<Object> exports)
170170
{
171171
// Get the current isolated V8 instance
172172
Isolate* isolate = Isolate::GetCurrent();
@@ -184,7 +184,6 @@ void KeyboardWrap::Initialize (Handle<Object> exports)
184184
NODE_SET_METHOD ((Local<Template>) tpl, "getState", GetState);
185185

186186
// Assign function template to our class creator
187-
constructor.Reset (isolate, tpl->GetFunction());
188-
exports->Set
189-
(NEW_STR ("Keyboard"), tpl->GetFunction());
187+
constructor.Reset (isolate, GET_FUNCTION (tpl));
188+
OBJECT_SET (exports, NEW_STR ("Keyboard"), GET_FUNCTION (tpl));
190189
}

src/NodeKeyboard.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class KeyboardWrap : public ObjectWrap
3737
static void New (const FunctionCallbackInfo<Value>& args);
3838

3939
public:
40-
static void Initialize (Handle<Object> exports);
40+
static void Initialize (Local<Object> exports);
4141

4242
public:
4343
Keyboard mKeyboard;

0 commit comments

Comments
 (0)