Skip to content

Commit 368467a

Browse files
committed
Build for Node 12 / Electron 6
1 parent a77999e commit 368467a

20 files changed

+462
-437
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: 63 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,26 @@ ROBOT_NS_USE_ALL;
4747

4848
////////////////////////////////////////////////////////////////////////////////
4949

50+
#if NODE_MODULE_VERSION >= 46
51+
52+
#define NEW_INSTANCE( f, argc, argv ) f->NewInstance(v8::Context::New(isolate), argc, argv).ToLocalChecked()
53+
54+
#else
55+
56+
#define NEW_INSTANCE( f, argc, argv ) f->NewInstance(argc, argv)
57+
58+
#endif
59+
60+
////////////////////////////////////////////////////////////////////////////////
61+
5062
#define NEW_INT( value ) Integer::New (isolate, value )
5163
#define NEW_NUM( value ) Number ::New (isolate, value )
5264
#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
5368
#define NEW_STR( value ) String ::NewFromUtf8 (isolate, value )
69+
#endif
5470
#define NEW_OBJ Object ::New (isolate )
5571
#define NEW_ARR( length) Array ::New (isolate, length)
5672
#define NEW_NULL Null (isolate )
@@ -64,32 +80,28 @@ ROBOT_NS_USE_ALL;
6480
_jsArgs[1] = NEW_INT (g), \
6581
_jsArgs[2] = NEW_INT (b), \
6682
_jsArgs[3] = NEW_INT (a), \
67-
Local<Function>::New \
68-
(isolate, JsColor)->NewInstance (4, _jsArgs) \
83+
NEW_INSTANCE(Local<Function>::New(isolate, JsColor), 4, _jsArgs) \
6984
)
7085

7186
#define NEW_RANGE( min, max ) \
7287
( \
7388
_jsArgs[0] = NEW_INT (min), \
7489
_jsArgs[1] = NEW_INT (max), \
75-
Local<Function>::New \
76-
(isolate, JsRange)->NewInstance (2, _jsArgs) \
90+
NEW_INSTANCE(Local<Function>::New(isolate, JsRange), 2, _jsArgs) \
7791
)
7892

7993
#define NEW_POINT( x, y ) \
8094
( \
8195
_jsArgs[0] = NEW_INT (x), \
8296
_jsArgs[1] = NEW_INT (y), \
83-
Local<Function>::New \
84-
(isolate, JsPoint)->NewInstance (2, _jsArgs) \
97+
NEW_INSTANCE(Local<Function>::New(isolate, JsPoint), 2, _jsArgs) \
8598
)
8699

87100
#define NEW_SIZE( w, h ) \
88101
( \
89102
_jsArgs[0] = NEW_INT (w), \
90103
_jsArgs[1] = NEW_INT (h), \
91-
Local<Function>::New \
92-
(isolate, JsSize)->NewInstance (2, _jsArgs) \
104+
NEW_INSTANCE(Local<Function>::New(isolate, JsSize), 2, _jsArgs) \
93105
)
94106

95107
#define NEW_BOUNDS( x, y, w, h ) \
@@ -98,14 +110,47 @@ ROBOT_NS_USE_ALL;
98110
_jsArgs[1] = NEW_INT (y), \
99111
_jsArgs[2] = NEW_INT (w), \
100112
_jsArgs[3] = NEW_INT (h), \
101-
Local<Function>::New \
102-
(isolate, JsBounds)->NewInstance (4, _jsArgs) \
113+
NEW_INSTANCE(Local<Function>::New(isolate, JsBounds), 4, _jsArgs) \
103114
)
104115

105-
#define NEW_MODULE Local<Function>::New (isolate, JsModule )->NewInstance()
106-
#define NEW_SEGMENT Local<Function>::New (isolate, JsSegment)->NewInstance()
107-
#define NEW_STATS Local<Function>::New (isolate, JsStats )->NewInstance()
108-
#define NEW_REGION Local<Function>::New (isolate, JsRegion )->NewInstance()
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
109154

110155
////////////////////////////////////////////////////////////////////////////////
111156

@@ -212,7 +257,7 @@ enum RobotType
212257
////////////////////////////////////////////////////////////////////////////////
213258

214259
template <class T>
215-
inline T* UnwrapRobot (Handle<Value> value)
260+
inline T* UnwrapRobot (Local<Value> value)
216261
{
217262
// Get the current isolated V8 instance
218263
Isolate* isolate = Isolate::GetCurrent();
@@ -221,30 +266,16 @@ inline T* UnwrapRobot (Handle<Value> value)
221266
if (!value->IsObject()) return nullptr;
222267

223268
// Retrieve the local object
224-
auto obj = value->ToObject();
225-
226-
#if NODE_MODULE_VERSION >= 48
227-
228-
auto context = isolate->GetCurrentContext();
229-
auto privateKeyValue = Private::ForApi
230-
(isolate, NEW_STR ("_ROBOT_TYPE"));
231-
232-
auto type = obj->GetPrivate (context,
233-
privateKeyValue).ToLocalChecked();
234-
235-
#else
269+
auto obj = TO_OBJECT (value);
236270

237271
// Convert and get hidden type
238-
auto type = obj->GetHiddenValue
239-
(NEW_STR ("_ROBOT_TYPE"));
240-
241-
#endif
272+
auto type = GET_PRIVATE (obj, "_ROBOT_TYPE");
242273

243274
// The value must contain a handle
244275
if (type.IsEmpty()) return nullptr;
245276

246277
// Compare hidden type with class type
247-
if (type->Int32Value() != T::ClassType)
278+
if (INT32_VALUE (type) != T::ClassType)
248279
return nullptr;
249280

250281
// Return the final unwrapped class

src/NodeImage.cc

Lines changed: 28 additions & 29 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

@@ -200,14 +200,14 @@ void ImageWrap::New (const FunctionCallbackInfo<Value>& args)
200200
else
201201
{
202202
// Normalize the size argument
203-
auto s = Local<Function>::New
204-
(isolate, JsSize)->NewInstance
205-
(2, (_jsArgs[0] = args[0],
206-
_jsArgs[1] = args[1], _jsArgs));
203+
auto s = NEW_INSTANCE(
204+
Local<Function>::New(isolate, JsSize),
205+
2, (_jsArgs[0] = args[0],
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;
@@ -218,15 +218,15 @@ void ImageWrap::New (const FunctionCallbackInfo<Value>& args)
218218
{
219219
auto ctor = NEW_CTOR (Image);
220220
// Return as a new instance
221-
RETURN (ctor->NewInstance (2,
221+
RETURN (NEW_INSTANCE(ctor, 2,
222222
(_jsArgs[0] = args[0],
223223
_jsArgs[1] = args[1], _jsArgs)));
224224
}
225225
}
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;

0 commit comments

Comments
 (0)