From 46d1025add24d8d31e6f956a4c581b916bd8a4cc Mon Sep 17 00:00:00 2001 From: starkewang Date: Fri, 25 May 2018 16:54:24 +0800 Subject: [PATCH] net: use object destructuring PR-URL: https://github.com/nodejs/node/pull/20959 Reviewed-By: Ruben Bridgewater Reviewed-By: Benjamin Gruenbaum Reviewed-By: James M Snell --- lib/net.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/net.js b/lib/net.js index 6eb6ae818f5ae3..809a6f0f14582e 100644 --- a/lib/net.js +++ b/lib/net.js @@ -82,8 +82,7 @@ const kLastWriteQueueSize = Symbol('lastWriteQueueSize'); let cluster; let dns; -const errnoException = errors.errnoException; -const exceptionWithHostPort = errors.exceptionWithHostPort; +const { errnoException, exceptionWithHostPort } = errors; const { kTimeout, @@ -244,7 +243,7 @@ function Socket(options) { options.readable = options.readable || false; options.writable = options.writable || false; - const allowHalfOpen = options.allowHalfOpen; + const { allowHalfOpen } = options; // Prevent the "no-half-open enforcer" from being inherited from `Duplex`. options.allowHalfOpen = true; @@ -259,7 +258,7 @@ function Socket(options) { this._handle = options.handle; // private this[async_id_symbol] = getNewAsyncId(this._handle); } else if (options.fd !== undefined) { - const fd = options.fd; + const { fd } = options; this._handle = createHandle(fd, false); this._handle.open(fd); this[async_id_symbol] = this._handle.getAsyncId(); @@ -434,7 +433,7 @@ Socket.prototype._onTimeout = function() { if (lastWriteQueueSize > 0 && handle) { // `lastWriteQueueSize !== writeQueueSize` means there is // an active write in progress, so we suppress the timeout. - const writeQueueSize = handle.writeQueueSize; + const { writeQueueSize } = handle; if (lastWriteQueueSize !== writeQueueSize) { this[kLastWriteQueueSize] = writeQueueSize; this._unrefTimer(); @@ -956,7 +955,7 @@ Socket.prototype.connect = function(...args) { this._sockname = null; } - const path = options.path; + const { path } = options; var pipe = !!path; debug('pipe', pipe, path); @@ -991,10 +990,8 @@ Socket.prototype.connect = function(...args) { function lookupAndConnect(self, options) { + var { port, localAddress, localPort } = options; var host = options.host || 'localhost'; - var port = options.port; - var localAddress = options.localAddress; - var localPort = options.localPort; if (localAddress && !isIP(localAddress)) { throw new ERR_INVALID_IP_ADDRESS(localAddress);