Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | |
| 2 // Redistribution and use in source and binary forms, with or without | |
| 3 // modification, are permitted provided that the following conditions are | |
| 4 // met: | |
| 5 // | |
| 6 // * Redistributions of source code must retain the above copyright | |
| 7 // notice, this list of conditions and the following disclaimer. | |
| 8 // * Redistributions in binary form must reproduce the above | |
| 9 // copyright notice, this list of conditions and the following | |
| 10 // disclaimer in the documentation and/or other materials provided | |
| 11 // with the distribution. | |
| 12 // * Neither the name of Google Inc. nor the names of its | |
| 13 // contributors may be used to endorse or promote products derived | |
| 14 // from this software without specific prior written permission. | |
| 15 // | |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 27 | |
| 28 // Flags: --allow-natives-syntax --smi-only-arrays --expose-gc | |
| 29 // Test element kind of objects. | |
| 30 // Since --smi-only-arrays affects builtins, its default setting at compile | |
| 31 // time sticks if built with snapshot. If --smi-only-arrays is deactivated | |
| 32 // by default, only a no-snapshot build actually has smi-only arrays enabled | |
| 33 // in this test case. Depending on whether smi-only arrays are actually | |
| 34 // enabled, this test takes the appropriate code path to check smi-only arrays. | |
| 35 | |
| 36 support_smi_only_arrays = %HasFastSmiOnlyElements(new Array()); | |
| 37 | |
| 38 // IC and Crankshaft support for smi-only elements in dynamic array literals. | |
| 39 function get(foo) { return foo; } // Used to generate dynamic values. | |
| 40 | |
| 41 function array_literal_test() { | |
| 42 var a0 = [1, 2, 3]; | |
| 43 assertTrue(%HasFastSmiOnlyElements(a0)); | |
| 44 var a1 = [get(1), get(2), get(3)]; | |
| 45 assertTrue(%HasFastSmiOnlyElements(a1)); | |
| 46 | |
| 47 var b0 = [1, 2, get("three")]; | |
| 48 assertTrue(%HasFastElements(b0)); | |
| 49 var b1 = [get(1), get(2), get("three")]; | |
| 50 assertTrue(%HasFastElements(b1)); | |
| 51 | |
| 52 var c0 = [1, 2, get(3.5)]; | |
| 53 assertTrue(%HasFastDoubleElements(c0)); | |
| 54 assertEquals(3.5, c0[2]); | |
| 55 assertEquals(2, c0[1]); | |
| 56 assertEquals(1, c0[0]); | |
| 57 | |
| 58 var c1 = [1, 2, 3.5]; | |
| 59 assertTrue(%HasFastDoubleElements(c1)); | |
| 60 assertEquals(3.5, c1[2]); | |
| 61 assertEquals(2, c1[1]); | |
| 62 assertEquals(1, c1[0]); | |
| 63 | |
| 64 var c2 = [get(1), get(2), get(3.5)]; | |
| 65 assertTrue(%HasFastDoubleElements(c2)); | |
| 66 assertEquals(3.5, c2[2]); | |
| 67 assertEquals(2, c2[1]); | |
| 68 assertEquals(1, c2[0]); | |
| 69 | |
| 70 var object = new Object(); | |
| 71 var d0 = [1, 2, object]; | |
| 72 assertTrue(%HasFastElements(d0)); | |
| 73 assertEquals(object, d0[2]); | |
| 74 assertEquals(2, d0[1]); | |
| 75 assertEquals(1, d0[0]); | |
| 76 | |
| 77 var e0 = [1, 2, 3.5]; | |
| 78 assertTrue(%HasFastDoubleElements(e0)); | |
| 79 assertEquals(3.5, e0[2]); | |
| 80 assertEquals(2, e0[1]); | |
| 81 assertEquals(1, e0[0]); | |
| 82 | |
| 83 var f0 = [1, 2, [1, 2]]; | |
| 84 assertTrue(%HasFastElements(f0)); | |
| 85 assertEquals([1,2], f0[2]); | |
| 86 assertEquals(2, f0[1]); | |
| 87 assertEquals(1, f0[0]); | |
| 88 } | |
| 89 | |
| 90 if (support_smi_only_arrays) { | |
| 91 | |
| 92 for (var i = 0; i < 3; i++) { | |
| 93 array_literal_test(); | |
| 94 } | |
| 95 %OptimizeFunctionOnNextCall(array_literal_test); | |
| 96 array_literal_test(); | |
| 97 | |
| 98 function test_large_literal() { | |
| 99 | |
| 100 function d() { | |
| 101 gc(); | |
| 102 return 2.5; | |
| 103 } | |
| 104 | |
| 105 function o() { | |
| 106 gc(); | |
| 107 return new Object(); | |
| 108 } | |
| 109 | |
| 110 large = | |
| 111 [ 0, 1, 2, 3, 4, 5, d(), d(), d(), d(), d(), d(), o(), o(), o(), o() ]; | |
| 112 assertFalse(%HasDictionaryElements(large)); | |
| 113 assertFalse(%HasFastSmiOnlyElements(large)); | |
| 114 assertFalse(%HasFastDoubleElements(large)); | |
| 115 assertTrue(%HasFastElements(large)); | |
| 116 assertEquals(large, | |
| 117 [0, 1, 2, 3, 4, 5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, | |
| 118 new Object(), new Object(), new Object(), new Object()]); | |
| 119 } | |
| 120 | |
| 121 for (var i = 0; i < 3; i++) { | |
| 122 test_large_literal(); | |
| 123 } | |
| 124 %OptimizeFunctionOnNextCall(test_large_literal); | |
| 125 test_large_literal(); | |
| 126 | |
| 127 | |
| 128 function d() { | |
|
Jakob Kummerow
2011/10/18 15:42:36
Isn't everything from here on down contained in te
danno
2011/10/19 11:36:39
Done.
| |
| 129 gc(); | |
| 130 return 2.5; | |
| 131 } | |
| 132 | |
| 133 function o() { | |
| 134 gc(); | |
| 135 return new Object(); | |
| 136 } | |
| 137 | |
| 138 large = | |
| 139 [ 0, 1, 2, 3, 4, 5, d(), d(), d(), d(), d(), d(), o(), o(), o(), o() ]; | |
| 140 assertFalse(%HasDictionaryElements(large)); | |
| 141 assertFalse(%HasFastSmiOnlyElements(large)); | |
| 142 assertFalse(%HasFastDoubleElements(large)); | |
| 143 assertTrue(%HasFastElements(large)); | |
| 144 } | |
| OLD | NEW |