From f2115a84bd2bc878e840255152cdb2fe117b0c77 Mon Sep 17 00:00:00 2001 From: Xavier Redondo Date: Tue, 12 Nov 2019 16:20:02 +0000 Subject: [PATCH 1/2] tls: change loop var to let --- lib/internal/tls.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/tls.js b/lib/internal/tls.js index 80f6d80e18ccc8..8bf9330352bd20 100644 --- a/lib/internal/tls.js +++ b/lib/internal/tls.js @@ -7,7 +7,7 @@ const { Object } = primordials; function parseCertString(s) { const out = Object.create(null); const parts = s.split('\n'); - for (var i = 0, len = parts.length; i < len; i++) { + for (let i = 0, len = parts.length; i < len; i++) { const sepIndex = parts[i].indexOf('='); if (sepIndex > 0) { const key = parts[i].slice(0, sepIndex); From b2bc3af61a562a95ffa01c069c65c7c1b4bff250 Mon Sep 17 00:00:00 2001 From: Xavier Redondo Date: Tue, 12 Nov 2019 16:21:47 +0000 Subject: [PATCH 2/2] url: change var to let and const --- lib/internal/url.js | 70 ++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/lib/internal/url.js b/lib/internal/url.js index fde643bea370c8..860fa4d7ad01b3 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -165,7 +165,7 @@ class URLSearchParams { // Need to use reflection APIs for full spec compliance. this[searchParams] = []; const keys = Reflect.ownKeys(init); - for (var i = 0; i < keys.length; i++) { + for (let i = 0; i < keys.length; i++) { const key = keys[i]; const desc = Reflect.getOwnPropertyDescriptor(init, key); if (desc !== undefined && desc.enumerable) { @@ -203,7 +203,7 @@ class URLSearchParams { const list = this[searchParams]; const output = []; - for (var i = 0; i < list.length; i += 2) + for (let i = 0; i < list.length; i += 2) output.push(`${innerInspect(list[i])} => ${innerInspect(list[i + 1])}`); const length = output.reduce( @@ -390,7 +390,7 @@ Object.defineProperties(URL.prototype, { ...options }; const ctx = this[context]; - var ret = ctx.scheme; + let ret = ctx.scheme; if (ctx.host !== null) { ret += '//'; const has_username = ctx.username !== ''; @@ -539,7 +539,7 @@ Object.defineProperties(URL.prototype, { configurable: true, get() { const ctx = this[context]; - var ret = ctx.host || ''; + let ret = ctx.host || ''; if (ctx.port !== null) ret += `:${ctx.port}`; return ret; @@ -707,13 +707,13 @@ function initSearchParams(url, init) { // Ref: https://url.spec.whatwg.org/#concept-urlencoded-parser function parseParams(qs) { const out = []; - var pairStart = 0; - var lastPos = 0; - var seenSep = false; - var buf = ''; - var encoded = false; - var encodeCheck = 0; - var i; + let pairStart = 0; + let lastPos = 0; + let seenSep = false; + let buf = ''; + let encoded = false; + let encodeCheck = 0; + let i; for (i = 0; i < qs.length; ++i) { const code = qs.charCodeAt(i); @@ -834,7 +834,7 @@ function serializeParams(array) { const firstEncodedValue = encodeStr(array[1], noEscape, paramHexTable); let output = `${firstEncodedParam}=${firstEncodedValue}`; - for (var i = 2; i < len; i += 2) { + for (let i = 2; i < len; i += 2) { const encodedParam = encodeStr(array[i], noEscape, paramHexTable); const encodedValue = encodeStr(array[i + 1], noEscape, paramHexTable); output += `&${encodedParam}=${encodedValue}`; @@ -876,7 +876,7 @@ function defineIDLClass(proto, classStr, obj) { function merge(out, start, mid, end, lBuffer, rBuffer) { const sizeLeft = mid - start; const sizeRight = end - mid; - var l, r, o; + let l, r, o; for (l = 0; l < sizeLeft; l++) lBuffer[l] = out[start + l]; @@ -926,7 +926,7 @@ defineIDLClass(URLSearchParams.prototype, 'URLSearchParams', { const list = this[searchParams]; name = toUSVString(name); - for (var i = 0; i < list.length;) { + for (let i = 0; i < list.length;) { const cur = list[i]; if (cur === name) { list.splice(i, 2); @@ -947,7 +947,7 @@ defineIDLClass(URLSearchParams.prototype, 'URLSearchParams', { const list = this[searchParams]; name = toUSVString(name); - for (var i = 0; i < list.length; i += 2) { + for (let i = 0; i < list.length; i += 2) { if (list[i] === name) { return list[i + 1]; } @@ -966,7 +966,7 @@ defineIDLClass(URLSearchParams.prototype, 'URLSearchParams', { const list = this[searchParams]; const values = []; name = toUSVString(name); - for (var i = 0; i < list.length; i += 2) { + for (let i = 0; i < list.length; i += 2) { if (list[i] === name) { values.push(list[i + 1]); } @@ -984,7 +984,7 @@ defineIDLClass(URLSearchParams.prototype, 'URLSearchParams', { const list = this[searchParams]; name = toUSVString(name); - for (var i = 0; i < list.length; i += 2) { + for (let i = 0; i < list.length; i += 2) { if (list[i] === name) { return true; } @@ -1007,8 +1007,8 @@ defineIDLClass(URLSearchParams.prototype, 'URLSearchParams', { // If there are any name-value pairs whose name is `name`, in `list`, set // the value of the first such name-value pair to `value` and remove the // others. - var found = false; - for (var i = 0; i < list.length;) { + let found = false; + for (let i = 0; i < list.length;) { const cur = list[i]; if (cur === name) { if (!found) { @@ -1042,10 +1042,10 @@ defineIDLClass(URLSearchParams.prototype, 'URLSearchParams', { // 100 is found through testing. // Simple stable in-place insertion sort // Derived from v8/src/js/array.js - for (var i = 2; i < len; i += 2) { - var curKey = a[i]; - var curVal = a[i + 1]; - var j; + for (let i = 2; i < len; i += 2) { + const curKey = a[i]; + const curVal = a[i + 1]; + let j; for (j = i - 2; j >= 0; j -= 2) { if (a[j] > curKey) { a[j + 2] = a[j]; @@ -1061,10 +1061,10 @@ defineIDLClass(URLSearchParams.prototype, 'URLSearchParams', { // Bottom-up iterative stable merge sort const lBuffer = new Array(len); const rBuffer = new Array(len); - for (var step = 2; step < len; step *= 2) { - for (var start = 0; start < len - 2; start += 2 * step) { - var mid = start + step; - var end = mid + step; + for (let step = 2; step < len; step *= 2) { + for (let start = 0; start < len - 2; start += 2 * step) { + const mid = start + step; + let end = mid + step; end = end < len ? end : len; if (mid > end) continue; @@ -1097,7 +1097,7 @@ defineIDLClass(URLSearchParams.prototype, 'URLSearchParams', { let list = this[searchParams]; - var i = 0; + let i = 0; while (i < list.length) { const key = list[i]; const value = list[i + 1]; @@ -1279,10 +1279,10 @@ const forwardSlashRegEx = /\//g; function getPathFromURLWin32(url) { const hostname = url.hostname; - var pathname = url.pathname; - for (var n = 0; n < pathname.length; n++) { + let pathname = url.pathname; + for (let n = 0; n < pathname.length; n++) { if (pathname[n] === '%') { - var third = pathname.codePointAt(n + 2) | 0x20; + const third = pathname.codePointAt(n + 2) | 0x20; if ((pathname[n + 1] === '2' && third === 102) || // 2f 2F / (pathname[n + 1] === '5' && third === 99)) { // 5c 5C \ throw new ERR_INVALID_FILE_URL_PATH( @@ -1303,8 +1303,8 @@ function getPathFromURLWin32(url) { return `\\\\${domainToUnicode(hostname)}${pathname}`; } else { // Otherwise, it's a local path that requires a drive letter - var letter = pathname.codePointAt(1) | 0x20; - var sep = pathname[2]; + const letter = pathname.codePointAt(1) | 0x20; + const sep = pathname[2]; if (letter < CHAR_LOWERCASE_A || letter > CHAR_LOWERCASE_Z || // a..z A..Z (sep !== ':')) { throw new ERR_INVALID_FILE_URL_PATH('must be absolute'); @@ -1318,9 +1318,9 @@ function getPathFromURLPosix(url) { throw new ERR_INVALID_FILE_URL_HOST(platform); } const pathname = url.pathname; - for (var n = 0; n < pathname.length; n++) { + for (let n = 0; n < pathname.length; n++) { if (pathname[n] === '%') { - var third = pathname.codePointAt(n + 2) | 0x20; + const third = pathname.codePointAt(n + 2) | 0x20; if (pathname[n + 1] === '2' && third === 102) { throw new ERR_INVALID_FILE_URL_PATH( 'must not include encoded / characters'