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