Skip to content

Commit 459fe68

Browse files
aduh95targos
authored andcommitted
zlib: refactor to avoid unsafe array iteration
PR-URL: #36722 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Pooja D P <[email protected]>
1 parent cf9556d commit 459fe68

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/zlib.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
const {
2525
ArrayBuffer,
26+
ArrayPrototypeForEach,
2627
ArrayPrototypeMap,
2728
ArrayPrototypePush,
2829
Error,
@@ -798,8 +799,8 @@ function Brotli(opts, mode) {
798799
assert(mode === BROTLI_DECODE || mode === BROTLI_ENCODE);
799800

800801
TypedArrayPrototypeFill(brotliInitParamsArray, -1);
801-
if (opts && opts.params) {
802-
for (const origKey of ObjectKeys(opts.params)) {
802+
if (opts?.params) {
803+
ArrayPrototypeForEach(ObjectKeys(opts.params), (origKey) => {
803804
const key = +origKey;
804805
if (NumberIsNaN(key) || key < 0 || key > kMaxBrotliParam ||
805806
(brotliInitParamsArray[key] | 0) !== -1) {
@@ -812,7 +813,7 @@ function Brotli(opts, mode) {
812813
'number', opts.params[origKey]);
813814
}
814815
brotliInitParamsArray[key] = value;
815-
}
816+
});
816817
}
817818

818819
const handle = mode === BROTLI_DECODE ?

0 commit comments

Comments
 (0)