1 // Get early out-of-bound data.
2 function opaqueGetByValOnInt32ArrayEarlyOutOfBounds(array
, index
)
6 noInline(opaqueGetByValOnInt32ArrayEarlyOutOfBounds
);
8 function testInt32ArrayEarlyOutOfBounds()
10 // Warm up with an immediate out of bounds.
11 var int32Array
= [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
12 for (var i
= 0; i
<= 10; ++i
) {
13 var value
= opaqueGetByValOnInt32ArrayEarlyOutOfBounds(int32Array
, i
);
14 if ((i
< 10 && value
!== i
) || (i
>= 10 && value
!== undefined))
15 throw "Failed opaqueGetByValOnInt32ArrayEarlyOutOfBounds(int32Array, i) warmup with i = " + i
+ " value = " + value
;
18 // We then do plenty of in-bounds accesses.
19 for (var i
= 0; i
< 1e4
; ++i
) {
20 for (var j
= 0; j
< 10; ++j
) {
21 var value
= opaqueGetByValOnInt32ArrayEarlyOutOfBounds(int32Array
, j
);
22 if (j
< 10 && value
!== j
)
23 throw "Failed opaqueGetByValOnInt32ArrayEarlyOutOfBounds(int32Array, j) in-bounds with j = " + j
+ " value = " + value
;
27 // Followed by plenty of out-of-bounds accesses.
28 for (var i
= 0; i
< 1e4
; ++i
) {
29 for (var j
= 0; j
<= 10; ++j
) {
30 var value
= opaqueGetByValOnInt32ArrayEarlyOutOfBounds(int32Array
, j
);
31 if ((j
< 10 && value
!== j
) || (j
>= 10 && value
!== undefined))
32 throw "Failed opaqueGetByValOnInt32ArrayEarlyOutOfBounds(int32Array, j) out-of-bounds with j = " + j
+ " value = " + value
;
36 testInt32ArrayEarlyOutOfBounds();
38 // One more access, with a completely different array type.
39 function testIndexingTypeChangesOnInt32Array()
41 var doubleArray
= [-0, 5.5, -42.1];
42 var value
= opaqueGetByValOnInt32ArrayEarlyOutOfBounds(doubleArray
, 0);
43 if (value
|| 1 / value
!== -Infinity
)
44 throw "Failed opaqueGetByValOnInt32ArrayEarlyOutOfBounds(doubleArray, 0)";
45 var value
= opaqueGetByValOnInt32ArrayEarlyOutOfBounds(doubleArray
, 1);
47 throw "Failed opaqueGetByValOnInt32ArrayEarlyOutOfBounds(doubleArray, 1)";
48 var value
= opaqueGetByValOnInt32ArrayEarlyOutOfBounds(doubleArray
, 2);
50 throw "Failed opaqueGetByValOnInt32ArrayEarlyOutOfBounds(doubleArray, 2)";
52 testIndexingTypeChangesOnInt32Array();
56 // Get out-of-bound data after a thousand run.
57 function opaqueGetByValOnStringArrayHotOutOfBounds(array
, index
)
61 noInline(opaqueGetByValOnStringArrayHotOutOfBounds
);
63 function testStringArrayHotOutOfBounds()
65 // Warm up with in bounds access.
66 var stringArray
= ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
67 for (var i
= 0; i
< 1e2
; ++i
) {
68 for (var j
= 0; j
< 10; ++j
) {
69 var value
= opaqueGetByValOnStringArrayHotOutOfBounds(stringArray
, j
);
71 throw "Failed opaqueGetByValOnStringArrayHotOutOfBounds(stringArray, j) in-bounds with j = " + j
+ " value = " + value
;
75 // Do a single out of bounds after warmup.
76 var value
= opaqueGetByValOnStringArrayHotOutOfBounds(stringArray
, 10);
77 if (value
!== undefined)
78 throw "Failed opaqueGetByValOnStringArrayHotOutOfBounds(stringArray, 10) with i = " + i
+ " value = " + value
;
80 // We then do plenty of in-bounds accesses.
81 for (var i
= 0; i
< 1e3
; ++i
) {
82 for (var j
= 0; j
< 10; ++j
) {
83 var value
= opaqueGetByValOnStringArrayHotOutOfBounds(stringArray
, j
);
85 throw "Failed opaqueGetByValOnStringArrayHotOutOfBounds(stringArray, j) in-bounds with j = " + j
+ " value = " + value
;
89 // Followed by plenty of out-of-bounds accesses.
90 for (var i
= 0; i
< 1e3
; ++i
) {
91 for (var j
= 0; j
<= 10; ++j
) {
92 var value
= opaqueGetByValOnStringArrayHotOutOfBounds(stringArray
, j
);
93 if ((j
< 10 && value
!== "" + j
) || (j
>= 10 && value
!== undefined))
94 throw "Failed opaqueGetByValOnStringArrayHotOutOfBounds(stringArray, j) out-of-bounds with j = " + j
+ " value = " + value
;
98 testStringArrayHotOutOfBounds();
100 function testIndexingTypeChangesOnStringArray()
102 var doubleArray
= [-0, 5.5, -42.1];
103 var value
= opaqueGetByValOnStringArrayHotOutOfBounds(doubleArray
, 0);
104 if (value
|| 1 / value
!== -Infinity
)
105 throw "Failed opaqueGetByValOnStringArrayHotOutOfBounds(doubleArray, 0)";
106 var value
= opaqueGetByValOnStringArrayHotOutOfBounds(doubleArray
, 1);
108 throw "Failed opaqueGetByValOnStringArrayHotOutOfBounds(doubleArray, 1)";
109 var value
= opaqueGetByValOnStringArrayHotOutOfBounds(doubleArray
, 2);
111 throw "Failed opaqueGetByValOnStringArrayHotOutOfBounds(doubleArray, 2)";
113 testIndexingTypeChangesOnStringArray();
117 // Get out-of-bound data after a thousand run, but from a different array type.
118 function opaqueGetByValOnStringAndInt32ArrayHotOutOfBounds(array
, index
)
122 noInline(opaqueGetByValOnStringAndInt32ArrayHotOutOfBounds
);
124 function testStringAndInt32ArrayHotOutOfBounds()
126 // Warm up with in bounds access.
127 var stringArray
= ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
128 for (var i
= 0; i
< 1e2
; ++i
) {
129 for (var j
= 0; j
< 10; ++j
) {
130 var value
= opaqueGetByValOnStringAndInt32ArrayHotOutOfBounds(stringArray
, j
);
131 if (value
!== "" + j
)
132 throw "Failed opaqueGetByValOnStringAndInt32ArrayHotOutOfBounds(stringArray, j) in-bounds with j = " + j
+ " value = " + value
;
136 // Do a single out of bounds after warmup.
137 var int32Array
= [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
138 var value
= opaqueGetByValOnStringAndInt32ArrayHotOutOfBounds(int32Array
, 10);
139 if (value
!== undefined)
140 throw "Failed opaqueGetByValOnStringAndInt32ArrayHotOutOfBounds(stringArray, 10) with i = " + i
+ " value = " + value
;
142 // We then do plenty of in-bounds accesses.
143 for (var i
= 0; i
< 1e3
; ++i
) {
144 for (var j
= 0; j
< 10; ++j
) {
145 var value
= opaqueGetByValOnStringAndInt32ArrayHotOutOfBounds(stringArray
, j
);
146 if (value
!== "" + j
)
147 throw "Failed opaqueGetByValOnStringAndInt32ArrayHotOutOfBounds(stringArray, j) in-bounds with j = " + j
+ " value = " + value
;
149 var value
= opaqueGetByValOnStringAndInt32ArrayHotOutOfBounds(int32Array
, j
);
151 throw "Failed opaqueGetByValOnStringAndInt32ArrayHotOutOfBounds(int32Array, j) in-bounds with j = " + j
+ " value = " + value
;
155 // Followed by plenty of out-of-bounds accesses.
156 for (var i
= 0; i
< 1e3
; ++i
) {
157 for (var j
= 0; j
<= 10; ++j
) {
158 var value
= opaqueGetByValOnStringAndInt32ArrayHotOutOfBounds(int32Array
, j
);
159 if ((j
< 10 && value
!== j
) || (j
>= 10 && value
!== undefined))
160 throw "Failed opaqueGetByValOnStringAndInt32ArrayHotOutOfBounds(int32Array, j) out-of-bounds with j = " + j
+ " value = " + value
;
162 var value
= opaqueGetByValOnStringAndInt32ArrayHotOutOfBounds(stringArray
, j
);
163 if ((j
< 10 && value
!== "" + j
) || (j
>= 10 && value
!== undefined))
164 throw "Failed opaqueGetByValOnStringAndInt32ArrayHotOutOfBounds(stringArray, j) out-of-bounds with j = " + j
+ " value = " + value
;
168 testStringAndInt32ArrayHotOutOfBounds();
171 // Get out-of-bound data from a hole after a thousand run.
172 function opaqueGetByValOnDoubleArrayHotOutOfBounds(array
, index
)
176 noInline(opaqueGetByValOnDoubleArrayHotOutOfBounds
);
178 function testStringArrayHotOutOfBounds()
180 // Warm up with in bounds access.
181 var doubleArray
= new Array(10);
182 for (var i
= 0; i
< 10; ++i
) {
184 doubleArray
[i
] = i
+ 0.5;
186 for (var i
= 0; i
< 1e2
; ++i
) {
187 for (var j
= 0; j
< 10; ++j
) {
189 var value
= opaqueGetByValOnDoubleArrayHotOutOfBounds(doubleArray
, j
);
190 if (value
!== j
+ 0.5)
191 throw "Failed opaqueGetByValOnDoubleArrayHotOutOfBounds(doubleArray, j) in-bounds with j = " + j
+ " value = " + value
;
196 // Do a single out of bounds after warmup.
197 var value
= opaqueGetByValOnDoubleArrayHotOutOfBounds(doubleArray
, 5);
198 if (value
!== undefined)
199 throw "Failed opaqueGetByValOnDoubleArrayHotOutOfBounds(doubleArray, 5) with i = " + i
+ " value = " + value
;
201 // We then do plenty of in-bounds accesses.
202 for (var i
= 0; i
< 1e3
; ++i
) {
203 for (var j
= 0; j
< 10; ++j
) {
205 var value
= opaqueGetByValOnDoubleArrayHotOutOfBounds(doubleArray
, j
);
206 if (value
!== j
+ 0.5)
207 throw "Failed opaqueGetByValOnDoubleArrayHotOutOfBounds(doubleArray, j) in-bounds with j = " + j
+ " value = " + value
;
212 // Followed by plenty of out-of-bounds accesses.
213 for (var i
= 0; i
< 1e3
; ++i
) {
214 for (var j
= 0; j
< 10; ++j
) {
215 var value
= opaqueGetByValOnDoubleArrayHotOutOfBounds(doubleArray
, j
);
216 if ((j
!== 5 && value
!== j
+ 0.5) || (j
=== 10 && value
!== undefined))
217 throw "Failed opaqueGetByValOnDoubleArrayHotOutOfBounds(doubleArray, j) out-of-bounds with j = " + j
+ " value = " + value
;
221 testStringArrayHotOutOfBounds();