Skip to content

Commit 716076e

Browse files
aduh95targos
authored andcommitted
tty: refactor to avoid unsafe array iteration
PR-URL: #36771 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Pooja D P <Pooja.D.P@ibm.com>
1 parent 0dea866 commit 716076e

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

lib/internal/tty.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
'use strict';
2424

2525
const {
26+
ArrayPrototypeSome,
2627
RegExpPrototypeTest,
2728
StringPrototypeSplit,
2829
StringPrototypeToLowerCase,
@@ -202,10 +203,9 @@ function getColorDepth(env = process.env) {
202203
if (TERM_ENVS[termEnv]) {
203204
return TERM_ENVS[termEnv];
204205
}
205-
for (const term of TERM_ENVS_REG_EXP) {
206-
if (RegExpPrototypeTest(term, termEnv)) {
207-
return COLORS_16;
208-
}
206+
if (ArrayPrototypeSome(TERM_ENVS_REG_EXP,
207+
(term) => RegExpPrototypeTest(term, termEnv))) {
208+
return COLORS_16;
209209
}
210210
}
211211
// Move 16 color COLORTERM below 16m and 256

lib/tty.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ WriteStream.prototype._refreshSize = function() {
133133
this.emit('error', errors.errnoException(err, 'getWindowSize'));
134134
return;
135135
}
136-
const [newCols, newRows] = winSize;
136+
const { 0: newCols, 1: newRows } = winSize;
137137
if (oldCols !== newCols || oldRows !== newRows) {
138138
this.columns = newCols;
139139
this.rows = newRows;

0 commit comments

Comments
 (0)