deno.land / std@0.166.0 / node / _tools / test / parallel / test-buffer-failed-alloc-typed-arrays.js

test-buffer-failed-alloc-typed-arrays.js
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// deno-fmt-ignore-file// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.// Taken from Node 18.12.0// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
require('../common');const assert = require('assert');const SlowBuffer = require('buffer').SlowBuffer;
// Test failed or zero-sized Buffer allocations not affecting typed arrays.// This test exists because of a regression that occurred. Because Buffer// instances are allocated with the same underlying allocator as TypedArrays,// but Buffer's can optional be non-zero filled, there was a regression that// occurred when a Buffer allocated failed, the internal flag specifying// whether or not to zero-fill was not being reset, causing TypedArrays to// allocate incorrectly.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 { // Some of these allocations are known to fail. If they do, // Uint32Array should still produce a zeroed out result. allocator(size); } catch { assert.deepStrictEqual(zeroArray, new Uint32Array(10)); } }}
std

Version Info

Tagged at
a year ago