| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 %OptimizeFunctionOnNextCall(test_func); | 183 %OptimizeFunctionOnNextCall(test_func); |
| 184 var sum = 0; | 184 var sum = 0; |
| 185 for (var i = 0; i < kRuns; i++) { | 185 for (var i = 0; i < kRuns; i++) { |
| 186 sum = test_func(array, sum); | 186 sum = test_func(array, sum); |
| 187 } | 187 } |
| 188 assertEquals(expected_result, sum); | 188 assertEquals(expected_result, sum); |
| 189 %DeoptimizeFunction(test_func); | 189 %DeoptimizeFunction(test_func); |
| 190 gc(); // Makes V8 forget about type information for test_func. | 190 gc(); // Makes V8 forget about type information for test_func. |
| 191 } | 191 } |
| 192 | 192 |
| 193 function run_bounds_test(test_func, array, expected_result) { |
| 194 assertEquals(undefined, a[kElementCount]); |
| 195 a[kElementCount] = 456; |
| 196 assertEquals(undefined, a[kElementCount]); |
| 197 assertEquals(undefined, a[kElementCount+1]); |
| 198 a[kElementCount+1] = 456; |
| 199 assertEquals(undefined, a[kElementCount+1]); |
| 200 } |
| 201 |
| 193 for (var t = 0; t < types.length; t++) { | 202 for (var t = 0; t < types.length; t++) { |
| 194 var type = types[t]; | 203 var type = types[t]; |
| 195 var a = new type(kElementCount); | 204 var a = new type(kElementCount); |
| 205 |
| 196 for (var i = 0; i < kElementCount; i++) { | 206 for (var i = 0; i < kElementCount; i++) { |
| 197 a[i] = i; | 207 a[i] = i; |
| 198 } | 208 } |
| 199 | 209 |
| 200 // Run test functions defined above. | 210 // Run test functions defined above. |
| 201 run_test(test_load, a, 780 * kRuns); | 211 run_test(test_load, a, 780 * kRuns); |
| 202 run_test(test_load_const_key, a, 3 * kRuns); | 212 run_test(test_load_const_key, a, 3 * kRuns); |
| 203 run_test(test_store, a, 820 * kRuns); | 213 run_test(test_store, a, 820 * kRuns); |
| 204 run_test(test_store_const_key, a, 6 * kRuns); | 214 run_test(test_store_const_key, a, 6 * kRuns); |
| 205 run_test(test_store_low_int, a, test_result_low_int[t]); | 215 run_test(test_store_low_int, a, test_result_low_int[t]); |
| 206 run_test(test_store_low_double, a, test_result_low_double[t]); | 216 run_test(test_store_low_double, a, test_result_low_double[t]); |
| 207 run_test(test_store_low_tagged, a, test_result_low_double[t]); | 217 run_test(test_store_low_tagged, a, test_result_low_double[t]); |
| 208 run_test(test_store_high_int, a, test_result_high_int[t]); | 218 run_test(test_store_high_int, a, test_result_high_int[t]); |
| 209 run_test(test_store_nan, a, test_result_nan[t]); | 219 run_test(test_store_nan, a, test_result_nan[t]); |
| 210 run_test(test_store_middle_double, a, test_result_middle[t]); | 220 run_test(test_store_middle_double, a, test_result_middle[t]); |
| 211 run_test(test_store_middle_tagged, a, test_result_middle[t]); | 221 run_test(test_store_middle_tagged, a, test_result_middle[t]); |
| 212 run_test(test_store_high_double, a, test_result_high_double[t]); | 222 run_test(test_store_high_double, a, test_result_high_double[t]); |
| 213 run_test(test_store_high_tagged, a, test_result_high_double[t]); | 223 run_test(test_store_high_tagged, a, test_result_high_double[t]); |
| 214 | 224 |
| 215 // Test the correct behavior of the |length| property (which is read-only). | 225 // Test the correct behavior of the |length| property (which is read-only). |
| 216 if (t != 0) { | 226 if (t != 0) { |
| 217 assertEquals(kElementCount, a.length); | 227 assertEquals(kElementCount, a.length); |
| 218 a.length = 2; | 228 a.length = 2; |
| 219 assertEquals(kElementCount, a.length); | 229 assertEquals(kElementCount, a.length); |
| 220 assertTrue(delete a.length); | 230 assertTrue(delete a.length); |
| 221 a.length = 2; | 231 a.length = 2; |
| 222 assertEquals(2, a.length); | 232 assertEquals(2, a.length); |
| 233 |
| 234 // Make sure bounds checks are handled correctly for external arrays. |
| 235 run_bounds_test(a); |
| 236 run_bounds_test(a); |
| 237 run_bounds_test(a); |
| 238 %OptimizeFunctionOnNextCall(run_bounds_test); |
| 239 run_bounds_test(a); |
| 240 %DeoptimizeFunction(run_bounds_test); |
| 241 gc(); // Makes V8 forget about type information for test_func. |
| 242 |
| 223 } | 243 } |
| 224 | 244 |
| 225 function array_load_set_smi_check(a) { | 245 function array_load_set_smi_check(a) { |
| 226 return a[0] = a[0] = 1; | 246 return a[0] = a[0] = 1; |
| 227 } | 247 } |
| 228 | 248 |
| 229 array_load_set_smi_check(a); | 249 array_load_set_smi_check(a); |
| 230 array_load_set_smi_check(0); | 250 array_load_set_smi_check(0); |
| 231 | 251 |
| 232 function array_load_set_smi_check2(a) { | 252 function array_load_set_smi_check2(a) { |
| 233 return a[0] = a[0] = 1; | 253 return a[0] = a[0] = 1; |
| 234 } | 254 } |
| 235 | 255 |
| 236 array_load_set_smi_check2(a); | 256 array_load_set_smi_check2(a); |
| 237 %OptimizeFunctionOnNextCall(array_load_set_smi_check2); | 257 %OptimizeFunctionOnNextCall(array_load_set_smi_check2); |
| 238 array_load_set_smi_check2(a); | 258 array_load_set_smi_check2(a); |
| 239 array_load_set_smi_check2(0); | 259 array_load_set_smi_check2(0); |
| 240 %DeoptimizeFunction(array_load_set_smi_check2); | 260 %DeoptimizeFunction(array_load_set_smi_check2); |
| 241 gc(); // Makes V8 forget about type information for array_load_set_smi_check. | 261 gc(); // Makes V8 forget about type information for array_load_set_smi_check. |
| 242 } | 262 } |
| OLD | NEW |