Skip to content

Commit ca096e5

Browse files
committed
fixup! zlib: avoid mutable push in sync output collection
Signed-off-by: Roberto Bianchi <roberto.bianchi@spendesk.com>
1 parent 20b02a5 commit ca096e5

1 file changed

Lines changed: 5 additions & 14 deletions

File tree

‎test/parallel/test-zlib-sync-array-push.js‎

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,18 @@ const zlib = require('zlib');
1111
const expected = fixtures.readSync('person.jpg');
1212
const compressed = fixtures.readSync('person.jpg.gz');
1313

14-
function gunzipWithInstrumentedPush(opts) {
14+
// Without options, the default chunk size still yields several chunks.
15+
// A small chunkSize goes through the options path and yields many chunks.
16+
for (const opts of [undefined, { chunkSize: 1024 }]) {
1517
const originalPush = Array.prototype.push;
16-
let chunkPushes = 0;
1718
let result;
18-
Array.prototype.push = function(...args) {
19-
if (args.some((arg) => arg instanceof Uint8Array))
20-
chunkPushes++;
21-
return Reflect.apply(originalPush, this, args);
19+
Array.prototype.push = function() {
20+
throw new Error('Array.prototype.push should not be called');
2221
};
2322
try {
2423
result = zlib.gunzipSync(compressed, opts);
2524
} finally {
2625
Array.prototype.push = originalPush;
2726
}
28-
return { result, chunkPushes };
29-
}
30-
31-
// Without options, the default chunk size still yields several chunks.
32-
// A small chunkSize goes through the options path and yields many chunks.
33-
for (const opts of [undefined, { chunkSize: 1024 }]) {
34-
const { result, chunkPushes } = gunzipWithInstrumentedPush(opts);
3527
assert.deepStrictEqual(result, expected);
36-
assert.strictEqual(chunkPushes, 0);
3728
}

0 commit comments

Comments
 (0)