From f24fc3e20cc1c45ad1d3f834344e4b396f169a62 Mon Sep 17 00:00:00 2001 From: yorkie Date: Mon, 26 Sep 2016 11:59:01 +0800 Subject: [PATCH] tls: improve createSecureContext in _tls_common - this shares the iterator variable `i` expictly. - this converts some var to const. PR-URL: https://github.com/nodejs/node/pull/8781 Reviewed-By: Brian White Reviewed-By: James M Snell --- lib/_tls_common.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/_tls_common.js b/lib/_tls_common.js index d75b9ffe28..6e98c1ee4d 100644 --- a/lib/_tls_common.js +++ b/lib/_tls_common.js @@ -43,6 +43,7 @@ exports.createSecureContext = function createSecureContext(options, context) { secureOptions |= SSL_OP_CIPHER_SERVER_PREFERENCE; var c = new SecureContext(options.secureProtocol, secureOptions, context); + var i; if (context) return c; @@ -50,7 +51,7 @@ exports.createSecureContext = function createSecureContext(options, context) { // cert's issuer in C++ code. if (options.ca) { if (Array.isArray(options.ca)) { - for (let i = 0, len = options.ca.length; i < len; i++) { + for (i = 0; i < options.ca.length; i++) { c.context.addCACert(options.ca[i]); } } else { @@ -62,7 +63,7 @@ exports.createSecureContext = function createSecureContext(options, context) { if (options.cert) { if (Array.isArray(options.cert)) { - for (let i = 0; i < options.cert.length; i++) + for (i = 0; i < options.cert.length; i++) c.context.setCert(options.cert[i]); } else { c.context.setCert(options.cert); @@ -75,9 +76,8 @@ exports.createSecureContext = function createSecureContext(options, context) { // which leads to the crash later on. if (options.key) { if (Array.isArray(options.key)) { - for (let i = 0; i < options.key.length; i++) { - var key = options.key[i]; - + for (i = 0; i < options.key.length; i++) { + const key = options.key[i]; if (key.passphrase) c.context.setKey(key.pem, key.passphrase); else @@ -103,14 +103,14 @@ exports.createSecureContext = function createSecureContext(options, context) { c.context.setECDHCurve(options.ecdhCurve); if (options.dhparam) { - var warning = c.context.setDHParam(options.dhparam); + const warning = c.context.setDHParam(options.dhparam); if (warning) internalUtil.trace(warning); } if (options.crl) { if (Array.isArray(options.crl)) { - for (let i = 0, len = options.crl.length; i < len; i++) { + for (i = 0; i < options.crl.length; i++) { c.context.addCRL(options.crl[i]); } } else {