From fea3070ec46d8d231b95ff100170d16306814ee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BA=D0=BE=D0=B2=D0=BE=D1=80=D0=BE=D0=B4=D0=B0=20?= =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=90=D0=BD=D0=B4=D1=80?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2=D0=B8=D1=87?= Date: Wed, 1 Jun 2016 17:32:02 +0300 Subject: [PATCH] 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/7093 Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell Reviewed-By: Trevor Norris --- test/parallel/test-buffer.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/parallel/test-buffer.js b/test/parallel/test-buffer.js index 02f9443696..f773da321d 100644 --- a/test/parallel/test-buffer.js +++ b/test/parallel/test-buffer.js @@ -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); + } + } + } +}