@@ -35,7 +35,7 @@ void SetAddress(const Nan::FunctionCallbackInfo<v8::Value>& info) {
35
35
Nan::ThrowTypeError (" addr must be an int" );
36
36
return ;
37
37
}
38
- addr = info[0 ]->Int32Value ();
38
+ addr = info[0 ]->Int32Value (Nan::GetCurrentContext ()). FromJust ( );
39
39
setAddress (addr);
40
40
}
41
41
@@ -57,7 +57,11 @@ void Scan(const Nan::FunctionCallbackInfo<v8::Value>& info) {
57
57
if (res >= 0 ) {
58
58
res = i;
59
59
}
60
- results->Set (i, Nan::New<Integer>(res));
60
+ results->Set (
61
+ Nan::GetCurrentContext (),
62
+ i,
63
+ Nan::New<Integer>(res)
64
+ );
61
65
}
62
66
63
67
setAddress (addr);
@@ -81,7 +85,7 @@ void Close(const Nan::FunctionCallbackInfo<v8::Value>& info) {
81
85
void Open (const Nan::FunctionCallbackInfo<v8::Value>& info) {
82
86
Nan::HandleScope scope;
83
87
84
- String::Utf8Value device (info[0 ]);
88
+ Nan::Utf8String device (info[0 ]);
85
89
Local<Value> err = Nan::New<Value>(Nan::Null ());
86
90
87
91
fd = open (*device, O_RDWR);
@@ -100,7 +104,7 @@ void Open(const Nan::FunctionCallbackInfo<v8::Value>& info) {
100
104
void Read (const Nan::FunctionCallbackInfo<v8::Value>& info) {
101
105
Nan::HandleScope scope;
102
106
103
- int len = info[0 ]->Int32Value ();
107
+ int len = info[0 ]->Int32Value (Nan::GetCurrentContext ()). FromJust ( );
104
108
105
109
Local<Array> data = Nan::New<Array>();
106
110
@@ -111,7 +115,7 @@ void Read(const Nan::FunctionCallbackInfo<v8::Value>& info) {
111
115
err = Nan::Error (Nan::New (" Cannot read from device" ).ToLocalChecked ());
112
116
} else {
113
117
for (int i = 0 ; i < len; ++i) {
114
- data->Set (i, Nan::New<Integer>(buf[i]));
118
+ data->Set (Nan::GetCurrentContext (), i, Nan::New<Integer>(buf[i]));
115
119
}
116
120
}
117
121
delete[] buf;
@@ -151,8 +155,8 @@ void ReadByte(const Nan::FunctionCallbackInfo<v8::Value>& info) {
151
155
void ReadBlock (const Nan::FunctionCallbackInfo<v8::Value>& info) {
152
156
Nan::HandleScope scope;
153
157
154
- int8_t cmd = info[0 ]->Int32Value ();
155
- int32_t len = info[1 ]->Int32Value ();
158
+ int8_t cmd = info[0 ]->Int32Value (Nan::GetCurrentContext ()). FromJust ( );
159
+ int32_t len = info[1 ]->Int32Value (Nan::GetCurrentContext ()). FromJust ( );
156
160
uint8_t data[len];
157
161
Local<Value> err = Nan::New<Value>(Nan::Null ());
158
162
// Local<Object> buffer = node::Buffer::New(len);
@@ -175,7 +179,7 @@ void ReadBlock(const Nan::FunctionCallbackInfo<v8::Value>& info) {
175
179
}
176
180
177
181
if (info[2 ]->IsNumber ()) {
178
- int32_t delay = info[2 ]->Int32Value ();
182
+ int32_t delay = info[2 ]->Int32Value (Nan::GetCurrentContext ()). FromJust ( );
179
183
usleep (delay * 1000 );
180
184
} else {
181
185
break ;
@@ -188,10 +192,11 @@ void ReadBlock(const Nan::FunctionCallbackInfo<v8::Value>& info) {
188
192
void Write (const Nan::FunctionCallbackInfo<v8::Value>& info) {
189
193
Nan::HandleScope scope;
190
194
191
- Local<Value> buffer = info[0 ];
195
+ // v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext();
196
+ auto bufferObj = info[0 ]->ToObject (Nan::GetCurrentContext ()).ToLocalChecked ();
192
197
193
- int len = node::Buffer::Length (buffer-> ToObject () );
194
- char * data = node::Buffer::Data (buffer-> ToObject () );
198
+ int len = node::Buffer::Length (bufferObj );
199
+ char * data = node::Buffer::Data (bufferObj );
195
200
196
201
Local<Value> err = Nan::New<Value>(Nan::Null ());
197
202
@@ -210,7 +215,7 @@ void Write(const Nan::FunctionCallbackInfo<v8::Value>& info) {
210
215
void WriteByte (const Nan::FunctionCallbackInfo<v8::Value>& info) {
211
216
Nan::HandleScope scope;
212
217
213
- int8_t byte = info[0 ]->Int32Value ();
218
+ int8_t byte = info[0 ]->Int32Value (Nan::GetCurrentContext ()). FromJust ( );
214
219
Local<Value> err = Nan::New<Value>(Nan::Null ());
215
220
216
221
if (i2c_smbus_write_byte (fd, byte) == -1 ) {
@@ -228,10 +233,12 @@ void WriteByte(const Nan::FunctionCallbackInfo<v8::Value>& info) {
228
233
void WriteBlock (const Nan::FunctionCallbackInfo<v8::Value>& info) {
229
234
Nan::HandleScope scope;
230
235
231
- Local<Value> buffer = info[1 ];
232
- int8_t cmd = info[0 ]->Int32Value ();
233
- int len = node::Buffer::Length (buffer->ToObject ());
234
- char * data = node::Buffer::Data (buffer->ToObject ());
236
+ v8::Local<v8::Context> context = info.GetIsolate ()->GetCurrentContext ();
237
+ auto bufferObj = info[1 ]->ToObject (context).ToLocalChecked ();
238
+
239
+ int8_t cmd = info[0 ]->Int32Value (Nan::GetCurrentContext ()).FromJust ();
240
+ int len = node::Buffer::Length (bufferObj);
241
+ char * data = node::Buffer::Data (bufferObj);
235
242
236
243
Local<Value> err = Nan::New<Value>(Nan::Null ());
237
244
@@ -250,8 +257,8 @@ void WriteBlock(const Nan::FunctionCallbackInfo<v8::Value>& info) {
250
257
void WriteWord (const Nan::FunctionCallbackInfo<v8::Value>& info) {
251
258
Nan::HandleScope scope;
252
259
253
- int8_t cmd = info[0 ]->Int32Value ();
254
- int16_t word = info[1 ]->Int32Value ();
260
+ int8_t cmd = info[0 ]->Int32Value (Nan::GetCurrentContext ()). FromJust ( );
261
+ int16_t word = info[1 ]->Int32Value (Nan::GetCurrentContext ()). FromJust ( );
255
262
256
263
Local<Value> err = Nan::New<Value>(Nan::Null ());
257
264
@@ -267,29 +274,59 @@ void WriteWord(const Nan::FunctionCallbackInfo<v8::Value>& info) {
267
274
}
268
275
}
269
276
270
- void Init (Handle <Object> exports) {
271
-
272
- exports->Set (Nan::New (" setAddress" ).ToLocalChecked (),
273
- Nan::New<v8::FunctionTemplate>(SetAddress)->GetFunction ());
274
- exports->Set (Nan::New (" scan" ).ToLocalChecked (),
275
- Nan::New<v8::FunctionTemplate>(Scan)->GetFunction ());
276
- exports->Set (Nan::New (" open" ).ToLocalChecked (),
277
- Nan::New<v8::FunctionTemplate>(Open)->GetFunction ());
278
- exports->Set (Nan::New (" close" ).ToLocalChecked (),
279
- Nan::New<v8::FunctionTemplate>(Close)->GetFunction ());
280
- exports->Set (Nan::New (" write" ).ToLocalChecked (),
281
- Nan::New<v8::FunctionTemplate>(Write)->GetFunction ());
282
- exports->Set (Nan::New (" writeByte" ).ToLocalChecked (),
283
- Nan::New<v8::FunctionTemplate>(WriteByte)->GetFunction ());
284
- exports->Set (Nan::New (" writeBlock" ).ToLocalChecked (),
285
- Nan::New<v8::FunctionTemplate>(WriteBlock)->GetFunction ());
286
- exports->Set (Nan::New (" read" ).ToLocalChecked (),
287
- Nan::New<v8::FunctionTemplate>(Read)->GetFunction ());
288
- exports->Set (Nan::New (" readByte" ).ToLocalChecked (),
289
- Nan::New<v8::FunctionTemplate>(ReadByte)->GetFunction ());
290
- exports->Set (Nan::New (" readBlock" ).ToLocalChecked (),
291
- Nan::New<v8::FunctionTemplate>(ReadBlock)->GetFunction ());
277
+ void Init (Local<Object> exports) {
278
+
279
+ exports->Set (
280
+ Nan::GetCurrentContext (),
281
+ Nan::New (" setAddress" ).ToLocalChecked (),
282
+ Nan::New<v8::FunctionTemplate>(SetAddress)->GetFunction (Nan::GetCurrentContext ()).FromMaybe (v8::Local<v8::Function>())
283
+ );
284
+ exports->Set (
285
+ Nan::GetCurrentContext (),
286
+ Nan::New (" scan" ).ToLocalChecked (),
287
+ Nan::New<v8::FunctionTemplate>(Scan)->GetFunction (Nan::GetCurrentContext ()).FromMaybe (v8::Local<v8::Function>())
288
+ );
289
+ exports->Set (
290
+ Nan::GetCurrentContext (),
291
+ Nan::New (" open" ).ToLocalChecked (),
292
+ Nan::New<v8::FunctionTemplate>(Open)->GetFunction (Nan::GetCurrentContext ()).FromMaybe (v8::Local<v8::Function>())
293
+ );
294
+ exports->Set (
295
+ Nan::GetCurrentContext (),
296
+ Nan::New (" close" ).ToLocalChecked (),
297
+ Nan::New<v8::FunctionTemplate>(Close)->GetFunction (Nan::GetCurrentContext ()).FromMaybe (v8::Local<v8::Function>())
298
+ );
299
+ exports->Set (
300
+ Nan::GetCurrentContext (),
301
+ Nan::New (" write" ).ToLocalChecked (),
302
+ Nan::New<v8::FunctionTemplate>(Write)->GetFunction (Nan::GetCurrentContext ()).FromMaybe (v8::Local<v8::Function>())
303
+ );
304
+ exports->Set (
305
+ Nan::GetCurrentContext (),
306
+ Nan::New (" writeByte" ).ToLocalChecked (),
307
+ Nan::New<v8::FunctionTemplate>(WriteByte)->GetFunction (Nan::GetCurrentContext ()).FromMaybe (v8::Local<v8::Function>())
308
+ );
309
+ exports->Set (
310
+ Nan::GetCurrentContext (),
311
+ Nan::New (" writeBlock" ).ToLocalChecked (),
312
+ Nan::New<v8::FunctionTemplate>(WriteBlock)->GetFunction (Nan::GetCurrentContext ()).FromMaybe (v8::Local<v8::Function>())
313
+ );
314
+ exports->Set (
315
+ Nan::GetCurrentContext (),
316
+ Nan::New (" read" ).ToLocalChecked (),
317
+ Nan::New<v8::FunctionTemplate>(Read)->GetFunction (Nan::GetCurrentContext ()).FromMaybe (v8::Local<v8::Function>())
318
+ );
319
+ exports->Set (
320
+ Nan::GetCurrentContext (),
321
+ Nan::New (" readByte" ).ToLocalChecked (),
322
+ Nan::New<v8::FunctionTemplate>(ReadByte)->GetFunction (Nan::GetCurrentContext ()).FromMaybe (v8::Local<v8::Function>())
323
+ );
324
+ exports->Set (
325
+ Nan::GetCurrentContext (),
326
+ Nan::New (" readBlock" ).ToLocalChecked (),
327
+ Nan::New<v8::FunctionTemplate>(ReadBlock)->GetFunction (Nan::GetCurrentContext ()).FromMaybe (v8::Local<v8::Function>())
328
+ );
292
329
293
330
}
294
331
295
- NODE_MODULE (i2c, Init)
332
+ NODE_MODULE (i2c, Init)
0 commit comments