From 67da7efaf0418c47573572f4dc15d3d02aebff52 Mon Sep 17 00:00:00 2001 From: nathias Date: Tue, 12 Nov 2019 15:57:50 +0100 Subject: [PATCH] net: replaced vars to lets and consts --- lib/net.js | 88 +++++++++++++++++++++++++++--------------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/lib/net.js b/lib/net.js index c0d2576afc496b..8934f1dd62878e 100644 --- a/lib/net.js +++ b/lib/net.js @@ -150,7 +150,7 @@ function createServer(options, connectionListener) { // Target API: // -// var s = net.connect({port: 80, host: 'google.com'}, function() { +// let s = net.connect({port: 80, host: 'google.com'}, function() { // ... // }); // @@ -185,7 +185,7 @@ function connect(...args) { // For Server.prototype.listen(), the [...] part is [, backlog] // but will not be handled here (handled in listen()) function normalizeArgs(args) { - var arr; + let arr; if (args.length === 0) { arr = [{}, null]; @@ -194,7 +194,7 @@ function normalizeArgs(args) { } const arg0 = args[0]; - var options = {}; + let options = {}; if (typeof arg0 === 'object' && arg0 !== null) { // (options[...][, cb]) options = arg0; @@ -377,7 +377,7 @@ Object.setPrototypeOf(Socket, stream.Duplex); // Refresh existing timeouts. Socket.prototype._unrefTimer = function _unrefTimer() { - for (var s = this; s !== null; s = s._parent) { + for (let s = this; s !== null; s = s._parent) { if (s[kTimeout]) s[kTimeout].refresh(); } @@ -553,7 +553,7 @@ function tryReadStart(socket) { // Not already reading, start the flow debug('Socket._handle.readStart'); socket._handle.reading = true; - var err = socket._handle.readStart(); + const err = socket._handle.readStart(); if (err) socket.destroy(errnoException(err, 'read')); } @@ -641,7 +641,7 @@ Socket.prototype._destroy = function(exception, cb) { this.readable = this.writable = false; - for (var s = this; s !== null; s = s._parent) { + for (let s = this; s !== null; s = s._parent) { clearTimeout(s[kTimeout]); } @@ -649,7 +649,7 @@ Socket.prototype._destroy = function(exception, cb) { if (this._handle) { if (this !== process.stderr) debug('close handle'); - var isException = exception ? true : false; + const isException = exception ? true : false; // `bytesRead` and `kBytesWritten` should be accessible after `.destroy()` this[kBytesRead] = this._handle.bytesRead; this[kBytesWritten] = this._handle.bytesWritten; @@ -681,8 +681,8 @@ Socket.prototype._getpeername = function() { if (!this._handle || !this._handle.getpeername) { return {}; } - var out = {}; - var err = this._handle.getpeername(out); + const out = {}; + const err = this._handle.getpeername(out); if (err) return {}; // FIXME(bnoordhuis) Throw? this._peername = out; } @@ -719,8 +719,8 @@ Socket.prototype._getsockname = function() { return {}; } if (!this._sockname) { - var out = {}; - var err = this._handle.getsockname(out); + const out = {}; + const err = this._handle.getsockname(out); if (err) return {}; // FIXME(bnoordhuis) Throw? this._sockname = out; } @@ -791,7 +791,7 @@ protoGetter('_bytesDispatched', function _bytesDispatched() { }); protoGetter('bytesWritten', function bytesWritten() { - var bytes = this._bytesDispatched; + let bytes = this._bytesDispatched; const state = this._writableState; const data = this._pendingData; const encoding = this._pendingEncoding; @@ -808,7 +808,7 @@ protoGetter('bytesWritten', function bytesWritten() { if (Array.isArray(data)) { // Was a writev, iterate over chunks to get total length - for (var i = 0; i < data.length; i++) { + for (let i = 0; i < data.length; i++) { const chunk = data[i]; if (data.allBuffers || chunk instanceof Buffer) @@ -838,7 +838,7 @@ function checkBindError(err, port, handle) { // getsockname() method. Non-issue for now, the cluster module doesn't // really support pipes anyway. if (err === 0 && port > 0 && handle.getsockname) { - var out = {}; + const out = {}; err = handle.getsockname(out); if (err === 0 && port !== out.port) { debug(`checkBindError, bound to ${out.port} instead of ${port}`); @@ -856,7 +856,7 @@ function internalConnect( assert(self.connecting); - var err; + let err; if (localAddress || localPort) { if (addressType === 4) { @@ -898,8 +898,8 @@ function internalConnect( } if (err) { - var sockname = self._getsockname(); - var details; + const sockname = self._getsockname(); + let details; if (sockname) { details = sockname.address + ':' + sockname.port; @@ -1122,15 +1122,15 @@ function afterConnect(status, handle, req, readable, writable) { } else { self.connecting = false; - var details; + let details; if (req.localAddress && req.localPort) { details = req.localAddress + ':' + req.localPort; } - var ex = exceptionWithHostPort(status, - 'connect', - req.address, - req.port, - details); + const ex = exceptionWithHostPort(status, + 'connect', + req.address, + req.port, + details); if (details) { ex.localAddress = req.localAddress; ex.localPort = req.localPort; @@ -1194,11 +1194,11 @@ function toNumber(x) { return (x = Number(x)) >= 0 ? x : false; } // Returns handle if it can be created, or error code if it can't function createServerHandle(address, port, addressType, fd, flags) { - var err = 0; + let err = 0; // Assign handle in listen, and clean up if bind or listen fails - var handle; + let handle; - var isTCP = false; + let isTCP = false; if (typeof fd === 'number' && fd >= 0) { try { handle = createHandle(fd, true); @@ -1216,7 +1216,7 @@ function createServerHandle(address, port, addressType, fd, flags) { } else if (port === -1 && addressType === -1) { handle = new Pipe(PipeConstants.SERVER); if (process.platform === 'win32') { - var instances = parseInt(process.env.NODE_PENDING_PIPE_INSTANCES); + const instances = parseInt(process.env.NODE_PENDING_PIPE_INSTANCES); if (!Number.isNaN(instances)) { handle.setPendingInstances(instances); } @@ -1261,7 +1261,7 @@ function setupListenHandle(address, port, addressType, backlog, fd, flags) { } else { debug('setupListenHandle: create a handle'); - var rval = null; + let rval = null; // Try to bind to the unspecified IPv6 address, see if IPv6 is available if (!address && typeof fd !== 'number') { @@ -1281,7 +1281,7 @@ function setupListenHandle(address, port, addressType, backlog, fd, flags) { rval = createServerHandle(address, port, addressType, fd, flags); if (typeof rval === 'number') { - var error = uvExceptionWithHostPort(rval, 'listen', address, port); + const error = uvExceptionWithHostPort(rval, 'listen', address, port); process.nextTick(emitErrorNT, this, error); return; } @@ -1298,7 +1298,7 @@ function setupListenHandle(address, port, addressType, backlog, fd, flags) { const err = this._handle.listen(backlog || 511); if (err) { - var ex = uvExceptionWithHostPort(err, 'listen', address, port); + const ex = uvExceptionWithHostPort(err, 'listen', address, port); this._handle.close(); this._handle = null; defaultTriggerAsyncIdScope(this[async_id_symbol], @@ -1365,7 +1365,7 @@ function listenInCluster(server, address, port, addressType, err = checkBindError(err, port, handle); if (err) { - var ex = exceptionWithHostPort(err, 'bind', address, port); + const ex = exceptionWithHostPort(err, 'bind', address, port); return server.emit('error', ex); } @@ -1380,7 +1380,7 @@ function listenInCluster(server, address, port, addressType, Server.prototype.listen = function(...args) { const normalized = normalizeArgs(args); - var options = normalized[0]; + let options = normalized[0]; const cb = normalized[1]; if (this._handle) { @@ -1422,7 +1422,7 @@ Server.prototype.listen = function(...args) { // ([port][, host][, backlog][, cb]) where port is specified // or (options[, cb]) where options.port is specified // or if options.port is normalized as 0 before - var backlog; + let backlog; if (typeof options.port === 'number' || typeof options.port === 'string') { if (!isLegalPort(options.port)) { throw new ERR_SOCKET_BAD_PORT(options.port); @@ -1443,7 +1443,7 @@ Server.prototype.listen = function(...args) { // (path[, backlog][, cb]) or (options[, cb]) // where path or options.path is a UNIX domain socket or Windows pipe if (options.path && isPipeName(options.path)) { - var pipeName = this._pipeName = options.path; + const pipeName = this._pipeName = options.path; backlog = options.backlog || backlogFromArgs; listenInCluster(this, pipeName, -1, -1, backlog, undefined, options.exclusive); @@ -1501,8 +1501,8 @@ Object.defineProperty(Server.prototype, 'listening', { Server.prototype.address = function() { if (this._handle && this._handle.getsockname) { - var out = {}; - var err = this._handle.getsockname(out); + const out = {}; + const err = this._handle.getsockname(out); if (err) { throw errnoException(err, 'address'); } @@ -1564,8 +1564,8 @@ Server.prototype.getConnections = function(cb) { } // Poll workers - var left = this._workers.length; - var total = this._connections; + let left = this._workers.length; + let total = this._connections; function oncount(err, count) { if (err) { @@ -1577,7 +1577,7 @@ Server.prototype.getConnections = function(cb) { if (--left === 0) return end(null, total); } - for (var n = 0; n < this._workers.length; n++) { + for (let n = 0; n < this._workers.length; n++) { this._workers[n].getConnections(oncount); } @@ -1602,7 +1602,7 @@ Server.prototype.close = function(cb) { } if (this._usingWorkers) { - var left = this._workers.length; + let left = this._workers.length; const onWorkerClose = () => { if (--left !== 0) return; @@ -1615,7 +1615,7 @@ Server.prototype.close = function(cb) { this._connections++; // Poll workers - for (var n = 0; n < this._workers.length; n++) + for (let n = 0; n < this._workers.length; n++) this._workers[n].close(onWorkerClose); } else { this._emitCloseIfDrained(); @@ -1685,11 +1685,11 @@ Server.prototype.unref = function() { return this; }; -var _setSimultaneousAccepts; -var warnSimultaneousAccepts = true; +let _setSimultaneousAccepts; +let warnSimultaneousAccepts = true; if (process.platform === 'win32') { - var simultaneousAccepts; + let simultaneousAccepts; _setSimultaneousAccepts = function(handle) { if (warnSimultaneousAccepts) {