Skip to content

Commit 956dec8

Browse files
trivikrMylesBorins
authored andcommitted
tls: for...of in _tls_common.js
PR-URL: #30961 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent e10917f commit 956dec8

File tree

3 files changed

+14
-22
lines changed

3 files changed

+14
-22
lines changed

lib/_tls_common.js

+6-12
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,12 @@ exports.createSecureContext = function createSecureContext(options) {
100100

101101
const c = new SecureContext(options.secureProtocol, secureOptions,
102102
options.minVersion, options.maxVersion);
103-
let i;
104-
let val;
105103

106104
// Add CA before the cert to be able to load cert's issuer in C++ code.
107105
const { ca } = options;
108106
if (ca) {
109107
if (ArrayIsArray(ca)) {
110-
for (i = 0; i < ca.length; ++i) {
111-
val = ca[i];
108+
for (const val of ca) {
112109
validateKeyOrCertOption('ca', val);
113110
c.context.addCACert(val);
114111
}
@@ -123,8 +120,7 @@ exports.createSecureContext = function createSecureContext(options) {
123120
const { cert } = options;
124121
if (cert) {
125122
if (ArrayIsArray(cert)) {
126-
for (i = 0; i < cert.length; ++i) {
127-
val = cert[i];
123+
for (const val of cert) {
128124
validateKeyOrCertOption('cert', val);
129125
c.context.setCert(val);
130126
}
@@ -142,8 +138,7 @@ exports.createSecureContext = function createSecureContext(options) {
142138
const passphrase = options.passphrase;
143139
if (key) {
144140
if (ArrayIsArray(key)) {
145-
for (i = 0; i < key.length; ++i) {
146-
val = key[i];
141+
for (const val of key) {
147142
// eslint-disable-next-line eqeqeq
148143
const pem = (val != undefined && val.pem !== undefined ? val.pem : val);
149144
validateKeyOrCertOption('key', pem);
@@ -242,8 +237,8 @@ exports.createSecureContext = function createSecureContext(options) {
242237

243238
if (options.crl) {
244239
if (ArrayIsArray(options.crl)) {
245-
for (i = 0; i < options.crl.length; i++) {
246-
c.context.addCRL(options.crl[i]);
240+
for (const crl of options.crl) {
241+
c.context.addCRL(crl);
247242
}
248243
} else {
249244
c.context.addCRL(options.crl);
@@ -259,8 +254,7 @@ exports.createSecureContext = function createSecureContext(options) {
259254
toBuf = require('internal/crypto/util').toBuf;
260255

261256
if (ArrayIsArray(options.pfx)) {
262-
for (i = 0; i < options.pfx.length; i++) {
263-
const pfx = options.pfx[i];
257+
for (const pfx of options.pfx) {
264258
const raw = pfx.buf ? pfx.buf : pfx;
265259
const buf = toBuf(raw);
266260
const passphrase = pfx.passphrase || options.passphrase;

lib/_tls_wrap.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,9 @@ function makeMethodProxy(name) {
465465
return this._parent[name].apply(this._parent, args);
466466
};
467467
}
468-
for (let n = 0; n < proxiedMethods.length; n++) {
469-
tls_wrap.TLSWrap.prototype[proxiedMethods[n]] =
470-
makeMethodProxy(proxiedMethods[n]);
468+
for (const proxiedMethod of proxiedMethods) {
469+
tls_wrap.TLSWrap.prototype[proxiedMethod] =
470+
makeMethodProxy(proxiedMethod);
471471
}
472472

473473
tls_wrap.TLSWrap.prototype.close = function close(cb) {
@@ -1303,8 +1303,7 @@ Server.prototype[EE.captureRejectionSymbol] = function(
13031303
function SNICallback(servername, callback) {
13041304
const contexts = this.server._contexts;
13051305

1306-
for (let i = 0; i < contexts.length; i++) {
1307-
const elem = contexts[i];
1306+
for (const elem of contexts) {
13081307
if (elem[0].test(servername)) {
13091308
callback(null, elem[1]);
13101309
return;

lib/internal/tls.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ const {
99
// C=US\nST=CA\nL=SF\nO=Joyent\nOU=Node.js\nCN=ca1\nemailAddress=ry@clouds.org
1010
function parseCertString(s) {
1111
const out = ObjectCreate(null);
12-
const parts = s.split('\n');
13-
for (let i = 0, len = parts.length; i < len; i++) {
14-
const sepIndex = parts[i].indexOf('=');
12+
for (const part of s.split('\n')) {
13+
const sepIndex = part.indexOf('=');
1514
if (sepIndex > 0) {
16-
const key = parts[i].slice(0, sepIndex);
17-
const value = parts[i].slice(sepIndex + 1);
15+
const key = part.slice(0, sepIndex);
16+
const value = part.slice(sepIndex + 1);
1817
if (key in out) {
1918
if (!ArrayIsArray(out[key])) {
2019
out[key] = [out[key]];

0 commit comments

Comments
 (0)