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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
// |jit-test| --enable-arraybuffer-resizable; skip-if: !ArrayBuffer.prototype.resize
load(libdir + "asserts.js");
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.byteOffset, 0);
ab.resize(i + 1);
assertEq(ta.byteOffset, 0);
if (i > 0) {
ab.resize(i - 1);
assertEq(ta.byteOffset, 0);
}
}
}
}
for (let i = 0; i < 2; ++i) testResizableArrayBufferAutoLength();
function testResizableArrayBufferAutoLengthNonZeroOffset() {
for (let i = 1; i < 4 + 1; ++i) {
let ab = new ArrayBuffer(i, {maxByteLength: i + 1});
let ta = new DataView(ab, 1);
for (let j = 0; j < 100; ++j) {
ab.resize(i);
assertEq(ta.byteOffset, 1);
ab.resize(i + 1);
assertEq(ta.byteOffset, 1);
ab.resize(i - 1);
if (i > 1) {
assertEq(ta.byteOffset, 1);
} else {
assertThrowsInstanceOf(() => ta.byteOffset, TypeError);
}
}
}
}
for (let i = 0; i < 2; ++i) testResizableArrayBufferAutoLengthNonZeroOffset();
function testResizableArrayBufferNonZeroOffset() {
for (let i = 2; i < 4 + 2; ++i) {
let ab = new ArrayBuffer(i, {maxByteLength: i + 1});
let ta = new DataView(ab, 1, 1);
for (let j = 0; j < 100; ++j) {
ab.resize(i);
assertEq(ta.byteOffset, 1);
ab.resize(i + 1);
assertEq(ta.byteOffset, 1);
ab.resize(i - 1);
if (i > 2) {
assertEq(ta.byteOffset, 1);
} else {
assertThrowsInstanceOf(() => ta.byteOffset, TypeError);
}
}
}
}
for (let i = 0; i < 2; ++i) testResizableArrayBufferNonZeroOffset();
|