blob: 851011032f276d3652b7d554dbd41a4a29e9a421 (
plain)
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
42
43
|
// |jit-test| --enable-arraybuffer-resizable; skip-if: !ArrayBuffer.prototype.resize
load(libdir + "asserts.js");
function testResizableArrayBuffer() {
for (let i = 0; i < 4; ++i) {
let ab = new ArrayBuffer(i, {maxByteLength: i + 1});
let ta = new DataView(ab, 0, i);
for (let j = 0; j < 100; ++j) {
ab.resize(i);
assertEq(ta.byteLength, i);
ab.resize(i + 1);
assertEq(ta.byteLength, i);
if (i > 0) {
ab.resize(i - 1);
assertThrowsInstanceOf(() => ta.byteLength, TypeError);
}
}
}
}
for (let i = 0; i < 2; ++i) testResizableArrayBuffer();
function testResizableArrayBufferAutoLength() {
for (let i = 0; i < 4; ++i) {
let ab = new ArrayBuffer(i, {maxByteLength: i + 1});
let ta = new DataView(ab);
for (let j = 0; j < 100; ++j) {
ab.resize(i);
assertEq(ta.byteLength, i);
ab.resize(i + 1);
assertEq(ta.byteLength, i + 1);
if (i > 0) {
ab.resize(i - 1);
assertEq(ta.byteLength, i - 1);
}
}
}
}
for (let i = 0; i < 2; ++i) testResizableArrayBufferAutoLength();
|