GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/../src/udp_wrap.cc Lines: 252 261 96.6 %
Date: 2019-08-17 22:35:23 Branches: 101 171 59.1 %

Line Branch Exec Source
1
// Copyright Joyent, Inc. and other Node contributors.
2
//
3
// Permission is hereby granted, free of charge, to any person obtaining a
4
// copy of this software and associated documentation files (the
5
// "Software"), to deal in the Software without restriction, including
6
// without limitation the rights to use, copy, modify, merge, publish,
7
// distribute, sublicense, and/or sell copies of the Software, and to permit
8
// persons to whom the Software is furnished to do so, subject to the
9
// following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included
12
// in all copies or substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22
#include "udp_wrap.h"
23
#include "env-inl.h"
24
#include "node_buffer.h"
25
#include "handle_wrap.h"
26
#include "req_wrap-inl.h"
27
#include "util-inl.h"
28
29
namespace node {
30
31
using v8::Array;
32
using v8::Context;
33
using v8::DontDelete;
34
using v8::FunctionCallbackInfo;
35
using v8::FunctionTemplate;
36
using v8::HandleScope;
37
using v8::Integer;
38
using v8::Local;
39
using v8::MaybeLocal;
40
using v8::Object;
41
using v8::PropertyAttribute;
42
using v8::ReadOnly;
43
using v8::Signature;
44
using v8::String;
45
using v8::Uint32;
46
using v8::Undefined;
47
using v8::Value;
48
49
15782
class SendWrap : public ReqWrap<uv_udp_send_t> {
50
 public:
51
  SendWrap(Environment* env, Local<Object> req_wrap_obj, bool have_callback);
52
  inline bool have_callback() const;
53
  size_t msg_size;
54
55
1
  SET_NO_MEMORY_INFO()
56
1
  SET_MEMORY_INFO_NAME(SendWrap)
57
1
  SET_SELF_SIZE(SendWrap)
58
59
 private:
60
  const bool have_callback_;
61
};
62
63
64
7895
SendWrap::SendWrap(Environment* env,
65
                   Local<Object> req_wrap_obj,
66
                   bool have_callback)
67
    : ReqWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_UDPSENDWRAP),
