Skip to content
Permalink
Browse files

net: replaced vars to lets and consts

PR-URL: #30401
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
  • Loading branch information
nath1as authored and MylesBorins committed Nov 12, 2019
1 parent ff4f236 commit 21be4b1b95c65bc51bc1949305b8bcc6035d487f
Showing with 44 additions and 44 deletions.
  1. +44 −44 lib/net.js
@@ -155,7 +155,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() {
// ...
// });
//
@@ -190,7 +190,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];
@@ -199,7 +199,7 @@ function normalizeArgs(args) {
}

const arg0 = args[0];
var options = {};
let options = {};
if (typeof arg0 === 'object' && arg0 !== null) {
// (options[...][, cb])
options = arg0;
@@ -382,7 +382,7 @@ ObjectSetPrototypeOf(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();
}
@@ -558,7 +558,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'));
}
@@ -646,15 +646,15 @@ 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]);
}

debug('close');
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;
@@ -686,8 +686,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;
}
@@ -724,8 +724,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;
}
@@ -796,7 +796,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;
@@ -813,7 +813,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)
@@ -843,7 +843,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}`);
@@ -861,7 +861,7 @@ function internalConnect(

assert(self.connecting);

var err;
let err;

if (localAddress || localPort) {
if (addressType === 4) {
@@ -903,8 +903,8 @@ function internalConnect(
}

if (err) {
var sockname = self._getsockname();
var details;
const sockname = self._getsockname();
let details;

if (sockname) {
details = sockname.address + ':' + sockname.port;
@@ -1127,15 +1127,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;
@@ -1199,11 +1199,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);
@@ -1221,7 +1221,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);
}
@@ -1266,7 +1266,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') {
@@ -1286,7 +1286,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;
}
@@ -1303,7 +1303,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],
@@ -1370,7 +1370,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);
}

@@ -1385,7 +1385,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) {
@@ -1427,7 +1427,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);
@@ -1448,7 +1448,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);
@@ -1506,8 +1506,8 @@ ObjectDefineProperty(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');
}
@@ -1569,8 +1569,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) {
@@ -1582,7 +1582,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);
}

@@ -1607,7 +1607,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;

@@ -1620,7 +1620,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();
@@ -1690,11 +1690,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) {

0 comments on commit 21be4b1

Please sign in to comment.
You can’t perform that action at this time.