From 9b8bb18a02da5dd9faab66b663044758d099a802 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 | 37 +++++++++++--------------------- 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/lib/internal/js_stream_socket.js b/lib/internal/js_stream_socket.js index fd1294ec9764f9..bd902412564ceb 100644 --- a/lib/internal/js_stream_socket.js +++ b/lib/internal/js_stream_socket.js @@ -22,52 +22,41 @@ const kCurrentWriteRequest = Symbol('kCurrentWriteRequest'); const kCurrentShutdownRequest = Symbol('kCurrentShutdownRequest'); const kPendingShutdownRequest = Symbol('kPendingShutdownRequest'); -function isClosing() { - let socket = this[owner_symbol]; +function checkReusedHandle(self) { + let socket = self[owner_symbol]; - if (socket.constructor.name === 'ReusedHandle') { + if (socket.constructor.name === 'ReusedHandle') socket = socket.handle; - } + + return socket; +} + +function isClosing() { + const socket = checkReusedHandle(this); return socket.isClosing(); } function onreadstart() { - let socket = this[owner_symbol]; - - if (socket.constructor.name === 'ReusedHandle') { - socket = socket.handle; - } + const socket = checkReusedHandle(this); return socket.readStart(); } function onreadstop() { - let socket = this[owner_symbol]; - - if (socket.constructor.name === 'ReusedHandle') { - socket = socket.handle; - } + const socket = checkReusedHandle(this); return socket.readStop(); } function onshutdown(req) { - let socket = this[owner_symbol]; - - if (socket.constructor.name === 'ReusedHandle') { - socket = socket.handle; - } + const socket = checkReusedHandle(this); return socket.doShutdown(req); } function onwrite(req, bufs) { - let socket = this[owner_symbol]; - - if (socket.constructor.name === 'ReusedHandle') { - socket = socket.handle; - } + const socket = checkReusedHandle(this); return socket.doWrite(req, bufs); }