Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit f425ac6

Browse files
authored
fix breaking change issue for node 10 (#729)
1 parent 370c13e commit f425ac6

File tree

2 files changed

+58
-11
lines changed

2 files changed

+58
-11
lines changed

vendor/node-usb-native/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@
2929
"chai-as-promised": "^5.1.0",
3030
"chalk": "^1.0.0",
3131
"mocha": "^2.2.5",
32-
"nan": "^2.4.0"
32+
"nan": "^2.12.1"
3333
}
3434
}

vendor/node-usb-native/src/serialport.cpp

+57-10
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ v8::Local<v8::Value> getValueFromObject(v8::Local<v8::Object> options, std::stri
8787
}
8888

8989
int getIntFromObject(v8::Local<v8::Object> options, std::string key) {
90-
return getValueFromObject(options, key)->ToInt32()->Int32Value();
90+
#if NODE_MAJOR_VERSION >= 10
91+
return getValueFromObject(options, key)->ToInt32(v8::Isolate::GetCurrent())->Int32Value();
92+
#else
93+
return getValueFromObject(options, key)->ToInt32()->Int32Value();
94+
#endif
9195
}
9296

9397
bool getBoolFromObject(v8::Local<v8::Object> options, std::string key) {
@@ -99,7 +103,11 @@ v8::Local<v8::String> getStringFromObj(v8::Local<v8::Object> options, std::strin
99103
}
100104

101105
double getDoubleFromObject(v8::Local<v8::Object> options, std::string key) {
102-
return getValueFromObject(options, key)->ToNumber()->NumberValue();
106+
#if NODE_MAJOR_VERSION >= 10
107+
return getValueFromObject(options, key)->ToNumber(v8::Isolate::GetCurrent())->NumberValue();
108+
#else
109+
return getValueFromObject(options, key)->ToNumber()->NumberValue();
110+
#endif
103111
}
104112

105113
NAN_METHOD(Open) {
@@ -171,7 +179,12 @@ void EIO_AfterOpen(uv_work_t* req) {
171179
argv[0] = Nan::Null();
172180
argv[1] = Nan::New<v8::Int32>(data->result);
173181

174-
int fd = argv[1]->ToInt32()->Int32Value();
182+
int fd;
183+
#if NODE_MAJOR_VERSION >= 10
184+
fd = argv[1]->ToInt32(v8::Isolate::GetCurrent())->Int32Value();
185+
#else
186+
fd = argv[1]->ToInt32()->Int32Value();
187+
#endif
175188
newQForFD(fd);
176189

177190
AfterOpenSuccess(data->result, data->dataCallback, data->disconnectedCallback, data->errorCallback);
@@ -190,7 +203,12 @@ NAN_METHOD(Update) {
190203
Nan::ThrowTypeError("First argument must be an int");
191204
return;
192205
}
193-
int fd = info[0]->ToInt32()->Int32Value();
206+
int fd;
207+
#if NODE_MAJOR_VERSION >= 10
208+
fd = info[0]->ToInt32(v8::Isolate::GetCurrent())->Int32Value();
209+
#else
210+
fd = info[0]->ToInt32()->Int32Value();
211+
#endif
194212

195213
// options
196214
if (!info[1]->IsObject()) {
@@ -214,7 +232,11 @@ NAN_METHOD(Update) {
214232
memset(baton, 0, sizeof(ConnectionOptionsBaton));
215233

216234
baton->fd = fd;
217-
baton->baudRate = Nan::Get(options, Nan::New<v8::String>("baudRate").ToLocalChecked()).ToLocalChecked()->ToInt32()->Int32Value();
235+
#if NODE_MAJOR_VERSION >= 10
236+
baton->baudRate = Nan::Get(options, Nan::New<v8::String>("baudRate").ToLocalChecked()).ToLocalChecked()->ToInt32(v8::Isolate::GetCurrent())->Int32Value();
237+
#else
238+
baton->baudRate = Nan::Get(options, Nan::New<v8::String>("baudRate").ToLocalChecked()).ToLocalChecked()->ToInt32()->Int32Value();
239+
#endif
218240
baton->callback.Reset(info[2].As<v8::Function>());
219241

220242
uv_work_t* req = new uv_work_t();
@@ -249,7 +271,12 @@ NAN_METHOD(Write) {
249271
Nan::ThrowTypeError("First argument must be an int");
250272
return;
251273
}
252-
int fd = info[0]->ToInt32()->Int32Value();
274+
int fd;
275+
#if NODE_MAJOR_VERSION >= 10
276+
fd = info[0]->ToInt32(v8::Isolate::GetCurrent())->Int32Value();
277+
#else
278+
fd = info[0]->ToInt32()->Int32Value();
279+
#endif
253280

254281
// buffer
255282
if (!info[1]->IsObject() || !node::Buffer::HasInstance(info[1])) {
@@ -366,7 +393,12 @@ NAN_METHOD(Close) {
366393

367394
CloseBaton* baton = new CloseBaton();
368395
memset(baton, 0, sizeof(CloseBaton));
369-
baton->fd = info[0]->ToInt32()->Int32Value();
396+
#if NODE_MAJOR_VERSION >= 10
397+
baton->fd = info[0]->ToInt32(v8::Isolate::GetCurrent())->Int32Value();
398+
#else
399+
baton->fd = info[0]->ToInt32()->Int32Value();
400+
#endif
401+
370402
baton->callback.Reset(info[1].As<v8::Function>());
371403

372404
uv_work_t* req = new uv_work_t();
@@ -477,7 +509,12 @@ NAN_METHOD(Flush) {
477509
Nan::ThrowTypeError("First argument must be an int");
478510
return;
479511
}
480-
int fd = info[0]->ToInt32()->Int32Value();
512+
int fd;
513+
#if NODE_MAJOR_VERSION >= 10
514+
fd = info[0]->ToInt32(v8::Isolate::GetCurrent())->Int32Value();
515+
#else
516+
fd = info[0]->ToInt32()->Int32Value();
517+
#endif
481518

482519
// callback
483520
if (!info[1]->IsFunction()) {
@@ -525,7 +562,12 @@ NAN_METHOD(Set) {
525562
Nan::ThrowTypeError("First argument must be an int");
526563
return;
527564
}
528-
int fd = info[0]->ToInt32()->Int32Value();
565+
int fd;
566+
#if NODE_MAJOR_VERSION >= 10
567+
fd = info[0]->ToInt32(v8::Isolate::GetCurrent())->Int32Value();
568+
#else
569+
fd = info[0]->ToInt32()->Int32Value();
570+
#endif
529571

530572
// options
531573
if (!info[1]->IsObject()) {
@@ -582,7 +624,12 @@ NAN_METHOD(Drain) {
582624
Nan::ThrowTypeError("First argument must be an int");
583625
return;
584626
}
585-
int fd = info[0]->ToInt32()->Int32Value();
627+
int fd;
628+
#if NODE_MAJOR_VERSION >= 10
629+
fd = info[0]->ToInt32(v8::Isolate::GetCurrent())->Int32Value();
630+
#else
631+
fd = info[0]->ToInt32()->Int32Value();
632+
#endif
586633

587634
// callback
588635
if (!info[1]->IsFunction()) {

0 commit comments

Comments
 (0)