Skip to content

Commit

Permalink
test: add buffer testcase for resetting kZeroFill
Browse files Browse the repository at this point in the history
Test failed or zero-sized Buffer allocations not affecting subsequent
creations of typed arrays.

PR-URL: #7093
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
  • Loading branch information
ChALkeR authored and bnoordhuis committed Jun 2, 2016
1 parent 3a39963 commit fea3070
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/parallel/test-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1476,3 +1476,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);
}
}
}
}

0 comments on commit fea3070

Please sign in to comment.