Skip to content

Commit 03d36ae

Browse files
committed
test: add buffer testcase for resetting kZeroFill
Test failed or zero-sized Buffer allocations not affecting subsequent creations of typed arrays. PR-URL: #7169 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 0ca0827 commit 03d36ae

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

test/parallel/test-buffer.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,3 +1449,26 @@ assert.equal(SlowBuffer.prototype.offset, undefined);
14491449
// Check pool offset after that by trying to write string into the pool.
14501450
assert.doesNotThrow(() => Buffer.from('abc'));
14511451
}
1452+
1453+
1454+
// Test failed or zero-sized Buffer allocations not affecting typed arrays
1455+
{
1456+
const zeroArray = new Uint32Array(10).fill(0);
1457+
const sizes = [1e10, 0, 0.1, -1, 'a', undefined, null, NaN];
1458+
const allocators = [
1459+
Buffer,
1460+
SlowBuffer,
1461+
Buffer.alloc,
1462+
Buffer.allocUnsafe,
1463+
Buffer.allocUnsafeSlow
1464+
];
1465+
for (const allocator of allocators) {
1466+
for (const size of sizes) {
1467+
try {
1468+
allocator(size);
1469+
} catch (e) {
1470+
assert.deepStrictEqual(new Uint32Array(10), zeroArray);
1471+
}
1472+
}
1473+
}
1474+
}

0 commit comments

Comments
 (0)