| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 | 47 |
| 48 function array_natives_test() { | 48 function array_natives_test() { |
| 49 | 49 |
| 50 // Ensure small array literals start in specific element kind mode. | 50 // Ensure small array literals start in specific element kind mode. |
| 51 assertTrue(%HasFastSmiElements([])); | 51 assertTrue(%HasFastSmiElements([])); |
| 52 assertTrue(%HasFastSmiElements([1])); | 52 assertTrue(%HasFastSmiElements([1])); |
| 53 assertTrue(%HasFastSmiElements([1,2])); | 53 assertTrue(%HasFastSmiElements([1,2])); |
| 54 assertTrue(%HasFastDoubleElements([1.1])); | 54 assertTrue(%HasFastDoubleElements([1.1])); |
| 55 assertTrue(%HasFastDoubleElements([1.1,2])); | 55 assertTrue(%HasFastDoubleElements([1.1,2])); |
| 56 | 56 |
| 57 // This code exists to eliminate the learning influence of AllocationSites |
| 58 // on the following tests. |
| 59 var __sequence = 0; |
| 60 function make_array_string(literal) { |
| 61 this.__sequence = this.__sequence + 1; |
| 62 return "/* " + this.__sequence + " */ " + literal; |
| 63 } |
| 64 function make_array(literal) { |
| 65 return eval(make_array_string(literal)); |
| 66 } |
| 67 |
| 57 // Push | 68 // Push |
| 58 var a0 = [1, 2, 3]; | 69 var a0 = make_array("[1, 2, 3]"); |
| 59 if (%HasFastSmiElements(a0)) { | 70 assertTrue(%HasFastSmiElements(a0)); |
| 60 assertTrue(%HasFastSmiElements(a0)); | 71 a0.push(4); |
| 61 a0.push(4); | 72 assertTrue(%HasFastSmiElements(a0)); |
| 62 assertTrue(%HasFastSmiElements(a0)); | 73 a0.push(1.3); |
| 63 a0.push(1.3); | 74 assertTrue(%HasFastDoubleElements(a0)); |
| 64 assertTrue(%HasFastDoubleElements(a0)); | 75 a0.push(1.5); |
| 65 a0.push(1.5); | 76 assertTrue(%HasFastDoubleElements(a0)); |
| 66 assertTrue(%HasFastDoubleElements(a0)); | 77 a0.push({}); |
| 67 a0.push({}); | 78 assertTrue(%HasFastObjectElements(a0)); |
| 68 assertTrue(%HasFastObjectElements(a0)); | 79 a0.push({}); |
| 69 a0.push({}); | 80 assertTrue(%HasFastObjectElements(a0)); |
| 70 assertTrue(%HasFastObjectElements(a0)); | |
| 71 } else { | |
| 72 assertTrue(%HasFastObjectElements(a0)); | |
| 73 a0.push(4); | |
| 74 a0.push(1.3); | |
| 75 a0.push(1.5); | |
| 76 a0.push({}); | |
| 77 a0.push({}); | |
| 78 assertTrue(%HasFastObjectElements(a0)); | |
| 79 } | |
| 80 assertEquals([1,2,3,4,1.3,1.5,{},{}], a0); | 81 assertEquals([1,2,3,4,1.3,1.5,{},{}], a0); |
| 81 | 82 |
| 82 // Concat | 83 // Concat |
| 83 var a1; | 84 var a1; |
| 84 a1 = [1,2,3].concat([]); | 85 a1 = [1,2,3].concat([]); |
| 85 assertTrue(%HasFastSmiElements(a1)); | 86 assertTrue(%HasFastSmiElements(a1)); |
| 86 assertEquals([1,2,3], a1); | 87 assertEquals([1,2,3], a1); |
| 87 a1 = [1,2,3].concat([4,5,6]); | 88 a1 = [1,2,3].concat([4,5,6]); |
| 88 assertTrue(%HasFastSmiElements(a1)); | 89 assertTrue(%HasFastSmiElements(a1)); |
| 89 assertEquals([1,2,3,4,5,6], a1); | 90 assertEquals([1,2,3,4,5,6], a1); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 assertEquals([1.1,{},2,3], a4); | 308 assertEquals([1.1,{},2,3], a4); |
| 308 } | 309 } |
| 309 | 310 |
| 310 if (support_smi_only_arrays) { | 311 if (support_smi_only_arrays) { |
| 311 for (var i = 0; i < 3; i++) { | 312 for (var i = 0; i < 3; i++) { |
| 312 array_natives_test(); | 313 array_natives_test(); |
| 313 } | 314 } |
| 314 %OptimizeFunctionOnNextCall(array_natives_test); | 315 %OptimizeFunctionOnNextCall(array_natives_test); |
| 315 array_natives_test(); | 316 array_natives_test(); |
| 316 } | 317 } |
| OLD | NEW |