mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 00:20:08 +01:00
test: add buffer testcase for resetting kZeroFill
Test failed or zero-sized Buffer allocations not affecting subsequent creations of typed arrays. PR-URL: https://github.com/nodejs/node/pull/7169 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
parent
0ca0827b71
commit
03d36aea4f
|
|
@ -1449,3 +1449,26 @@ assert.equal(SlowBuffer.prototype.offset, undefined);
|
|||
// Check pool offset after that by trying to write string into the pool.
|
||||
assert.doesNotThrow(() => Buffer.from('abc'));
|
||||
}
|
||||
|
||||
|
||||
// Test failed or zero-sized Buffer allocations not affecting typed arrays
|
||||
{
|
||||
const zeroArray = new Uint32Array(10).fill(0);
|
||||
const sizes = [1e10, 0, 0.1, -1, 'a', undefined, null, NaN];
|
||||
const allocators = [
|
||||
Buffer,
|
||||
SlowBuffer,
|
||||
Buffer.alloc,
|
||||
Buffer.allocUnsafe,
|
||||
Buffer.allocUnsafeSlow
|
||||
];
|
||||
for (const allocator of allocators) {
|
||||
for (const size of sizes) {
|
||||
try {
|
||||
allocator(size);
|
||||
} catch (e) {
|
||||
assert.deepStrictEqual(new Uint32Array(10), zeroArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user