diff --git a/benchmark/module/module-loader-deep.js b/benchmark/module/module-loader-deep.js index a7e67296ea7a87..5b4f4b907a7ce6 100644 --- a/benchmark/module/module-loader-deep.js +++ b/benchmark/module/module-loader-deep.js @@ -37,14 +37,13 @@ function main({ ext, cache, files }) { } function measureDir(cache, files) { - var i; if (cache) { - for (i = 0; i <= files; i++) { + for (let i = 0; i <= files; i++) { require(`${benchmarkDirectory}/${i}`); } } bench.start(); - for (i = 0; i <= files; i++) { + for (let i = 0; i <= files; i++) { require(`${benchmarkDirectory}/${i}`); } bench.end(files); diff --git a/benchmark/module/module-loader.js b/benchmark/module/module-loader.js index c89f51d6a1a19f..f31ac8722cb208 100644 --- a/benchmark/module/module-loader.js +++ b/benchmark/module/module-loader.js @@ -42,15 +42,14 @@ function main({ n, name, cache, files, dir }) { } function measureDir(n, cache, files, name) { - var i; if (cache) { - for (i = 0; i <= files; i++) { + for (let i = 0; i <= files; i++) { require(`${benchmarkDirectory}${i}${name}`); } } bench.start(); - for (i = 0; i <= files; i++) { - for (var j = 0; j < n; j++) + for (let i = 0; i <= files; i++) { + for (let j = 0; j < n; j++) require(`${benchmarkDirectory}${i}${name}`); // Pretend mixed input (otherwise the results are less representative due to // highly specialized code). diff --git a/benchmark/napi/function_args/index.js b/benchmark/napi/function_args/index.js index 8f13454944772e..8ce9fa9d528f5c 100644 --- a/benchmark/napi/function_args/index.js +++ b/benchmark/napi/function_args/index.js @@ -89,7 +89,7 @@ function main({ n, engine, type }) { const args = generateArgs(type); bench.start(); - for (var i = 0; i < n; i++) { + for (let i = 0; i < n; i++) { fn.apply(null, args); } bench.end(n); diff --git a/benchmark/napi/function_call/index.js b/benchmark/napi/function_call/index.js index 3eebf9c05acdb1..1e1d159c8ad83a 100644 --- a/benchmark/napi/function_call/index.js +++ b/benchmark/napi/function_call/index.js @@ -29,7 +29,7 @@ try { } const napi = napi_binding.hello; -var c = 0; +let c = 0; function js() { return c++; } @@ -44,7 +44,7 @@ const bench = common.createBenchmark(main, { function main({ n, type }) { const fn = type === 'cxx' ? cxx : type === 'napi' ? napi : js; bench.start(); - for (var i = 0; i < n; i++) { + for (let i = 0; i < n; i++) { fn(); } bench.end(n); diff --git a/benchmark/net/net-c2s-cork.js b/benchmark/net/net-c2s-cork.js index 12d15fe0795e57..1493cae68d0069 100644 --- a/benchmark/net/net-c2s-cork.js +++ b/benchmark/net/net-c2s-cork.js @@ -11,8 +11,8 @@ const bench = common.createBenchmark(main, { dur: [5], }); -var chunk; -var encoding; +let chunk; +let encoding; function main({ dur, len, type }) { switch (type) { diff --git a/benchmark/net/net-c2s.js b/benchmark/net/net-c2s.js index 4b64cbeca18124..cacd6815630b2e 100644 --- a/benchmark/net/net-c2s.js +++ b/benchmark/net/net-c2s.js @@ -11,8 +11,8 @@ const bench = common.createBenchmark(main, { dur: [5], }); -var chunk; -var encoding; +let chunk; +let encoding; function main({ dur, len, type }) { switch (type) { diff --git a/benchmark/net/net-pipe.js b/benchmark/net/net-pipe.js index 06426129f7f271..d86ff73041d845 100644 --- a/benchmark/net/net-pipe.js +++ b/benchmark/net/net-pipe.js @@ -11,8 +11,8 @@ const bench = common.createBenchmark(main, { dur: [5], }); -var chunk; -var encoding; +let chunk; +let encoding; function main({ dur, len, type }) { switch (type) { diff --git a/benchmark/net/net-s2c.js b/benchmark/net/net-s2c.js index d8c26db9bdb035..789eadf0a18dba 100644 --- a/benchmark/net/net-s2c.js +++ b/benchmark/net/net-s2c.js @@ -12,10 +12,10 @@ const bench = common.createBenchmark(main, { dur: [5] }); -var chunk; -var encoding; -var recvbuf; -var received = 0; +let chunk; +let encoding; +let recvbuf; +let received = 0; function main({ dur, sendchunklen, type, recvbuflen, recvbufgenfn }) { if (isFinite(recvbuflen) && recvbuflen > 0) @@ -38,8 +38,8 @@ function main({ dur, sendchunklen, type, recvbuflen, recvbufgenfn }) { } const reader = new Reader(); - var writer; - var socketOpts; + let writer; + let socketOpts; if (recvbuf === undefined) { writer = new Writer(); socketOpts = { port: PORT }; diff --git a/benchmark/net/net-wrap-js-stream-passthrough.js b/benchmark/net/net-wrap-js-stream-passthrough.js index 1e8a1ee1c5a092..0d7be36c6aa545 100644 --- a/benchmark/net/net-wrap-js-stream-passthrough.js +++ b/benchmark/net/net-wrap-js-stream-passthrough.js @@ -12,8 +12,8 @@ const bench = common.createBenchmark(main, { flags: ['--expose-internals'] }); -var chunk; -var encoding; +let chunk; +let encoding; function main({ dur, len, type }) { // Can only require internals inside main(). diff --git a/benchmark/net/tcp-raw-c2s.js b/benchmark/net/tcp-raw-c2s.js index fe320ddaa2716b..b8af124a7f40fc 100644 --- a/benchmark/net/tcp-raw-c2s.js +++ b/benchmark/net/tcp-raw-c2s.js @@ -24,7 +24,7 @@ function main({ dur, len, type }) { const PORT = common.PORT; const serverHandle = new TCP(TCPConstants.SERVER); - var err = serverHandle.bind('127.0.0.1', PORT); + let err = serverHandle.bind('127.0.0.1', PORT); if (err) fail(err, 'bind'); @@ -38,7 +38,7 @@ function main({ dur, len, type }) { // The meat of the benchmark is right here: bench.start(); - var bytes = 0; + let bytes = 0; setTimeout(() => { // report in Gb/sec @@ -67,7 +67,7 @@ function main({ dur, len, type }) { } function client(type, len) { - var chunk; + let chunk; switch (type) { case 'buf': chunk = Buffer.alloc(len, 'x'); @@ -102,7 +102,7 @@ function main({ dur, len, type }) { function write() { const writeReq = new WriteWrap(); writeReq.oncomplete = afterWrite; - var err; + let err; switch (type) { case 'buf': err = clientHandle.writeBuffer(writeReq, chunk); diff --git a/benchmark/net/tcp-raw-pipe.js b/benchmark/net/tcp-raw-pipe.js index 4420cc2e6dcc17..249b61046a84cf 100644 --- a/benchmark/net/tcp-raw-pipe.js +++ b/benchmark/net/tcp-raw-pipe.js @@ -31,7 +31,7 @@ function main({ dur, len, type }) { // Server const serverHandle = new TCP(TCPConstants.SERVER); - var err = serverHandle.bind('127.0.0.1', PORT); + let err = serverHandle.bind('127.0.0.1', PORT); if (err) fail(err, 'bind'); @@ -66,7 +66,7 @@ function main({ dur, len, type }) { }; // Client - var chunk; + let chunk; switch (type) { case 'buf': chunk = Buffer.alloc(len, 'x'); @@ -83,7 +83,7 @@ function main({ dur, len, type }) { const clientHandle = new TCP(TCPConstants.SOCKET); const connectReq = new TCPConnectWrap(); - var bytes = 0; + let bytes = 0; err = clientHandle.connect(connectReq, '127.0.0.1', PORT); if (err) @@ -118,7 +118,7 @@ function main({ dur, len, type }) { function write() { const writeReq = new WriteWrap(); writeReq.oncomplete = afterWrite; - var err; + let err; switch (type) { case 'buf': err = clientHandle.writeBuffer(writeReq, chunk); diff --git a/benchmark/net/tcp-raw-s2c.js b/benchmark/net/tcp-raw-s2c.js index cc2f69019fff61..393cf060489cb8 100644 --- a/benchmark/net/tcp-raw-s2c.js +++ b/benchmark/net/tcp-raw-s2c.js @@ -26,7 +26,7 @@ function main({ dur, len, type }) { const PORT = common.PORT; const serverHandle = new TCP(TCPConstants.SERVER); - var err = serverHandle.bind('127.0.0.1', PORT); + let err = serverHandle.bind('127.0.0.1', PORT); if (err) fail(err, 'bind'); @@ -38,7 +38,7 @@ function main({ dur, len, type }) { if (err) fail(err, 'connect'); - var chunk; + let chunk; switch (type) { case 'buf': chunk = Buffer.alloc(len, 'x'); @@ -62,7 +62,7 @@ function main({ dur, len, type }) { const writeReq = new WriteWrap(); writeReq.async = false; writeReq.oncomplete = afterWrite; - var err; + let err; switch (type) { case 'buf': err = clientHandle.writeBuffer(writeReq, chunk); @@ -108,7 +108,7 @@ function main({ dur, len, type }) { fail(err, 'connect'); connectReq.oncomplete = function() { - var bytes = 0; + let bytes = 0; clientHandle.onread = function(buffer) { // We're not expecting to ever get an EOF from the client. // Just lots of data forever. diff --git a/benchmark/path/basename-posix.js b/benchmark/path/basename-posix.js index 2116f03d5e13e1..6600068d4c53f6 100644 --- a/benchmark/path/basename-posix.js +++ b/benchmark/path/basename-posix.js @@ -19,7 +19,7 @@ const bench = common.createBenchmark(main, { }); function main({ n, pathext }) { - var ext; + let ext; const extIdx = pathext.indexOf('|'); if (extIdx !== -1) { ext = pathext.slice(extIdx + 1); diff --git a/benchmark/path/basename-win32.js b/benchmark/path/basename-win32.js index d310ef2afcf580..dc26a134e29252 100644 --- a/benchmark/path/basename-win32.js +++ b/benchmark/path/basename-win32.js @@ -19,7 +19,7 @@ const bench = common.createBenchmark(main, { }); function main({ n, pathext }) { - var ext; + let ext; const extIdx = pathext.indexOf('|'); if (extIdx !== -1) { ext = pathext.slice(extIdx + 1); diff --git a/benchmark/path/relative-posix.js b/benchmark/path/relative-posix.js index 2c4dd31d2778c7..0285c2c968dcb2 100644 --- a/benchmark/path/relative-posix.js +++ b/benchmark/path/relative-posix.js @@ -16,7 +16,7 @@ const bench = common.createBenchmark(main, { }); function main({ n, paths }) { - var to = ''; + let to = ''; const delimIdx = paths.indexOf('|'); if (delimIdx > -1) { to = paths.slice(delimIdx + 1); diff --git a/benchmark/path/relative-win32.js b/benchmark/path/relative-win32.js index 5f34fdf8fd5842..401919aa20d802 100644 --- a/benchmark/path/relative-win32.js +++ b/benchmark/path/relative-win32.js @@ -14,7 +14,7 @@ const bench = common.createBenchmark(main, { }); function main({ n, paths }) { - var to = ''; + let to = ''; const delimIdx = paths.indexOf('|'); if (delimIdx > -1) { to = paths.slice(delimIdx + 1); diff --git a/benchmark/process/bench-hrtime.js b/benchmark/process/bench-hrtime.js index d73ed7aae4336e..2da9035f806cf9 100644 --- a/benchmark/process/bench-hrtime.js +++ b/benchmark/process/bench-hrtime.js @@ -10,27 +10,26 @@ const bench = common.createBenchmark(main, { function main({ n, type }) { const hrtime = process.hrtime; - var noDead = type === 'bigint' ? hrtime.bigint() : hrtime(); - var i; + let noDead = type === 'bigint' ? hrtime.bigint() : hrtime(); switch (type) { case 'raw': bench.start(); - for (i = 0; i < n; i++) { + for (let i = 0; i < n; i++) { noDead = hrtime(); } bench.end(n); break; case 'diff': bench.start(); - for (i = 0; i < n; i++) { + for (let i = 0; i < n; i++) { noDead = hrtime(noDead); } bench.end(n); break; case 'bigint': bench.start(); - for (i = 0; i < n; i++) { + for (let i = 0; i < n; i++) { noDead = hrtime.bigint(); } bench.end(n); diff --git a/benchmark/process/next-tick-breadth-args.js b/benchmark/process/next-tick-breadth-args.js index 7270fda720c5f0..bd3b24ddc29fc5 100644 --- a/benchmark/process/next-tick-breadth-args.js +++ b/benchmark/process/next-tick-breadth-args.js @@ -6,7 +6,7 @@ const bench = common.createBenchmark(main, { }); function main({ n }) { - var j = 0; + let j = 0; function cb1(arg1) { j++; diff --git a/benchmark/process/next-tick-breadth.js b/benchmark/process/next-tick-breadth.js index b295294e1423e5..eb34ea830acfe7 100644 --- a/benchmark/process/next-tick-breadth.js +++ b/benchmark/process/next-tick-breadth.js @@ -6,7 +6,7 @@ const bench = common.createBenchmark(main, { }); function main({ n }) { - var j = 0; + let j = 0; function cb() { j++; diff --git a/benchmark/process/queue-microtask-breadth.js b/benchmark/process/queue-microtask-breadth.js index 6d225cbd526f8a..610dfc584ef738 100644 --- a/benchmark/process/queue-microtask-breadth.js +++ b/benchmark/process/queue-microtask-breadth.js @@ -6,7 +6,7 @@ const bench = common.createBenchmark(main, { }); function main({ n }) { - var j = 0; + let j = 0; function cb() { j++; diff --git a/benchmark/querystring/querystring-parse.js b/benchmark/querystring/querystring-parse.js index ca4dca13bc14eb..2a5f3048de46b9 100644 --- a/benchmark/querystring/querystring-parse.js +++ b/benchmark/querystring/querystring-parse.js @@ -10,23 +10,23 @@ const bench = common.createBenchmark(main, { function main({ type, n }) { const input = inputs[type]; - var i; + // Execute the function a "sufficient" number of times before the timed // loop to ensure the function is optimized just once. if (type === 'multicharsep') { - for (i = 0; i < n; i += 1) + for (let i = 0; i < n; i += 1) querystring.parse(input, '&&&&&&&&&&'); bench.start(); - for (i = 0; i < n; i += 1) + for (let i = 0; i < n; i += 1) querystring.parse(input, '&&&&&&&&&&'); bench.end(n); } else { - for (i = 0; i < n; i += 1) + for (let i = 0; i < n; i += 1) querystring.parse(input); bench.start(); - for (i = 0; i < n; i += 1) + for (let i = 0; i < n; i += 1) querystring.parse(input); bench.end(n); } diff --git a/benchmark/streams/creation.js b/benchmark/streams/creation.js index 46a0a547907c45..760ab5c89dca96 100644 --- a/benchmark/streams/creation.js +++ b/benchmark/streams/creation.js @@ -13,14 +13,13 @@ const bench = common.createBenchmark(main, { }); function main({ n, kind }) { - var i = 0; switch (kind) { case 'duplex': new Duplex({}); new Duplex(); bench.start(); - for (; i < n; ++i) + for (let i = 0; i < n; ++i) new Duplex(); bench.end(n); break; @@ -29,7 +28,7 @@ function main({ n, kind }) { new Readable(); bench.start(); - for (; i < n; ++i) + for (let i = 0; i < n; ++i) new Readable(); bench.end(n); break; @@ -38,7 +37,7 @@ function main({ n, kind }) { new Writable(); bench.start(); - for (; i < n; ++i) + for (let i = 0; i < n; ++i) new Writable(); bench.end(n); break; @@ -47,7 +46,7 @@ function main({ n, kind }) { new Transform(); bench.start(); - for (; i < n; ++i) + for (let i = 0; i < n; ++i) new Transform(); bench.end(n); break; diff --git a/benchmark/streams/pipe-object-mode.js b/benchmark/streams/pipe-object-mode.js index d52b2238780ccb..33588819f00a6c 100644 --- a/benchmark/streams/pipe-object-mode.js +++ b/benchmark/streams/pipe-object-mode.js @@ -12,7 +12,7 @@ function main({ n }) { const r = new Readable({ objectMode: true }); const w = new Writable({ objectMode: true }); - var i = 0; + let i = 0; r._read = () => r.push(i++ === n ? null : b); w._write = (data, enc, cb) => cb(); diff --git a/benchmark/streams/pipe.js b/benchmark/streams/pipe.js index 4baeeb2d2e7706..0df1afdbe10134 100644 --- a/benchmark/streams/pipe.js +++ b/benchmark/streams/pipe.js @@ -12,7 +12,7 @@ function main({ n }) { const r = new Readable(); const w = new Writable(); - var i = 0; + let i = 0; r._read = () => r.push(i++ === n ? null : b); w._write = (data, enc, cb) => cb(); diff --git a/benchmark/streams/readable-bigread.js b/benchmark/streams/readable-bigread.js index c3cff3d933d915..1bd1dab4edb07f 100644 --- a/benchmark/streams/readable-bigread.js +++ b/benchmark/streams/readable-bigread.js @@ -14,8 +14,8 @@ function main({ n }) { s._read = noop; bench.start(); - for (var k = 0; k < n; ++k) { - for (var i = 0; i < 1e4; ++i) + for (let k = 0; k < n; ++k) { + for (let i = 0; i < 1e4; ++i) s.push(b); while (s.read(128)); } diff --git a/benchmark/streams/readable-bigunevenread.js b/benchmark/streams/readable-bigunevenread.js index 95a4139c069e87..684986a778aba2 100644 --- a/benchmark/streams/readable-bigunevenread.js +++ b/benchmark/streams/readable-bigunevenread.js @@ -14,8 +14,8 @@ function main({ n }) { s._read = noop; bench.start(); - for (var k = 0; k < n; ++k) { - for (var i = 0; i < 1e4; ++i) + for (let k = 0; k < n; ++k) { + for (let i = 0; i < 1e4; ++i) s.push(b); while (s.read(106)); } diff --git a/benchmark/streams/readable-boundaryread.js b/benchmark/streams/readable-boundaryread.js index 835c7d18b51285..edc90d04de161d 100644 --- a/benchmark/streams/readable-boundaryread.js +++ b/benchmark/streams/readable-boundaryread.js @@ -10,14 +10,14 @@ const bench = common.createBenchmark(main, { function main({ n, type }) { const s = new Readable(); - var data = 'a'.repeat(32); + let data = 'a'.repeat(32); if (type === 'buffer') data = Buffer.from(data); s._read = function() {}; bench.start(); - for (var k = 0; k < n; ++k) { - for (var i = 0; i < 1e4; ++i) + for (let k = 0; k < n; ++k) { + for (let i = 0; i < 1e4; ++i) s.push(data); while (s.read(32)); } diff --git a/benchmark/streams/readable-readall.js b/benchmark/streams/readable-readall.js index 3c177ec4c39988..d14fd7756586e9 100644 --- a/benchmark/streams/readable-readall.js +++ b/benchmark/streams/readable-readall.js @@ -14,8 +14,8 @@ function main({ n }) { s._read = noop; bench.start(); - for (var k = 0; k < n; ++k) { - for (var i = 0; i < 1e4; ++i) + for (let k = 0; k < n; ++k) { + for (let i = 0; i < 1e4; ++i) s.push(b); while (s.read()); } diff --git a/benchmark/streams/readable-unevenread.js b/benchmark/streams/readable-unevenread.js index 690f1f420838c6..9da8410131bfff 100644 --- a/benchmark/streams/readable-unevenread.js +++ b/benchmark/streams/readable-unevenread.js @@ -14,8 +14,8 @@ function main({ n }) { s._read = noop; bench.start(); - for (var k = 0; k < n; ++k) { - for (var i = 0; i < 1e4; ++i) + for (let k = 0; k < n; ++k) { + for (let i = 0; i < 1e4; ++i) s.push(b); while (s.read(12)); } diff --git a/benchmark/string_decoder/string-decoder.js b/benchmark/string_decoder/string-decoder.js index 0e34effbc7d964..afc0dde62e7937 100644 --- a/benchmark/string_decoder/string-decoder.js +++ b/benchmark/string_decoder/string-decoder.js @@ -14,12 +14,11 @@ const ASC_ALPHA = 'Blueberry jam'; const UTF16_BUF = Buffer.from('Blåbærsyltetøy', 'utf16le'); function main({ encoding, inLen, chunkLen, n }) { - var alpha; - var buf; + let alpha; + let buf; const chunks = []; - var str = ''; + let str = ''; const isBase64 = (encoding === 'base64-ascii' || encoding === 'base64-utf8'); - var i; if (encoding === 'ascii' || encoding === 'base64-ascii') alpha = ASC_ALPHA; @@ -33,7 +32,7 @@ function main({ encoding, inLen, chunkLen, n }) { const sd = new StringDecoder(isBase64 ? 'base64' : encoding); - for (i = 0; i < inLen; ++i) { + for (let i = 0; i < inLen; ++i) { if (i > 0 && (i % chunkLen) === 0 && !isBase64) { if (alpha) { chunks.push(Buffer.from(str, encoding)); @@ -46,8 +45,8 @@ function main({ encoding, inLen, chunkLen, n }) { if (alpha) str += alpha[i % alpha.length]; else { - var start = i; - var end = i + 2; + let start = i; + let end = i + 2; if (i % 2 !== 0) { ++start; ++end; @@ -77,8 +76,8 @@ function main({ encoding, inLen, chunkLen, n }) { const nChunks = chunks.length; bench.start(); - for (i = 0; i < n; ++i) { - for (var j = 0; j < nChunks; ++j) + for (let i = 0; i < n; ++i) { + for (let j = 0; j < nChunks; ++j) sd.write(chunks[j]); } bench.end(n);