OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 } else { | 42 } else { |
43 print("Tests do NOT include smi-only arrays."); | 43 print("Tests do NOT include smi-only arrays."); |
44 } | 44 } |
45 | 45 |
46 // IC and Crankshaft support for smi-only elements in dynamic array literals. | 46 // IC and Crankshaft support for smi-only elements in dynamic array literals. |
47 function get(foo) { return foo; } // Used to generate dynamic values. | 47 function get(foo) { return foo; } // Used to generate dynamic values. |
48 | 48 |
49 function array_natives_test() { | 49 function array_natives_test() { |
50 | 50 |
51 // Ensure small array literals start in specific element kind mode. | 51 // Ensure small array literals start in specific element kind mode. |
52 assertTrue(%HasFastSmiElements([])); | 52 assertTrue(%HasFastObjectElements([])); |
53 assertTrue(%HasFastSmiElements([1])); | 53 assertTrue(%HasFastSmiElements([1])); |
54 assertTrue(%HasFastSmiElements([1,2])); | 54 assertTrue(%HasFastSmiElements([1,2])); |
55 assertTrue(%HasFastDoubleElements([1.1])); | 55 assertTrue(%HasFastDoubleElements([1.1])); |
56 assertTrue(%HasFastDoubleElements([1.1,2])); | 56 assertTrue(%HasFastDoubleElements([1.1,2])); |
57 | 57 |
58 // Push | 58 // Push |
59 var a0 = [1, 2, 3]; | 59 var a0 = [1, 2, 3]; |
60 assertTrue(%HasFastSmiElements(a0)); | 60 assertTrue(%HasFastSmiElements(a0)); |
61 a0.push(4); | 61 a0.push(4); |
62 assertTrue(%HasFastSmiElements(a0)); | 62 assertTrue(%HasFastSmiElements(a0)); |
63 a0.push(1.3); | 63 a0.push(1.3); |
64 assertTrue(%HasFastDoubleElements(a0)); | 64 assertTrue(%HasFastDoubleElements(a0)); |
65 a0.push(1.5); | 65 a0.push(1.5); |
66 assertTrue(%HasFastDoubleElements(a0)); | 66 assertTrue(%HasFastDoubleElements(a0)); |
67 a0.push({}); | 67 a0.push({}); |
68 assertTrue(%HasFastObjectElements(a0)); | 68 assertTrue(%HasFastObjectElements(a0)); |
69 a0.push({}); | 69 a0.push({}); |
70 assertTrue(%HasFastObjectElements(a0)); | 70 assertTrue(%HasFastObjectElements(a0)); |
71 assertEquals([1,2,3,4,1.3,1.5,{},{}], a0); | 71 assertEquals([1,2,3,4,1.3,1.5,{},{}], a0); |
72 | 72 |
73 // Concat | 73 // Concat |
74 var a1; | 74 var a1; |
75 a1 = [1,2,3].concat([]); | 75 a1 = [1,2,3].concat([]); |
76 assertTrue(%HasFastSmiElements(a1)); | 76 assertTrue(%HasFastObjectElements(a1)); |
77 assertEquals([1,2,3], a1); | 77 assertEquals([1,2,3], a1); |
78 a1 = [1,2,3].concat([4,5,6]); | 78 a1 = [1,2,3].concat([4,5,6]); |
79 assertTrue(%HasFastSmiElements(a1)); | 79 assertTrue(%HasFastSmiElements(a1)); |
80 assertEquals([1,2,3,4,5,6], a1); | 80 assertEquals([1,2,3,4,5,6], a1); |
81 a1 = [1,2,3].concat([4,5,6], [7,8,9]); | 81 a1 = [1,2,3].concat([4,5,6], [7,8,9]); |
82 assertTrue(%HasFastSmiElements(a1)); | 82 assertTrue(%HasFastSmiElements(a1)); |
83 assertEquals([1,2,3,4,5,6,7,8,9], a1); | 83 assertEquals([1,2,3,4,5,6,7,8,9], a1); |
84 a1 = [1.1,2,3].concat([]); | 84 a1 = [1.1,2,3].concat([]); |
85 assertTrue(%HasFastDoubleElements(a1)); | 85 assertTrue(%HasFastObjectElements(a1)); |
86 assertEquals([1.1,2,3], a1); | 86 assertEquals([1.1,2,3], a1); |
87 a1 = [1,2,3].concat([1.1, 2]); | 87 a1 = [1,2,3].concat([1.1, 2]); |
88 assertTrue(%HasFastDoubleElements(a1)); | 88 assertTrue(%HasFastDoubleElements(a1)); |
89 assertEquals([1,2,3,1.1,2], a1); | 89 assertEquals([1,2,3,1.1,2], a1); |
90 a1 = [1.1,2,3].concat([1, 2]); | 90 a1 = [1.1,2,3].concat([1, 2]); |
91 assertTrue(%HasFastDoubleElements(a1)); | 91 assertTrue(%HasFastDoubleElements(a1)); |
92 assertEquals([1.1,2,3,1,2], a1); | 92 assertEquals([1.1,2,3,1,2], a1); |
93 a1 = [1.1,2,3].concat([1.2, 2]); | 93 a1 = [1.1,2,3].concat([1.2, 2]); |
94 assertTrue(%HasFastDoubleElements(a1)); | 94 assertTrue(%HasFastDoubleElements(a1)); |
95 assertEquals([1.1,2,3,1.2,2], a1); | 95 assertEquals([1.1,2,3,1.2,2], a1); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 a3 = [1.1,2,3]; | 166 a3 = [1.1,2,3]; |
167 a3r = a3.splice(0, 1); | 167 a3r = a3.splice(0, 1); |
168 assertTrue(%HasFastDoubleElements(a3r)); | 168 assertTrue(%HasFastDoubleElements(a3r)); |
169 assertTrue(%HasFastDoubleElements(a3)); | 169 assertTrue(%HasFastDoubleElements(a3)); |
170 assertEquals([1.1], a3r); | 170 assertEquals([1.1], a3r); |
171 assertEquals([2, 3], a3); | 171 assertEquals([2, 3], a3); |
172 a3 = [1.1,2,3]; | 172 a3 = [1.1,2,3]; |
173 a3r = a3.splice(0, 0, 2); | 173 a3r = a3.splice(0, 0, 2); |
174 // Commented out since handled in js, which takes the best fit. | 174 // Commented out since handled in js, which takes the best fit. |
175 // assertTrue(%HasFastDoubleElements(a3r)); | 175 // assertTrue(%HasFastDoubleElements(a3r)); |
176 assertTrue(%HasFastSmiElements(a3r)); | 176 assertTrue(%HasFastObjectElements(a3r)); |
177 assertTrue(%HasFastDoubleElements(a3)); | 177 assertTrue(%HasFastDoubleElements(a3)); |
178 assertEquals([], a3r); | 178 assertEquals([], a3r); |
179 assertEquals([2, 1.1, 2, 3], a3); | 179 assertEquals([2, 1.1, 2, 3], a3); |
180 a3 = [1.1,2,3]; | 180 a3 = [1.1,2,3]; |
181 a3r = a3.splice(0, 1, 2); | 181 a3r = a3.splice(0, 1, 2); |
182 assertTrue(%HasFastDoubleElements(a3r)); | 182 assertTrue(%HasFastDoubleElements(a3r)); |
183 assertTrue(%HasFastDoubleElements(a3)); | 183 assertTrue(%HasFastDoubleElements(a3)); |
184 assertEquals([1.1], a3r); | 184 assertEquals([1.1], a3r); |
185 assertEquals([2, 2, 3], a3); | 185 assertEquals([2, 2, 3], a3); |
186 a3 = [1.1,2,3]; | 186 a3 = [1.1,2,3]; |
187 a3r = a3.splice(0, 0, 2.1); | 187 a3r = a3.splice(0, 0, 2.1); |
188 // Commented out since handled in js, which takes the best fit. | 188 // Commented out since handled in js, which takes the best fit. |
189 // assertTrue(%HasFastDoubleElements(a3r)); | 189 // assertTrue(%HasFastDoubleElements(a3r)); |
190 assertTrue(%HasFastSmiElements(a3r)); | 190 assertTrue(%HasFastObjectElements(a3r)); |
191 assertTrue(%HasFastDoubleElements(a3)); | 191 assertTrue(%HasFastDoubleElements(a3)); |
192 assertEquals([], a3r); | 192 assertEquals([], a3r); |
193 assertEquals([2.1, 1.1, 2, 3], a3); | 193 assertEquals([2.1, 1.1, 2, 3], a3); |
194 a3 = [1.1,2,3]; | 194 a3 = [1.1,2,3]; |
195 a3r = a3.splice(0, 1, 2.2); | 195 a3r = a3.splice(0, 1, 2.2); |
196 assertTrue(%HasFastDoubleElements(a3r)); | 196 assertTrue(%HasFastDoubleElements(a3r)); |
197 assertTrue(%HasFastDoubleElements(a3)); | 197 assertTrue(%HasFastDoubleElements(a3)); |
198 assertEquals([1.1], a3r); | 198 assertEquals([1.1], a3r); |
199 assertEquals([2.2, 2, 3], a3); | 199 assertEquals([2.2, 2, 3], a3); |
200 a3 = [1,2,3]; | 200 a3 = [1,2,3]; |
201 a3r = a3.splice(0, 0, 2.1); | 201 a3r = a3.splice(0, 0, 2.1); |
202 // Commented out since handled in js, which takes the best fit. | 202 // Commented out since handled in js, which takes the best fit. |
203 // assertTrue(%HasFastDoubleElements(a3r)); | 203 // assertTrue(%HasFastDoubleElements(a3r)); |
204 assertTrue(%HasFastSmiElements(a3r)); | 204 assertTrue(%HasFastObjectElements(a3r)); |
205 assertTrue(%HasFastDoubleElements(a3)); | 205 assertTrue(%HasFastDoubleElements(a3)); |
206 assertEquals([], a3r); | 206 assertEquals([], a3r); |
207 assertEquals([2.1, 1, 2, 3], a3); | 207 assertEquals([2.1, 1, 2, 3], a3); |
208 a3 = [1,2,3]; | 208 a3 = [1,2,3]; |
209 a3r = a3.splice(0, 1, 2.2); | 209 a3r = a3.splice(0, 1, 2.2); |
210 assertTrue(%HasFastDoubleElements(a3r)); | 210 assertTrue(%HasFastDoubleElements(a3r)); |
211 assertTrue(%HasFastDoubleElements(a3)); | 211 assertTrue(%HasFastDoubleElements(a3)); |
212 assertEquals([1], a3r); | 212 assertEquals([1], a3r); |
213 assertEquals([2.2, 2, 3], a3); | 213 assertEquals([2.2, 2, 3], a3); |
214 | 214 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 assertEquals([1.1,{},2,3], a4); | 298 assertEquals([1.1,{},2,3], a4); |
299 } | 299 } |
300 | 300 |
301 if (support_smi_only_arrays) { | 301 if (support_smi_only_arrays) { |
302 for (var i = 0; i < 3; i++) { | 302 for (var i = 0; i < 3; i++) { |
303 array_natives_test(); | 303 array_natives_test(); |
304 } | 304 } |
305 %OptimizeFunctionOnNextCall(array_natives_test); | 305 %OptimizeFunctionOnNextCall(array_natives_test); |
306 array_natives_test(); | 306 array_natives_test(); |
307 } | 307 } |
OLD | NEW |