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 10 matching lines...) Expand all Loading... |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Flags: --allow-natives-syntax | 28 // Flags: --allow-natives-syntax |
29 // Test element kind of objects | 29 // Test element kind of objects |
30 | 30 |
| 31 support_smi_only_arrays = %HasFastSmiOnlyElements([]); |
| 32 |
31 var element_kind = { | 33 var element_kind = { |
| 34 fast_smi_only_elements : 0, |
32 fast_elements : 1, | 35 fast_elements : 1, |
33 fast_double_elements : 2, | 36 fast_double_elements : 2, |
34 dictionary_elements : 3, | 37 dictionary_elements : 3, |
35 external_byte_elements : 4, | 38 external_byte_elements : 4, |
36 external_unsigned_byte_elements : 5, | 39 external_unsigned_byte_elements : 5, |
37 external_short_elements : 6, | 40 external_short_elements : 6, |
38 external_unsigned_short_elements : 7, | 41 external_unsigned_short_elements : 7, |
39 external_int_elements : 8, | 42 external_int_elements : 8, |
40 external_unsigned_int_elements : 9, | 43 external_unsigned_int_elements : 9, |
41 external_float_elements : 10, | 44 external_float_elements : 10, |
42 external_double_elements : 11, | 45 external_double_elements : 11, |
43 external_pixel_elements : 12 | 46 external_pixel_elements : 12 |
44 } | 47 } |
45 | 48 |
46 // We expect an object to only be of one element kind. | 49 // We expect an object to only be of one element kind. |
47 function assertKind(expected, obj){ | 50 function assertKind(expected, obj){ |
48 assertEquals(expected == element_kind.fast_elements, | 51 if (support_smi_only_arrays) { |
49 %HasFastElements(obj)); | 52 assertEquals(expected == element_kind.fast_smi_only_elements, |
| 53 %HasFastSmiOnlyElements(obj)); |
| 54 assertEquals(expected == element_kind.fast_elements, |
| 55 %HasFastElements(obj)); |
| 56 } else { |
| 57 assertEquals(expected == element_kind.fast_elements || |
| 58 expected == element_kind.fast_smi_only_elements, |
| 59 %HasFastElements(obj)); |
| 60 } |
50 assertEquals(expected == element_kind.fast_double_elements, | 61 assertEquals(expected == element_kind.fast_double_elements, |
51 %HasFastDoubleElements(obj)); | 62 %HasFastDoubleElements(obj)); |
52 assertEquals(expected == element_kind.dictionary_elements, | 63 assertEquals(expected == element_kind.dictionary_elements, |
53 %HasDictionaryElements(obj)); | 64 %HasDictionaryElements(obj)); |
54 assertEquals(expected == element_kind.external_byte_elements, | 65 assertEquals(expected == element_kind.external_byte_elements, |
55 %HasExternalByteElements(obj)); | 66 %HasExternalByteElements(obj)); |
56 assertEquals(expected == element_kind.external_unsigned_byte_elements, | 67 assertEquals(expected == element_kind.external_unsigned_byte_elements, |
57 %HasExternalUnsignedByteElements(obj)); | 68 %HasExternalUnsignedByteElements(obj)); |
58 assertEquals(expected == element_kind.external_short_elements, | 69 assertEquals(expected == element_kind.external_short_elements, |
59 %HasExternalShortElements(obj)); | 70 %HasExternalShortElements(obj)); |
(...skipping 13 matching lines...) Expand all Loading... |
73 assertEquals(expected >= element_kind.external_byte_elements, | 84 assertEquals(expected >= element_kind.external_byte_elements, |
74 %HasExternalArrayElements(obj)); | 85 %HasExternalArrayElements(obj)); |
75 } | 86 } |
76 | 87 |
77 var me = {}; | 88 var me = {}; |
78 assertKind(element_kind.fast_elements, me); | 89 assertKind(element_kind.fast_elements, me); |
79 me.dance = 0xD15C0; | 90 me.dance = 0xD15C0; |
80 me.drink = 0xC0C0A; | 91 me.drink = 0xC0C0A; |
81 assertKind(element_kind.fast_elements, me); | 92 assertKind(element_kind.fast_elements, me); |
82 | 93 |
| 94 var too = [1,2,3]; |
| 95 assertKind(element_kind.fast_smi_only_elements, too); |
| 96 too.dance = 0xD15C0; |
| 97 too.drink = 0xC0C0A; |
| 98 assertKind(element_kind.fast_smi_only_elements, too); |
| 99 |
| 100 // Make sure the element kind transitions from smionly when a non-smi is stored. |
83 var you = new Array(); | 101 var you = new Array(); |
| 102 assertKind(element_kind.fast_smi_only_elements, you); |
84 for(i = 0; i < 1337; i++) { | 103 for(i = 0; i < 1337; i++) { |
85 you[i] = i; | 104 var val = i; |
| 105 if (i == 1336) { |
| 106 assertKind(element_kind.fast_smi_only_elements, you); |
| 107 val = new Object(); |
| 108 } |
| 109 you[i] = val; |
86 } | 110 } |
87 assertKind(element_kind.fast_elements, you); | 111 assertKind(element_kind.fast_elements, you); |
88 | 112 |
89 assertKind(element_kind.dictionary_elements, new Array(0xC0C0A)); | 113 assertKind(element_kind.dictionary_elements, new Array(0xC0C0A)); |
90 | 114 |
91 // fast_double_elements not yet available | 115 // fast_double_elements not yet available |
92 | 116 |
93 | 117 |
94 assertKind(element_kind.external_byte_elements, new Int8Array(9001)); | 118 assertKind(element_kind.external_byte_elements, new Int8Array(9001)); |
95 assertKind(element_kind.external_unsigned_byte_elements, new Uint8Array(007)); | 119 assertKind(element_kind.external_unsigned_byte_elements, new Uint8Array(007)); |
96 assertKind(element_kind.external_short_elements, new Int16Array(666)); | 120 assertKind(element_kind.external_short_elements, new Int16Array(666)); |
97 assertKind(element_kind.external_unsigned_short_elements, new Uint16Array(42)); | 121 assertKind(element_kind.external_unsigned_short_elements, new Uint16Array(42)); |
98 assertKind(element_kind.external_int_elements, new Int32Array(0xF)); | 122 assertKind(element_kind.external_int_elements, new Int32Array(0xF)); |
99 assertKind(element_kind.external_unsigned_int_elements, new Uint32Array(23)); | 123 assertKind(element_kind.external_unsigned_int_elements, new Uint32Array(23)); |
100 assertKind(element_kind.external_float_elements, new Float32Array(7)); | 124 assertKind(element_kind.external_float_elements, new Float32Array(7)); |
101 assertKind(element_kind.external_double_elements, new Float64Array(0)); | 125 assertKind(element_kind.external_double_elements, new Float64Array(0)); |
102 assertKind(element_kind.external_pixel_elements, new PixelArray(512)); | 126 assertKind(element_kind.external_pixel_elements, new PixelArray(512)); |
OLD | NEW |