Skip to content

Commit

Permalink
benchmark,lib: change var to const
Browse files Browse the repository at this point in the history
Refs: #26679

PR-URL: #26915
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Signed-off-by: Beth Griggs <Bethany.Griggs@uk.ibm.com>
  • Loading branch information
BridgeAR authored and BethGriggs committed Apr 8, 2019
1 parent 0f615d4 commit 0aea4d1
Show file tree
Hide file tree
Showing 44 changed files with 343 additions and 346 deletions.
2 changes: 1 addition & 1 deletion benchmark/fs/readfile-partitioned.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function main(conf) {
fs.writeFileSync(filename, data);
data = null;

var zipData = Buffer.alloc(1024, 'a');
const zipData = Buffer.alloc(1024, 'a');

var reads = 0;
var zips = 0;
Expand Down
2 changes: 1 addition & 1 deletion benchmark/fs/write-stream-throughput.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function main({ dur, encodingType, size }) {
var started = false;
var ended = false;

var f = fs.createWriteStream(filename);
const f = fs.createWriteStream(filename);
f.on('drain', write);
f.on('open', write);
f.on('close', done);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/http/_chunky_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function main({ len, n }) {
const add = 11;
var count = 0;
const PIPE = process.env.PIPE_NAME;
var socket = net.connect(PIPE, () => {
const socket = net.connect(PIPE, () => {
bench.start();
WriteHTTPHeaders(socket, 1, len);
socket.setEncoding('utf8');
Expand Down
4 changes: 1 addition & 3 deletions benchmark/http/http_server_for_chunky_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ process.env.PIPE_NAME = PIPE;

tmpdir.refresh();

var server;

server = http.createServer((req, res) => {
const server = http.createServer((req, res) => {
const headers = {
'content-type': 'text/plain',
'content-length': '2'
Expand Down
2 changes: 1 addition & 1 deletion benchmark/http/set-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const c = 50;
// setHeaderWH: setHeader(...), writeHead(status, ...)
function main({ res }) {
process.env.PORT = PORT;
var server = require('../fixtures/simple-http-server.js')
const server = require('../fixtures/simple-http-server.js')
.listen(PORT)
.on('listening', () => {
const path = `/${type}/${len}/${chunks}/normal/${chunkedEnc}`;
Expand Down
2 changes: 1 addition & 1 deletion benchmark/http/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const bench = common.createBenchmark(main, {
});

function main({ type, len, chunks, c, chunkedEnc, res }) {
var server = require('../fixtures/simple-http-server.js')
const server = require('../fixtures/simple-http-server.js')
.listen(common.PORT)
.on('listening', () => {
const path = `/${type}/${len}/${chunks}/normal/${chunkedEnc}`;
Expand Down
2 changes: 1 addition & 1 deletion benchmark/http/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const resData = 'HTTP/1.1 101 Web Socket Protocol Handshake\r\n' +
'\r\n\r\n';

function main({ n }) {
var server = require('../fixtures/simple-http-server.js')
const server = require('../fixtures/simple-http-server.js')
.listen(common.PORT)
.on('listening', () => {
bench.start();
Expand Down
3 changes: 1 addition & 2 deletions benchmark/tls/throughput.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const tls = require('tls');

function main({ dur, type, size }) {
var encoding;
var server;
var chunk;
switch (type) {
case 'buf':
Expand All @@ -39,7 +38,7 @@ function main({ dur, type, size }) {
ciphers: 'AES256-GCM-SHA384'
};

server = tls.createServer(options, onConnection);
const server = tls.createServer(options, onConnection);
var conn;
server.listen(common.PORT, () => {
const opt = { port: common.PORT, rejectUnauthorized: false };
Expand Down
2 changes: 1 addition & 1 deletion benchmark/tls/tls-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function makeConnection() {
port: common.PORT,
rejectUnauthorized: false
};
var conn = tls.connect(options, () => {
const conn = tls.connect(options, () => {
clientConn++;
conn.on('error', (er) => {
console.error('client error', er);
Expand Down
16 changes: 8 additions & 8 deletions lib/_http_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function Agent(options) {
this.maxFreeSockets = this.options.maxFreeSockets || 256;

this.on('free', (socket, options) => {
var name = this.getName(options);
const name = this.getName(options);
debug('agent.on(free)', name);

if (socket.writable &&
Expand Down Expand Up @@ -153,13 +153,13 @@ Agent.prototype.addRequest = function addRequest(req, options, port/* legacy */,
if (!options.servername)
options.servername = calculateServerName(options, req);

var name = this.getName(options);
const name = this.getName(options);
if (!this.sockets[name]) {
this.sockets[name] = [];
}

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

if (freeLen) {
// We have a free socket, so use that.
Expand Down Expand Up @@ -200,7 +200,7 @@ Agent.prototype.createSocket = function createSocket(req, options, cb) {
if (!options.servername)
options.servername = calculateServerName(options, req);

var name = this.getName(options);
const name = this.getName(options);
options._agentKey = name;

debug('createConnection', name, options);
Expand Down Expand Up @@ -280,9 +280,9 @@ function installListeners(agent, s, options) {
}

Agent.prototype.removeSocket = function removeSocket(s, options) {
var name = this.getName(options);
const name = this.getName(options);
debug('removeSocket', name, 'writable:', s.writable);
var sets = [this.sockets];
const sets = [this.sockets];

// If the socket was destroyed, remove it from the free buffers too.
if (!s.writable)
Expand Down Expand Up @@ -324,7 +324,7 @@ Agent.prototype.reuseSocket = function reuseSocket(socket, req) {
};

Agent.prototype.destroy = function destroy() {
var sets = [this.freeSockets, this.sockets];
const sets = [this.freeSockets, this.sockets];
for (var s = 0; s < sets.length; s++) {
var set = sets[s];
var keys = Object.keys(set);
Expand Down
56 changes: 28 additions & 28 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function ClientRequest(input, options, cb) {
}

var agent = options.agent;
var defaultAgent = options._defaultAgent || Agent.globalAgent;
const defaultAgent = options._defaultAgent || Agent.globalAgent;
if (agent === false) {
agent = new defaultAgent.constructor();
} else if (agent === null || agent === undefined) {
Expand All @@ -115,7 +115,7 @@ function ClientRequest(input, options, cb) {
}
this.agent = agent;

var protocol = options.protocol || defaultAgent.protocol;
const protocol = options.protocol || defaultAgent.protocol;
var expectedProtocol = defaultAgent.protocol;
if (this.agent && this.agent.protocol)
expectedProtocol = this.agent.protocol;
Expand All @@ -131,20 +131,20 @@ function ClientRequest(input, options, cb) {
throw new ERR_INVALID_PROTOCOL(protocol, expectedProtocol);
}

var defaultPort = options.defaultPort ||
const defaultPort = options.defaultPort ||
this.agent && this.agent.defaultPort;

var port = options.port = options.port || defaultPort || 80;
var host = options.host = validateHost(options.hostname, 'hostname') ||
const port = options.port = options.port || defaultPort || 80;
const host = options.host = validateHost(options.hostname, 'hostname') ||
validateHost(options.host, 'host') || 'localhost';

var setHost = (options.setHost === undefined || Boolean(options.setHost));
const setHost = (options.setHost === undefined || Boolean(options.setHost));

this.socketPath = options.socketPath;
this.timeout = options.timeout;

var method = options.method;
var methodIsString = (typeof method === 'string');
const methodIsString = (typeof method === 'string');
if (method !== null && method !== undefined && !methodIsString) {
throw new ERR_INVALID_ARG_TYPE('method', 'string', method);
}
Expand Down Expand Up @@ -197,7 +197,7 @@ function ClientRequest(input, options, cb) {
}
}

var headersArray = Array.isArray(options.headers);
const headersArray = Array.isArray(options.headers);
if (!headersArray) {
if (options.headers) {
var keys = Object.keys(options.headers);
Expand Down Expand Up @@ -244,7 +244,7 @@ function ClientRequest(input, options, cb) {
options.headers);
}

var oncreate = (err, socket) => {
const oncreate = (err, socket) => {
if (called)
return;
called = true;
Expand Down Expand Up @@ -327,15 +327,15 @@ function emitAbortNT() {

function createHangUpError() {
// eslint-disable-next-line no-restricted-syntax
var error = new Error('socket hang up');
const error = new Error('socket hang up');
error.code = 'ECONNRESET';
return error;
}


function socketCloseListener() {
var socket = this;
var req = socket._httpMessage;
const socket = this;
const req = socket._httpMessage;
debug('HTTP socket close');

// Pull through final chunk, if anything is buffered.
Expand Down Expand Up @@ -386,8 +386,8 @@ function socketCloseListener() {
}

function socketErrorListener(err) {
var socket = this;
var req = socket._httpMessage;
const socket = this;
const req = socket._httpMessage;
debug('SOCKET ERROR:', err.message, err.stack);

if (req) {
Expand All @@ -400,7 +400,7 @@ function socketErrorListener(err) {
// Handle any pending data
socket.read();

var parser = socket.parser;
const parser = socket.parser;
if (parser) {
parser.finish();
freeParser(parser, req, socket);
Expand All @@ -413,16 +413,16 @@ function socketErrorListener(err) {
}

function freeSocketErrorListener(err) {
var socket = this;
const socket = this;
debug('SOCKET ERROR on FREE socket:', err.message, err.stack);
socket.destroy();
socket.emit('agentRemove');
}

function socketOnEnd() {
var socket = this;
var req = this._httpMessage;
var parser = this.parser;
const socket = this;
const req = this._httpMessage;
const parser = this.parser;

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

function socketOnData(d) {
var socket = this;
var req = this._httpMessage;
var parser = this.parser;
const socket = this;
const req = this._httpMessage;
const parser = this.parser;

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

var ret = parser.execute(d);
const ret = parser.execute(d);
if (ret instanceof Error) {
debug('parse error', ret);
freeParser(parser, req, socket);
Expand Down Expand Up @@ -506,8 +506,8 @@ function statusIsInformational(status) {

// client
function parserOnIncomingClient(res, shouldKeepAlive) {
var socket = this.socket;
var req = socket._httpMessage;
const socket = this.socket;
const req = socket._httpMessage;

debug('AGENT incoming response!');

Expand Down Expand Up @@ -557,7 +557,7 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
// Add our listener first, so that we guarantee socket cleanup
res.on('end', responseOnEnd);
req.on('prefinish', requestOnPrefinish);
var handled = req.emit('response', res);
const handled = req.emit('response', res);

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

// client
function responseKeepAlive(res, req) {
var socket = req.socket;
const socket = req.socket;

if (!req.shouldKeepAlive) {
if (socket.writable) {
Expand Down Expand Up @@ -627,7 +627,7 @@ function emitFreeNT(socket) {
}

function tickOnSocket(req, socket) {
var parser = parsers.alloc();
const parser = parsers.alloc();
req.socket = socket;
req.connection = socket;
parser.reinitialize(HTTPParser.RESPONSE, parser[is_reused_symbol]);
Expand Down
2 changes: 1 addition & 1 deletion lib/_http_incoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ function matchKnownFields(field, lowercased) {
IncomingMessage.prototype._addHeaderLine = _addHeaderLine;
function _addHeaderLine(field, value, dest) {
field = matchKnownFields(field);
var flag = field.charCodeAt(0);
const flag = field.charCodeAt(0);
if (flag === 0 || flag === 2) {
field = field.slice(1);
// Make a delimited list
Expand Down
16 changes: 8 additions & 8 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ const kIsCorked = Symbol('isCorked');

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

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

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

var headersMap = this[outHeadersKey];
const headersMap = this[outHeadersKey];
const headers = {};

if (headersMap !== null) {
Expand Down Expand Up @@ -540,7 +540,7 @@ OutgoingMessage.prototype.removeHeader = function removeHeader(name) {
throw new ERR_HTTP_HEADERS_SENT('remove');
}

var key = name.toLowerCase();
const key = name.toLowerCase();

switch (key) {
case 'connection':
Expand Down Expand Up @@ -656,8 +656,8 @@ function connectionCorkNT(msg, conn) {

OutgoingMessage.prototype.addTrailers = function addTrailers(headers) {
this._trailer = '';
var keys = Object.keys(headers);
var isArray = Array.isArray(headers);
const keys = Object.keys(headers);
const isArray = Array.isArray(headers);
var field, value;
for (var i = 0, l = keys.length; i < l; i++) {
var key = keys[i];
Expand Down Expand Up @@ -720,7 +720,7 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) {
if (typeof callback === 'function')
this.once('finish', callback);

var finish = onFinish.bind(undefined, this);
const finish = onFinish.bind(undefined, this);

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

if (socket && socket.writable) {
Expand Down
Loading

0 comments on commit 0aea4d1

Please sign in to comment.