68
7895
      have_callback_(have_callback) {
69
7895
}
70
71
72
7891
inline bool SendWrap::have_callback() const {
73
7891
  return have_callback_;
74
}
75
76
77
243
UDPWrap::UDPWrap(Environment* env, Local<Object> object)
78
    : HandleWrap(env,
79
                 object,
80
                 reinterpret_cast<uv_handle_t*>(&handle_),
81
243
                 AsyncWrap::PROVIDER_UDPWRAP) {
82
243
  int r = uv_udp_init(env->event_loop(), &handle_);
83
243
  CHECK_EQ(r, 0);  // can't fail anyway
84
243
}
85
86
87
4411
void UDPWrap::Initialize(Local<Object> target,
88
                         Local<Value> unused,
89
                         Local<Context> context,
90
                         void* priv) {
91
4411
  Environment* env = Environment::GetCurrent(context);
92
93
4411
  Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
94
8822
  t->InstanceTemplate()->SetInternalFieldCount(1);
95
  Local<String> udpString =
96
4411
      FIXED_ONE_BYTE_STRING(env->isolate(), "UDP");
97
4411
  t->SetClassName(udpString);
98
99
  enum PropertyAttribute attributes =
100
4411
      static_cast<PropertyAttribute>(ReadOnly | DontDelete);
101
102
4411
  Local<Signature> signature = Signature::New(env->isolate(), t);
103
104
  Local<FunctionTemplate> get_fd_templ =
105
      FunctionTemplate::New(env->isolate(),
106
                            UDPWrap::GetFD,
107
                            env->as_callback_data(),
108
8822
                            signature);
109
110
13233
  t->PrototypeTemplate()->SetAccessorProperty(env->fd_string(),
111
                                              get_fd_templ,
112
                                              Local<FunctionTemplate>(),
113
13233
                                              attributes);
114
115
4411
  env->SetProtoMethod(t, "open", Open);
116
4411
  env->SetProtoMethod(t, "bind", Bind);
117
4411
  env->SetProtoMethod(t, "connect", Connect);
118
4411
  env->SetProtoMethod(t, "send", Send);
119
4411
  env->SetProtoMethod(t, "bind6", Bind6);
120
4411
  env->SetProtoMethod(t, "connect6", Connect6);
121
4411
  env->SetProtoMethod(t, "send6", Send6);
122
4411
  env->SetProtoMethod(t, "disconnect", Disconnect);
123
4411
  env->SetProtoMethod(t, "recvStart", RecvStart);
124
4411
  env->SetProtoMethod(t, "recvStop", RecvStop);
125
  env->SetProtoMethod(t, "getpeername",
126
4411
                      GetSockOrPeerName<UDPWrap, uv_udp_getpeername>);
127
  env->SetProtoMethod(t, "getsockname",
128
4411
                      GetSockOrPeerName<UDPWrap, uv_udp_getsockname>);
129
4411
  env->SetProtoMethod(t, "addMembership", AddMembership);
130
4411
  env->SetProtoMethod(t, "dropMembership", DropMembership);
131
4411
  env->SetProtoMethod(t, "setMulticastInterface", SetMulticastInterface);
132
4411
  env->SetProtoMethod(t, "setMulticastTTL", SetMulticastTTL);
133
4411
  env->SetProtoMethod(t, "setMulticastLoopback", SetMulticastLoopback);
134
4411
  env->SetProtoMethod(t, "setBroadcast", SetBroadcast);
135
4411
  env->SetProtoMethod(t, "setTTL", SetTTL);
136
4411
  env->SetProtoMethod(t, "bufferSize", BufferSize);
137
138
8822
  t->Inherit(HandleWrap::GetConstructorTemplate(env));
139
140
  target->Set(env->context(),
141
              udpString,
142
22055
              t->GetFunction(env->context()).ToLocalChecked()).Check();
143
  env->set_udp_constructor_function(
144
13233
      t->GetFunction(env->context()).ToLocalChecked());
145
146
  // Create FunctionTemplate for SendWrap
147
  Local<FunctionTemplate> swt =
148
4411
      BaseObject::MakeLazilyInitializedJSTemplate(env);
149
8822
  swt->Inherit(AsyncWrap::GetConstructorTemplate(env));
150
  Local<String> sendWrapString =
151
4411
      FIXED_ONE_BYTE_STRING(env->isolate(), "SendWrap");
152
4411
  swt->SetClassName(sendWrapString);
153
  target->Set(env->context(),
154
              sendWrapString,
155
22055
              swt->GetFunction(env->context()).ToLocalChecked()).Check();
156
157
4411
  Local<Object> constants = Object::New(env->isolate());
158
17644
  NODE_DEFINE_CONSTANT(constants, UV_UDP_IPV6ONLY);
159
  target->Set(context,
160
              env->constants_string(),
161
13233
              constants).Check();
162
4411
}
163
164
165
243
void UDPWrap::New(const FunctionCallbackInfo<Value>& args) {
166
243
  CHECK(args.IsConstructCall());
167
243
  Environment* env = Environment::GetCurrent(args);
168
243
  new UDPWrap(env, args.This());
169
243
}
170
171
172
21
void UDPWrap::GetFD(const FunctionCallbackInfo<Value>& args) {
173
21
  int fd = UV_EBADF;
174
#if !defined(_WIN32)
175
21
  UDPWrap* wrap = Unwrap<UDPWrap>(args.This());
176
21
  if (wrap != nullptr)
177
20
    uv_fileno(reinterpret_cast<uv_handle_t*>(&wrap->handle_), &fd);
178
#endif
179
63
  args.GetReturnValue().Set(fd);
180
21
}
181
182
8028
int sockaddr_for_family(int address_family,
183
                        const char* address,
184
                        const unsigned short port,
185
                        struct sockaddr_storage* addr) {
186
8028
  switch (address_family) {
187
  case AF_INET:
188
8011
    return uv_ip4_addr(address, port, reinterpret_cast<sockaddr_in*>(addr));
189
  case AF_INET6:
190
17
    return uv_ip6_addr(address, port, reinterpret_cast<sockaddr_in6*>(addr));
191
  default:
192
    CHECK(0 && "unexpected address family");
193
  }
194
}
195
196
135
void UDPWrap::DoBind(const FunctionCallbackInfo<Value>& args, int family) {
197
  UDPWrap* wrap;
198
135
  ASSIGN_OR_RETURN_UNWRAP(&wrap,
199
                          args.Holder(),
200
                          args.GetReturnValue().Set(UV_EBADF));
201
202
  // bind(ip, port, flags)
203
135
  CHECK_EQ(args.Length(), 3);
204
205
135
  node::Utf8Value address(args.GetIsolate(), args[0]);
206
135
  Local<Context> ctx = args.GetIsolate()->GetCurrentContext();
207
  uint32_t port, flags;
208


945
  if (!args[1]->Uint32Value(ctx).To(&port) ||
209

540
      !args[2]->Uint32Value(ctx).To(&flags))
210
    return;
211
  struct sockaddr_storage addr_storage;
212
135
  int err = sockaddr_for_family(family, address.out(), port, &addr_storage);
213
135
  if (err == 0) {
214
    err = uv_udp_bind(&wrap->handle_,
215
                      reinterpret_cast<const sockaddr*>(&addr_storage),
216
134
                      flags);
217
  }
218
219
270
  args.GetReturnValue().Set(err);
220
}
221
222
223
14
void UDPWrap::DoConnect(const FunctionCallbackInfo<Value>& args, int family) {
224
  UDPWrap* wrap;
225
14
  ASSIGN_OR_RETURN_UNWRAP(&wrap,
226
                          args.Holder(),
227
                          args.GetReturnValue().Set(UV_EBADF));
228
229
14
  CHECK_EQ(args.Length(), 2);
230
231
14
  node::Utf8Value address(args.GetIsolate(), args[0]);
232
14
  Local<Context> ctx = args.GetIsolate()->GetCurrentContext();
233
  uint32_t port;
234
42
  if (!args[1]->Uint32Value(ctx).To(&port))
235
    return;
236
  struct sockaddr_storage addr_storage;
237
14
  int err = sockaddr_for_family(family, address.out(), port, &addr_storage);
238
14
  if (err == 0) {
239
    err = uv_udp_connect(&wrap->handle_,
240
14
                         reinterpret_cast<const sockaddr*>(&addr_storage));
241
  }
242
243
28
  args.GetReturnValue().Set(err);
244
}
245
246
247
6
void UDPWrap::Open(const FunctionCallbackInfo<Value>& args) {
248
  UDPWrap* wrap;
249
12
  ASSIGN_OR_RETURN_UNWRAP(&wrap,
250
                          args.Holder(),
251
                          args.GetReturnValue().Set(UV_EBADF));
252
12
  CHECK(args[0]->IsNumber());
253
18
  int fd = static_cast<int>(args[0].As<Integer>()->Value());
254
6
  int err = uv_udp_open(&wrap->handle_, fd);
255
256
12
  args.GetReturnValue().Set(err);
257
}
258
259
260
124
void UDPWrap::Bind(const FunctionCallbackInfo<Value>& args) {
261
124
  DoBind(args, AF_INET);
262
124
}
263
264
265
11
void UDPWrap::Bind6(const FunctionCallbackInfo<Value>& args) {
266
11
  DoBind(args, AF_INET6);
267
11
}
268
269
270
30
void UDPWrap::BufferSize(const FunctionCallbackInfo<Value>& args) {
271
30
  Environment* env = Environment::GetCurrent(args);
272
  UDPWrap* wrap;
273
36
  ASSIGN_OR_RETURN_UNWRAP(&wrap,
274
                          args.Holder(),
275
                          args.GetReturnValue().Set(UV_EBADF));
276
277
60
  CHECK(args[0]->IsUint32());
278
60
  CHECK(args[1]->IsBoolean());
279
90
  bool is_recv = args[1].As<v8::Boolean>()->Value();
280
  const char* uv_func_name = is_recv ? "uv_recv_buffer_size" :
281
30
                                       "uv_send_buffer_size";
282
283
60
  if (!args[0]->IsInt32()) {
284
2
    env->CollectUVExceptionInfo(args[2], UV_EINVAL, uv_func_name);
285
4
    return args.GetReturnValue().SetUndefined();
286
  }
287
288
28
  uv_handle_t* handle = reinterpret_cast<uv_handle_t*>(&wrap->handle_);
289
84
  int size = static_cast<int>(args[0].As<Uint32>()->Value());
290
  int err;
291
292
28
  if (is_recv)
293
15
    err = uv_recv_buffer_size(handle, &size);
294
  else
295
13
    err = uv_send_buffer_size(handle, &size);
296
297
28
  if (err != 0) {
298
4
    env->CollectUVExceptionInfo(args[2], err, uv_func_name);
299
8
    return args.GetReturnValue().SetUndefined();
300
  }
301
302
72
  args.GetReturnValue().Set(size);
303
}
304
305
306
14
void UDPWrap::Connect(const FunctionCallbackInfo<Value>& args) {
307
14
  DoConnect(args, AF_INET);
308
14
}
309
310
311
void UDPWrap::Connect6(const FunctionCallbackInfo<Value>& args) {
312
  DoConnect(args, AF_INET6);
313
}
314
315
316
1
void UDPWrap::Disconnect(const FunctionCallbackInfo<Value>& args) {
317
  UDPWrap* wrap;
318
2
  ASSIGN_OR_RETURN_UNWRAP(&wrap,
319
                          args.Holder(),
320
                          args.GetReturnValue().Set(UV_EBADF));
321
322
1
  CHECK_EQ(args.Length(), 0);
323
324
1
  int err = uv_udp_connect(&wrap->handle_, nullptr);
325
326
2
  args.GetReturnValue().Set(err);
327
}
328
329
#define X(name, fn)                                                            \
330
  void UDPWrap::name(const FunctionCallbackInfo<Value>& args) {                \
331
    UDPWrap* wrap = Unwrap<UDPWrap>(args.Holder());                            \
332
    Environment* env = wrap->env();                                            \
333
    CHECK_EQ(args.Length(), 1);                                                \
334
    int flag;                                                                  \
335
    if (!args[0]->Int32Value(env->context()).To(&flag)) {                      \
336
      return;                                                                  \
337
    }                                                                          \
338
    int err = wrap == nullptr ? UV_EBADF : fn(&wrap->handle_, flag);           \
339
    args.GetReturnValue().Set(err);                                            \
340
  }
