@@ -304,74 +304,44 @@ void WeakReference::DecRef(const FunctionCallbackInfo<Value>& args) {
304
304
v8::Number::New (args.GetIsolate (), weak_ref->reference_count_ ));
305
305
}
306
306
307
- static void GuessHandleType (const FunctionCallbackInfo<Value>& args) {
308
- Environment* env = Environment::GetCurrent (args);
309
- int fd;
310
- if (!args[0 ]->Int32Value (env->context ()).To (&fd)) return ;
311
- CHECK_GE (fd, 0 );
312
-
313
- uv_handle_type t = uv_guess_handle (fd);
307
+ static uint32_t GetUVHandleTypeCode (const uv_handle_type type) {
314
308
// TODO(anonrig): We can use an enum here and then create the array in the
315
309
// binding, which will remove the hard-coding in C++ and JS land.
316
- uint32_t type{0 };
317
310
318
311
// Currently, the return type of this function corresponds to the index of the
319
312
// array defined in the JS land. This is done as an optimization to reduce the
320
313
// string serialization overhead.
321
- switch (t ) {
314
+ switch (type ) {
322
315
case UV_TCP:
323
- type = 0 ;
324
- break ;
316
+ return 0 ;
325
317
case UV_TTY:
326
- type = 1 ;
327
- break ;
318
+ return 1 ;
328
319
case UV_UDP:
329
- type = 2 ;
330
- break ;
320
+ return 2 ;
331
321
case UV_FILE:
332
- type = 3 ;
333
- break ;
322
+ return 3 ;
334
323
case UV_NAMED_PIPE:
335
- type = 4 ;
336
- break ;
324
+ return 4 ;
337
325
case UV_UNKNOWN_HANDLE:
338
- type = 5 ;
339
- break ;
326
+ return 5 ;
340
327
default :
341
328
ABORT ();
342
329
}
330
+ }
331
+
332
+ static void GuessHandleType (const FunctionCallbackInfo<Value>& args) {
333
+ Environment* env = Environment::GetCurrent (args);
334
+ int fd;
335
+ if (!args[0 ]->Int32Value (env->context ()).To (&fd)) return ;
336
+ CHECK_GE (fd, 0 );
343
337
344
- args.GetReturnValue ().Set (type);
338
+ uv_handle_type t = uv_guess_handle (fd);
339
+ args.GetReturnValue ().Set (GetUVHandleTypeCode (t));
345
340
}
346
341
347
342
static uint32_t FastGuessHandleType (Local<Value> receiver, const uint32_t fd) {
348
343
uv_handle_type t = uv_guess_handle (fd);
349
- uint32_t type{0 };
350
-
351
- switch (t) {
352
- case UV_TCP:
353
- type = 0 ;
354
- break ;
355
- case UV_TTY:
356
- type = 1 ;
357
- break ;
358
- case UV_UDP:
359
- type = 2 ;
360
- break ;
361
- case UV_FILE:
362
- type = 3 ;
363
- break ;
364
- case UV_NAMED_PIPE:
365
- type = 4 ;
366
- break ;
367
- case UV_UNKNOWN_HANDLE:
368
- type = 5 ;
369
- break ;
370
- default :
371
- ABORT ();
372
- }
373
-
374
- return type;
344
+ return GetUVHandleTypeCode (t);
375
345
}
376
346
377
347
CFunction fast_guess_handle_type_ (CFunction::Make(FastGuessHandleType));
0 commit comments