Skip to content

Commit 403b595

Browse files
aduh95ruyadorno
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 1ef92f6 commit 403b595

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,
@@ -803,8 +804,8 @@ function Brotli(opts, mode) {
803804
assert(mode === BROTLI_DECODE || mode === BROTLI_ENCODE);
804805

805806
TypedArrayPrototypeFill(brotliInitParamsArray, -1);
806-
if (opts && opts.params) {
807-
for (const origKey of ObjectKeys(opts.params)) {
807+
if (opts?.params) {
808+
ArrayPrototypeForEach(ObjectKeys(opts.params), (origKey) => {
808809
const key = +origKey;
809810
if (NumberIsNaN(key) || key < 0 || key > kMaxBrotliParam ||
810811
(brotliInitParamsArray[key] | 0) !== -1) {
@@ -817,7 +818,7 @@ function Brotli(opts, mode) {
817818
'number', opts.params[origKey]);
818819
}
819820
brotliInitParamsArray[key] = value;
820-
}
821+
});
821822
}
822823

823824
const handle = mode === BROTLI_DECODE ?

0 commit comments

Comments
 (0)