Skip to content

Commit fea3070

Browse files
ChALkeRbnoordhuis
authored andcommitted
test: add buffer testcase for resetting kZeroFill
Test failed or zero-sized Buffer allocations not affecting subsequent creations of typed arrays. PR-URL: #7093 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
1 parent 3a39963 commit fea3070

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
@@ -1476,3 +1476,26 @@ assert.equal(SlowBuffer.prototype.offset, undefined);
14761476
// Check pool offset after that by trying to write string into the pool.
14771477
assert.doesNotThrow(() => Buffer.from('abc'));
14781478
}
1479+
1480+
1481+
// Test failed or zero-sized Buffer allocations not affecting typed arrays
1482+
{
1483+
const zeroArray = new Uint32Array(10).fill(0);
1484+
const sizes = [1e10, 0, 0.1, -1, 'a', undefined, null, NaN];
1485+
const allocators = [
1486+
Buffer,
1487+
SlowBuffer,
1488+
Buffer.alloc,
1489+
Buffer.allocUnsafe,
1490+
Buffer.allocUnsafeSlow
1491+
];
1492+
for (const allocator of allocators) {
1493+
for (const size of sizes) {
1494+
try {
1495+
allocator(size);
1496+
} catch (e) {
1497+
assert.deepStrictEqual(new Uint32Array(10), zeroArray);
1498+
}
1499+
}
1500+
}
1501+
}

0 commit comments

Comments
 (0)