Skip to content

Commit ae93168

Browse files
committed
benchmark,lib: var to const
Refs: #26679
1 parent 4bfc06f commit ae93168

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+341
-342
lines changed

benchmark/fs/readfile-partitioned.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function main(conf) {
2929
fs.writeFileSync(filename, data);
3030
data = null;
3131

32-
var zipData = Buffer.alloc(1024, 'a');
32+
const zipData = Buffer.alloc(1024, 'a');
3333

3434
var reads = 0;
3535
var zips = 0;

benchmark/fs/write-stream-throughput.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function main({ dur, encodingType, size }) {
3838
var started = false;
3939
var ended = false;
4040

41-
var f = fs.createWriteStream(filename);
41+
const f = fs.createWriteStream(filename);
4242
f.on('drain', write);
4343
f.on('open', write);
4444
f.on('close', done);

benchmark/http/_chunky_http_client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function main({ len, n }) {
5454
const add = 11;
5555
var count = 0;
5656
const PIPE = process.env.PIPE_NAME;
57-
var socket = net.connect(PIPE, () => {
57+
const socket = net.connect(PIPE, () => {
5858
bench.start();
5959
WriteHTTPHeaders(socket, 1, len);
6060
socket.setEncoding('utf8');

benchmark/http/http_server_for_chunky_client.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ process.env.PIPE_NAME = PIPE;
1010

1111
tmpdir.refresh();
1212

13-
var server;
14-
15-
server = http.createServer((req, res) => {
13+
const server = http.createServer((req, res) => {
1614
const headers = {
1715
'content-type': 'text/plain',
1816
'content-length': '2'

benchmark/http/set-header.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const c = 50;
1717
// setHeaderWH: setHeader(...), writeHead(status, ...)
1818
function main({ res }) {
1919
process.env.PORT = PORT;
20-
var server = require('../fixtures/simple-http-server.js')
20+
const server = require('../fixtures/simple-http-server.js')
2121
.listen(PORT)
2222
.on('listening', () => {
2323
const path = `/${type}/${len}/${chunks}/normal/${chunkedEnc}`;

benchmark/http/simple.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const bench = common.createBenchmark(main, {
1111
});
1212

1313
function main({ type, len, chunks, c, chunkedEnc, res }) {
14-
var server = require('../fixtures/simple-http-server.js')
14+
const server = require('../fixtures/simple-http-server.js')
1515
.listen(common.PORT)
1616
.on('listening', () => {
1717
const path = `/${type}/${len}/${chunks}/normal/${chunkedEnc}`;

benchmark/http/upgrade.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const resData = 'HTTP/1.1 101 Web Socket Protocol Handshake\r\n' +
1919
'\r\n\r\n';
2020

2121
function main({ n }) {
22-
var server = require('../fixtures/simple-http-server.js')
22+
const server = require('../fixtures/simple-http-server.js')
2323
.listen(common.PORT)
2424
.on('listening', () => {
2525
bench.start();

benchmark/tls/throughput.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const tls = require('tls');
1414

1515
function main({ dur, type, size }) {
1616
var encoding;
17-
var server;
1817
var chunk;
1918
switch (type) {
2019
case 'buf':
@@ -39,7 +38,7 @@ function main({ dur, type, size }) {
3938
ciphers: 'AES256-GCM-SHA384'
4039
};
4140

42-
server = tls.createServer(options, onConnection);
41+
const server = tls.createServer(options, onConnection);
4342
var conn;
4443
server.listen(common.PORT, () => {
4544
const opt = { port: common.PORT, rejectUnauthorized: false };

benchmark/tls/tls-connect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function makeConnection() {
4646
port: common.PORT,
4747
rejectUnauthorized: false
4848
};
49-
var conn = tls.connect(options, () => {
49+
const conn = tls.connect(options, () => {
5050
clientConn++;
5151
conn.on('error', (er) => {
5252
console.error('client error', er);

lib/_http_agent.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function Agent(options) {
6060
this.maxFreeSockets = this.options.maxFreeSockets || 256;
6161

6262
this.on('free', (socket, options) => {
63-
var name = this.getName(options);
63+
const name = this.getName(options);
6464
debug('agent.on(free)', name);
6565

6666
if (socket.writable &&
@@ -152,13 +152,13 @@ Agent.prototype.addRequest = function addRequest(req, options, port/* legacy */,
152152
if (!options.servername)
153153
options.servername = calculateServerName(options, req);
154154

155-
var name = this.getName(options);
155+
const name = this.getName(options);
156156
if (!this.sockets[name]) {
157157
this.sockets[name] = [];
158158
}
159159

160-
var freeLen = this.freeSockets[name] ? this.freeSockets[name].length : 0;
161-
var sockLen = freeLen + this.sockets[name].length;
160+
const freeLen = this.freeSockets[name] ? this.freeSockets[name].length : 0;
161+
const sockLen = freeLen + this.sockets[name].length;
162162

163163
if (freeLen) {
164164
// We have a free socket, so use that.
@@ -199,7 +199,7 @@ Agent.prototype.createSocket = function createSocket(req, options, cb) {
199199
if (!options.servername)
200200
options.servername = calculateServerName(options, req);
201201

202-
var name = this.getName(options);
202+
const name = this.getName(options);
203203
options._agentKey = name;
204204

205205
debug('createConnection', name, options);
@@ -279,9 +279,9 @@ function installListeners(agent, s, options) {
279279
}
280280

281281
Agent.prototype.removeSocket = function removeSocket(s, options) {
282-
var name = this.getName(options);
282+
const name = this.getName(options);
283283
debug('removeSocket', name, 'writable:', s.writable);
284-
var sets = [this.sockets];
284+
const sets = [this.sockets];
285285

286286
// If the socket was destroyed, remove it from the free buffers too.
287287
if (!s.writable)
@@ -323,7 +323,7 @@ Agent.prototype.reuseSocket = function reuseSocket(socket, req) {
323323
};
324324

325325
Agent.prototype.destroy = function destroy() {
326-
var sets = [this.freeSockets, this.sockets];
326+
const sets = [this.freeSockets, this.sockets];
327327
for (var s = 0; s < sets.length; s++) {
328328
var set = sets[s];
329329
var keys = Object.keys(set);

lib/_http_client.js

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function ClientRequest(input, options, cb) {
102102
}
103103

104104
var agent = options.agent;
105-
var defaultAgent = options._defaultAgent || Agent.globalAgent;
105+
const defaultAgent = options._defaultAgent || Agent.globalAgent;
106106
if (agent === false) {
107107
agent = new defaultAgent.constructor();
108108
} else if (agent === null || agent === undefined) {
@@ -118,7 +118,7 @@ function ClientRequest(input, options, cb) {
118118
}
119119
this.agent = agent;
120120

121-
var protocol = options.protocol || defaultAgent.protocol;
121+
const protocol = options.protocol || defaultAgent.protocol;
122122
var expectedProtocol = defaultAgent.protocol;
123123
if (this.agent && this.agent.protocol)
124124
expectedProtocol = this.agent.protocol;
@@ -134,22 +134,22 @@ function ClientRequest(input, options, cb) {
134134
throw new ERR_INVALID_PROTOCOL(protocol, expectedProtocol);
135135
}
136136

137-
var defaultPort = options.defaultPort ||
137+
const defaultPort = options.defaultPort ||
138138
this.agent && this.agent.defaultPort;
139139

140-
var port = options.port = options.port || defaultPort || 80;
141-
var host = options.host = validateHost(options.hostname, 'hostname') ||
140+
const port = options.port = options.port || defaultPort || 80;
141+
const host = options.host = validateHost(options.hostname, 'hostname') ||
142142
validateHost(options.host, 'host') || 'localhost';
143143

144-
var setHost = (options.setHost === undefined || Boolean(options.setHost));
144+
const setHost = (options.setHost === undefined || Boolean(options.setHost));
145145

146146
this.socketPath = options.socketPath;
147147

148148
if (options.timeout !== undefined)
149149
this.timeout = getTimerDuration(options.timeout, 'timeout');
150150

151151
var method = options.method;
152-
var methodIsString = (typeof method === 'string');
152+
const methodIsString = (typeof method === 'string');
153153
if (method !== null && method !== undefined && !methodIsString) {
154154
throw new ERR_INVALID_ARG_TYPE('method', 'string', method);
155155
}
@@ -202,7 +202,7 @@ function ClientRequest(input, options, cb) {
202202
}
203203
}
204204

205-
var headersArray = Array.isArray(options.headers);
205+
const headersArray = Array.isArray(options.headers);
206206
if (!headersArray) {
207207
if (options.headers) {
208208
var keys = Object.keys(options.headers);
@@ -249,7 +249,7 @@ function ClientRequest(input, options, cb) {
249249
options.headers);
250250
}
251251

252-
var oncreate = (err, socket) => {
252+
const oncreate = (err, socket) => {
253253
if (called)
254254
return;
255255
called = true;
@@ -331,15 +331,15 @@ function emitAbortNT() {
331331

332332
function createHangUpError() {
333333
// eslint-disable-next-line no-restricted-syntax
334-
var error = new Error('socket hang up');
334+
const error = new Error('socket hang up');
335335
error.code = 'ECONNRESET';
336336
return error;
337337
}
338338

339339

340340
function socketCloseListener() {
341-
var socket = this;
342-
var req = socket._httpMessage;
341+
const socket = this;
342+
const req = socket._httpMessage;
343343
debug('HTTP socket close');
344344

345345
// Pull through final chunk, if anything is buffered.
@@ -390,8 +390,8 @@ function socketCloseListener() {
390390
}
391391

392392
function socketErrorListener(err) {
393-
var socket = this;
394-
var req = socket._httpMessage;
393+
const socket = this;
394+
const req = socket._httpMessage;
395395
debug('SOCKET ERROR:', err.message, err.stack);
396396

397397
if (req) {
@@ -404,7 +404,7 @@ function socketErrorListener(err) {
404404
// Handle any pending data
405405
socket.read();
406406

407-
var parser = socket.parser;
407+
const parser = socket.parser;
408408
if (parser) {
409409
parser.finish();
410410
freeParser(parser, req, socket);
@@ -417,16 +417,16 @@ function socketErrorListener(err) {
417417
}
418418

419419
function freeSocketErrorListener(err) {
420-
var socket = this;
420+
const socket = this;
421421
debug('SOCKET ERROR on FREE socket:', err.message, err.stack);
422422
socket.destroy();
423423
socket.emit('agentRemove');
424424
}
425425

426426
function socketOnEnd() {
427-
var socket = this;
428-
var req = this._httpMessage;
429-
var parser = this.parser;
427+
const socket = this;
428+
const req = this._httpMessage;
429+
const parser = this.parser;
430430

431431
if (!req.res && !req.socket._hadError) {
432432
// If we don't have a response then we know that the socket
@@ -442,13 +442,13 @@ function socketOnEnd() {
442442
}
443443

444444
function socketOnData(d) {
445-
var socket = this;
446-
var req = this._httpMessage;
447-
var parser = this.parser;
445+
const socket = this;
446+
const req = this._httpMessage;
447+
const parser = this.parser;
448448

449449
assert(parser && parser.socket === socket);
450450

451-
var ret = parser.execute(d);
451+
const ret = parser.execute(d);
452452
if (ret instanceof Error) {
453453
debug('parse error', ret);
454454
freeParser(parser, req, socket);
@@ -510,8 +510,8 @@ function statusIsInformational(status) {
510510

511511
// client
512512
function parserOnIncomingClient(res, shouldKeepAlive) {
513-
var socket = this.socket;
514-
var req = socket._httpMessage;
513+
const socket = this.socket;
514+
const req = socket._httpMessage;
515515

516516
debug('AGENT incoming response!');
517517

@@ -561,7 +561,7 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
561561
// Add our listener first, so that we guarantee socket cleanup
562562
res.on('end', responseOnEnd);
563563
req.on('prefinish', requestOnPrefinish);
564-
var handled = req.emit('response', res);
564+
const handled = req.emit('response', res);
565565

566566
// If the user did not listen for the 'response' event, then they
567567
// can't possibly read the data, so we ._dump() it into the void
@@ -577,7 +577,7 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
577577

578578
// client
579579
function responseKeepAlive(res, req) {
580-
var socket = req.socket;
580+
const socket = req.socket;
581581

582582
if (!req.shouldKeepAlive) {
583583
if (socket.writable) {
@@ -631,7 +631,7 @@ function emitFreeNT(socket) {
631631
}
632632

633633
function tickOnSocket(req, socket) {
634-
var parser = parsers.alloc();
634+
const parser = parsers.alloc();
635635
req.socket = socket;
636636
req.connection = socket;
637637
parser.reinitialize(HTTPParser.RESPONSE, parser[is_reused_symbol]);

lib/_http_incoming.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ function matchKnownFields(field, lowercased) {
243243
IncomingMessage.prototype._addHeaderLine = _addHeaderLine;
244244
function _addHeaderLine(field, value, dest) {
245245
field = matchKnownFields(field);
246-
var flag = field.charCodeAt(0);
246+
const flag = field.charCodeAt(0);
247247
if (flag === 0 || flag === 2) {
248248
field = field.slice(1);
249249
// Make a delimited list

lib/_http_outgoing.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ const kIsCorked = Symbol('isCorked');
5555

5656
const hasOwnProperty = Function.call.bind(Object.prototype.hasOwnProperty);
5757

58-
var RE_CONN_CLOSE = /(?:^|\W)close(?:$|\W)/i;
59-
var RE_TE_CHUNKED = common.chunkExpression;
58+
const RE_CONN_CLOSE = /(?:^|\W)close(?:$|\W)/i;
59+
const RE_TE_CHUNKED = common.chunkExpression;
6060

6161
// isCookieField performs a case-insensitive comparison of a provided string
6262
// against the word "cookie." As of V8 6.6 this is faster than handrolling or
@@ -164,7 +164,7 @@ OutgoingMessage.prototype._renderHeaders = function _renderHeaders() {
164164
throw new ERR_HTTP_HEADERS_SENT('render');
165165
}
166166

167-
var headersMap = this[outHeadersKey];
167+
const headersMap = this[outHeadersKey];
168168
const headers = {};
169169

170170
if (headersMap !== null) {
@@ -525,7 +525,7 @@ OutgoingMessage.prototype.removeHeader = function removeHeader(name) {
525525
throw new ERR_HTTP_HEADERS_SENT('remove');
526526
}
527527

528-
var key = name.toLowerCase();
528+
const key = name.toLowerCase();
529529

530530
switch (key) {
531531
case 'connection':
@@ -641,8 +641,8 @@ function connectionCorkNT(msg, conn) {
641641

642642
OutgoingMessage.prototype.addTrailers = function addTrailers(headers) {
643643
this._trailer = '';
644-
var keys = Object.keys(headers);
645-
var isArray = Array.isArray(headers);
644+
const keys = Object.keys(headers);
645+
const isArray = Array.isArray(headers);
646646
var field, value;
647647
for (var i = 0, l = keys.length; i < l; i++) {
648648
var key = keys[i];
@@ -705,7 +705,7 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) {
705705
if (typeof callback === 'function')
706706
this.once('finish', callback);
707707

708-
var finish = onFinish.bind(undefined, this);
708+
const finish = onFinish.bind(undefined, this);
709709

710710
if (this._hasBody && this.chunkedEncoding) {
711711
this._send('0\r\n' + this._trailer + '\r\n', 'latin1', finish);
@@ -758,7 +758,7 @@ OutgoingMessage.prototype._finish = function _finish() {
758758
// This function, outgoingFlush(), is called by both the Server and Client
759759
// to attempt to flush any pending messages out to the socket.
760760
OutgoingMessage.prototype._flush = function _flush() {
761-
var socket = this.socket;
761+
const socket = this.socket;
762762
var ret;
763763

764764
if (socket && socket.writable) {

0 commit comments

Comments
 (0)