@@ -37,8 +37,12 @@ DtlsSocket::Initialize(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE target) {
37
37
Nan::SetPrototypeMethod (ctor, " close" , Close);
38
38
Nan::SetPrototypeMethod (ctor, " send" , Send);
39
39
Nan::SetPrototypeMethod (ctor, " connect" , Connect);
40
-
41
- Nan::Set (target, Nan::New (" DtlsSocket" ).ToLocalChecked (), ctor->GetFunction ());
40
+
41
+ Nan::Set (
42
+ target,
43
+ Nan::New (" DtlsSocket" ).ToLocalChecked (),
44
+ Nan::GetFunction (ctor).ToLocalChecked ()
45
+ );
42
46
}
43
47
44
48
void DtlsSocket::New (const Nan::FunctionCallbackInfo<v8::Value>& info) {
@@ -58,7 +62,10 @@ void DtlsSocket::New(const Nan::FunctionCallbackInfo<v8::Value>& info) {
58
62
59
63
int debug_level = 0 ;
60
64
if (info.Length () > 7 ) {
61
- debug_level = info[7 ]->Uint32Value ();
65
+ v8::Maybe<uint32_t > debug_level_maybe = info[7 ]->Uint32Value (Nan::GetCurrentContext ());
66
+ if (debug_level_maybe.IsJust ()) {
67
+ debug_level = debug_level_maybe.FromJust ();
68
+ }
62
69
}
63
70
64
71
DtlsSocket *socket = new DtlsSocket (
@@ -78,7 +85,7 @@ void DtlsSocket::ReceiveDataFromNode(const Nan::FunctionCallbackInfo<v8::Value>&
78
85
socket->store_data (recv_data, Buffer::Length (info[0 ]));
79
86
80
87
int len = 1024 ;
81
- unsigned char buf[len];
88
+ unsigned char buf[len];
82
89
len = socket->receive_data (buf, len);
83
90
84
91
if (len > 0 ) {
@@ -99,7 +106,7 @@ void DtlsSocket::Close(const Nan::FunctionCallbackInfo<v8::Value>& info) {
99
106
100
107
void DtlsSocket::Send (const Nan::FunctionCallbackInfo<v8::Value>& info) {
101
108
DtlsSocket *socket = Nan::ObjectWrap::Unwrap<DtlsSocket>(info.This ());
102
-
109
+
103
110
const unsigned char *send_data = (const unsigned char *)Buffer::Data (info[0 ]);
104
111
socket->send (send_data, Buffer::Length (info[0 ]));
105
112
}
@@ -225,7 +232,12 @@ int DtlsSocket::send_encrypted(const unsigned char *buf, size_t len) {
225
232
Nan::CopyBuffer ((char *)buf, len).ToLocalChecked ()
226
233
};
227
234
v8::Local<v8::Function> sendCallbackDirect = send_cb->GetFunction ();
228
- sendCallbackDirect->Call (Nan::GetCurrentContext ()->Global (), 1 , argv);
235
+ Nan::Call (
236
+ sendCallbackDirect,
237
+ Nan::GetCurrentContext ()->Global (),
238
+ 1 ,
239
+ argv
240
+ );
229
241
return len;
230
242
}
231
243
@@ -257,7 +269,7 @@ int DtlsSocket::receive_data(unsigned char *buf, int len) {
257
269
int ret;
258
270
259
271
if (ssl_context.state == MBEDTLS_SSL_HANDSHAKE_OVER) {
260
- // normal reading of unencrypted data
272
+ // normal reading of unencrypted data
261
273
memset (buf, 0 , len);
262
274
ret = mbedtls_ssl_read (&ssl_context, buf, len);
263
275
if (ret <= 0 ) {
@@ -290,7 +302,12 @@ int DtlsSocket::step() {
290
302
291
303
// this should only be called once when we first finish the handshake
292
304
v8::Local<v8::Function> handshakeCallbackDirect = handshake_cb->GetFunction ();
293
- handshakeCallbackDirect->Call (Nan::GetCurrentContext ()->Global (), 0 , NULL );
305
+ Nan::Call (
306
+ handshakeCallbackDirect,
307
+ Nan::GetCurrentContext ()->Global (),
308
+ 0 ,
309
+ NULL
310
+ );
294
311
return 0 ;
295
312
}
296
313
@@ -308,7 +325,12 @@ void DtlsSocket::error(int ret) {
308
325
Nan::New (error_buf).ToLocalChecked ()
309
326
};
310
327
v8::Local<v8::Function> errorCallbackDirect = error_cb->GetFunction ();
311
- errorCallbackDirect->Call (Nan::GetCurrentContext ()->Global (), 2 , argv);
328
+ Nan::Call (
329
+ errorCallbackDirect,
330
+ Nan::GetCurrentContext ()->Global (),
331
+ 2 ,
332
+ argv
333
+ );
312
334
}
313
335
314
336
void DtlsSocket::store_data (const unsigned char *buf, size_t len) {
0 commit comments