Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: replaced vars to lets and consts #30401

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 44 additions & 44 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
// ...
// });
//
Expand Down Expand Up @@ -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];
Expand All @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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'));
}
Expand Down Expand Up @@ -641,15 +641,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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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}`);
Expand All @@ -856,7 +856,7 @@ function internalConnect(

assert(self.connecting);

var err;
let err;

if (localAddress || localPort) {
if (addressType === 4) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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') {
Expand All @@ -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;
}
Expand All @@ -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],
Expand Down Expand Up @@ -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);
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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');
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}

Expand All @@ -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;

Expand All @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down