From 0580bd0c8bc37d46f190bfee93185a62f19911d8 Mon Sep 17 00:00:00 2001 From: Voltrex Date: Tue, 3 Aug 2021 17:44:10 +0430 Subject: [PATCH] lib: use helper for readability Used an extra `checkReusedHandle()` helper function to increase readability. --- lib/internal/js_stream_socket.js | 35 ++++++++++---------------------- 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/lib/internal/js_stream_socket.js b/lib/internal/js_stream_socket.js index fd1294ec9764f9..3717d37b58a2f6 100644 --- a/lib/internal/js_stream_socket.js +++ b/lib/internal/js_stream_socket.js @@ -22,52 +22,39 @@ const kCurrentWriteRequest = Symbol('kCurrentWriteRequest'); const kCurrentShutdownRequest = Symbol('kCurrentShutdownRequest'); const kPendingShutdownRequest = Symbol('kPendingShutdownRequest'); -function isClosing() { - let socket = this[owner_symbol]; +function checkReusedHandle(t) { + let socket = t[owner_symbol]; - if (socket.constructor.name === 'ReusedHandle') { + if (socket.constructor.name === 'ReusedHandle') socket = socket.handle; - } +} + +function isClosing() { + checkReusedHandle(this); return socket.isClosing(); } function onreadstart() { - let socket = this[owner_symbol]; - - if (socket.constructor.name === 'ReusedHandle') { - socket = socket.handle; - } + checkReusedHandle(this); return socket.readStart(); } function onreadstop() { - let socket = this[owner_symbol]; - - if (socket.constructor.name === 'ReusedHandle') { - socket = socket.handle; - } + checkReusedHandle(this); return socket.readStop(); } function onshutdown(req) { - let socket = this[owner_symbol]; - - if (socket.constructor.name === 'ReusedHandle') { - socket = socket.handle; - } + checkReusedHandle(this); return socket.doShutdown(req); } function onwrite(req, bufs) { - let socket = this[owner_symbol]; - - if (socket.constructor.name === 'ReusedHandle') { - socket = socket.handle; - } + checkReusedHandle(this); return socket.doWrite(req, bufs); }