Debian Codegraph @

js/src/jit-test/tests/typedarray/arraybuffer-zero-length-alignment-check.js

raw
1 // Iterate a few times to increase the likelihood for malloc(0) to return a
2 // non-aligned memory.
3 for (let i = 0; i < 100; ++i) {
4 // Create a zero-length buffer with malloc'ed memory.
5 let ab = createExternalArrayBuffer(0);
6
7 // Create a typed array which requires 8-byte alignment.
8 let source = new Float64Array(ab);
9
10 // This call shouldn't assert when copying zero bytes from |source|, even when
11 // the memory is non-aligned.
12 let target = new Float64Array(source);
13
14 // Add some uses of the objects.
15 assertEq(ab.byteLength, 0);
16 assertEq(source.byteLength, 0);
17 assertEq(target.byteLength, 0);
18 }
19
20 // Repeat the above tests with the |createUserArrayBuffer| testing function.
21 for (let i = 0; i < 100; ++i) {
22 let ab = createUserArrayBuffer(0);
23 let source = new Float64Array(ab);
24 let target = new Float64Array(source);
25
26 assertEq(ab.byteLength, 0);
27 assertEq(source.byteLength, 0);
28 assertEq(target.byteLength, 0);
29 }