341
342

24
X(SetTTL, uv_udp_set_ttl)
343

40
X(SetBroadcast, uv_udp_set_broadcast)
344

24
X(SetMulticastTTL, uv_udp_set_multicast_ttl)
345

32
X(SetMulticastLoopback, uv_udp_set_multicast_loop)
346
347
#undef X
348
349
9
void UDPWrap::SetMulticastInterface(const FunctionCallbackInfo<Value>& args) {
350
  UDPWrap* wrap;
351
18
  ASSIGN_OR_RETURN_UNWRAP(&wrap,
352
                          args.Holder(),
353
                          args.GetReturnValue().Set(UV_EBADF));
354
355
9
  CHECK_EQ(args.Length(), 1);
356
27
  CHECK(args[0]->IsString());
357
358
9
  Utf8Value iface(args.GetIsolate(), args[0]);
359
360
9
  const char* iface_cstr = *iface;
361
362
9
  int err = uv_udp_set_multicast_interface(&wrap->handle_, iface_cstr);
363
18
  args.GetReturnValue().Set(err);
364
}
365
366
6
void UDPWrap::SetMembership(const FunctionCallbackInfo<Value>& args,
367
                            uv_membership membership) {
368
  UDPWrap* wrap;
369
12
  ASSIGN_OR_RETURN_UNWRAP(&wrap,
370
                          args.Holder(),
371
                          args.GetReturnValue().Set(UV_EBADF));
372
373
6
  CHECK_EQ(args.Length(), 2);
374
375
6
  node::Utf8Value address(args.GetIsolate(), args[0]);
376
12
  node::Utf8Value iface(args.GetIsolate(), args[1]);
377
378
6
  const char* iface_cstr = *iface;
379


24
  if (args[1]->IsUndefined() || args[1]->IsNull()) {
380
6
      iface_cstr = nullptr;
381
  }
382
383
  int err = uv_udp_set_membership(&wrap->handle_,
384
6
                                  *address,
385
                                  iface_cstr,
386
6
                                  membership);
387
18
  args.GetReturnValue().Set(err);
388
}
389
390
391
3
void UDPWrap::AddMembership(const FunctionCallbackInfo<Value>& args) {
392
3
  SetMembership(args, UV_JOIN_GROUP);
393
3
}
394
395
396
3
void UDPWrap::DropMembership(const FunctionCallbackInfo<Value>& args) {
397
3
  SetMembership(args, UV_LEAVE_GROUP);
398
3
}
399
400
401
7895
void UDPWrap::DoSend(const FunctionCallbackInfo<Value>& args, int family) {
402
7895
  Environment* env = Environment::GetCurrent(args);
403
404
  UDPWrap* wrap;
405
15790
  ASSIGN_OR_RETURN_UNWRAP(&wrap,
406
                          args.Holder(),
407
                          args.GetReturnValue().Set(UV_EBADF));
408
409

15774
  CHECK(args.Length() == 4 || args.Length() == 6);
410
15790
  CHECK(args[0]->IsObject());
411
15790
  CHECK(args[1]->IsArray());
412
15790
  CHECK(args[2]->IsUint32());
413
414
7895
  bool sendto = args.Length() == 6;
415
7895
  if (sendto) {
416
    // send(req, list, list.length, port, address, hasCallback)
417
15758
    CHECK(args[3]->IsUint32());
418
23637
    CHECK(args[4]->IsString());
419
15758
    CHECK(args[5]->IsBoolean());
420
  } else {
421
    // send(req, list, list.length, hasCallback)
422
32
    CHECK(args[3]->IsBoolean());
423
  }
424
425
15790
  Local<Object> req_wrap_obj = args[0].As<Object>();
426
15790
  Local<Array> chunks = args[1].As<Array>();
427
  // it is faster to fetch the length of the
428
  // array in js-land
429
23685
  size_t count = args[2].As<Uint32>()->Value();
430

23685
  const bool have_callback = sendto ? args[5]->IsTrue() : args[3]->IsTrue();
431
432
  SendWrap* req_wrap;
433
  {
434
7895
    AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(wrap);
435
7895
    req_wrap = new SendWrap(env, req_wrap_obj, have_callback);
436
  }
437
7895
  size_t msg_size = 0;
438
439
7895
  MaybeStackBuffer<uv_buf_t, 16> bufs(count);
440
441
  // construct uv_buf_t array
442
19579
  for (size_t i = 0; i < count; i++) {
443
35052
    Local<Value> chunk = chunks->Get(env->context(), i).ToLocalChecked();
444
445
11684
    size_t length = Buffer::Length(chunk);
446
447
11684
    bufs[i] = uv_buf_init(Buffer::Data(chunk), length);
448
11684
    msg_size += length;
449
  }
450
451
7895
  req_wrap->msg_size = msg_size;
452
453
7895
  int err = 0;
454
  struct sockaddr_storage addr_storage;
455
7895
  sockaddr* addr = nullptr;
456
7895
  if (sendto) {
457
23637
    const unsigned short port = args[3].As<Uint32>()->Value();
458
7879
    node::Utf8Value address(env->isolate(), args[4]);
459
7879
    err = sockaddr_for_family(family, address.out(), port, &addr_storage);
460
7879
    if (err == 0) {
461
7879
      addr = reinterpret_cast<sockaddr*>(&addr_storage);
462
7879
    }
463
  }
464
465
7895
  if (err == 0) {
466
    err = req_wrap->Dispatch(uv_udp_send,
467
                             &wrap->handle_,
468
                             *bufs,
469
                             count,
470
                             addr,
471
7895
                             OnSend);
472
  }
473
474
7895
  if (err)
475
    delete req_wrap;
476
477
15790
  args.GetReturnValue().Set(err);
478
}
479
480
481
7889
void UDPWrap::Send(const FunctionCallbackInfo<Value>& args) {
482
7889
  DoSend(args, AF_INET);
483
7889
}
484
485
486
6
void UDPWrap::Send6(const FunctionCallbackInfo<Value>& args) {
487
6
  DoSend(args, AF_INET6);
488
6
}
489
490
491
139
void UDPWrap::RecvStart(const FunctionCallbackInfo<Value>& args) {
492
  UDPWrap* wrap;
493
278
  ASSIGN_OR_RETURN_UNWRAP(&wrap,
494
                          args.Holder(),
495
                          args.GetReturnValue().Set(UV_EBADF));
496
139
  int err = uv_udp_recv_start(&wrap->handle_, OnAlloc, OnRecv);
497
  // UV_EALREADY means that the socket is already bound but that's okay
498
139
  if (err == UV_EALREADY)
499
    err = 0;
500
278
  args.GetReturnValue().Set(err);
501
}
502
503
504
123
void UDPWrap::RecvStop(const FunctionCallbackInfo<Value>& args) {
505
  UDPWrap* wrap;
506
246
  ASSIGN_OR_RETURN_UNWRAP(&wrap,
507
                          args.Holder(),
508
                          args.GetReturnValue().Set(UV_EBADF));
509
123
  int r = uv_udp_recv_stop(&wrap->handle_);
510
246
  args.GetReturnValue().Set(r);
511
}
512
513
514
7891
void UDPWrap::OnSend(uv_udp_send_t* req, int status) {
515
7891
  std::unique_ptr<SendWrap> req_wrap{static_cast<SendWrap*>(req->data)};
516
7891
  if (req_wrap->have_callback()) {
517
7635
    Environment* env = req_wrap->env();
518
7635
    HandleScope handle_scope(env->isolate());
519
7635
    Context::Scope context_scope(env->context());
520
    Local<Value> arg[] = {
521
      Integer::New(env->isolate(), status),
522
7635
      Integer::New(env->isolate(), req_wrap->msg_size),
523
30540
    };
524
15270
    req_wrap->MakeCallback(env->oncomplete_string(), 2, arg);
525
7891
  }
526
7891
}
527
528
529
11864
void UDPWrap::OnAlloc(uv_handle_t* handle,
530
                      size_t suggested_size,
531
                      uv_buf_t* buf) {
532
11864
  UDPWrap* wrap = static_cast<UDPWrap*>(handle->data);
533
11864
  *buf = wrap->env()->AllocateManaged(suggested_size).release();
534
11864
}
535
536
11864
void UDPWrap::OnRecv(uv_udp_t* handle,
537
                     ssize_t nread,
538
                     const uv_buf_t* buf_,
539
                     const struct sockaddr* addr,
540
                     unsigned int flags) {
541
11864
  UDPWrap* wrap = static_cast<UDPWrap*>(handle->data);
542
11864
  Environment* env = wrap->env();
543
544
11864
  AllocatedBuffer buf(env, *buf_);
545

11864
  if (nread == 0 && addr == nullptr) {
546
3998
    return;
547
  }
548
549
15732
  HandleScope handle_scope(env->isolate());
550
15732
  Context::Scope context_scope(env->context());
551
552
7866
  Local<Object> wrap_obj = wrap->object();
553
  Local<Value> argv[] = {
554
    Integer::New(env->isolate(), nread),
555
    wrap_obj,
556
    Undefined(env->isolate()),
557
    Undefined(env->isolate())
558
39330
  };
559
560
7866
  if (nread < 0) {
561
    wrap->MakeCallback(env->onmessage_string(), arraysize(argv), argv);
562
    return;
563
  }
564
565
7866
  buf.Resize(nread);
566
15732
  argv[2] = buf.ToBuffer().ToLocalChecked();
567
15732
  argv[3] = AddressToJS(env, addr);
568
15732
  wrap->MakeCallback(env->onmessage_string(), arraysize(argv), argv);
569
}
570
571
26
MaybeLocal<Object> UDPWrap::Instantiate(Environment* env,
572
                                        AsyncWrap* parent,
573
                                        UDPWrap::SocketType type) {
574
26
  AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(parent);
575
576
  // If this assert fires then Initialize hasn't been called yet.
577
52
  CHECK_EQ(env->udp_constructor_function().IsEmpty(), false);
578
52
  return env->udp_constructor_function()->NewInstance(env->context());
579
}
580
581
582
}  // namespace node
583
584
5015
NODE_MODULE_CONTEXT_AWARE_INTERNAL(udp_wrap, node::UDPWrap::Initialize)