From 716076e389e8ed9f8fea750c581996ab7f9fe258 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Thu, 31 Dec 2020 12:40:50 +0100 Subject: [PATCH] tty: refactor to avoid unsafe array iteration PR-URL: https://github.com/nodejs/node/pull/36771 Reviewed-By: Rich Trott Reviewed-By: Pooja D P --- lib/internal/tty.js | 8 ++++---- lib/tty.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/internal/tty.js b/lib/internal/tty.js index 2852cfb1bbfe29..f4f05f971c2713 100644 --- a/lib/internal/tty.js +++ b/lib/internal/tty.js @@ -23,6 +23,7 @@ 'use strict'; const { + ArrayPrototypeSome, RegExpPrototypeTest, StringPrototypeSplit, StringPrototypeToLowerCase, @@ -202,10 +203,9 @@ function getColorDepth(env = process.env) { if (TERM_ENVS[termEnv]) { return TERM_ENVS[termEnv]; } - for (const term of TERM_ENVS_REG_EXP) { - if (RegExpPrototypeTest(term, termEnv)) { - return COLORS_16; - } + if (ArrayPrototypeSome(TERM_ENVS_REG_EXP, + (term) => RegExpPrototypeTest(term, termEnv))) { + return COLORS_16; } } // Move 16 color COLORTERM below 16m and 256 diff --git a/lib/tty.js b/lib/tty.js index 1828077c0adc0c..e61a5c3ac3f905 100644 --- a/lib/tty.js +++ b/lib/tty.js @@ -133,7 +133,7 @@ WriteStream.prototype._refreshSize = function() { this.emit('error', errors.errnoException(err, 'getWindowSize')); return; } - const [newCols, newRows] = winSize; + const { 0: newCols, 1: newRows } = winSize; if (oldCols !== newCols || oldRows !== newRows) { this.columns = newCols; this.rows = newRows;