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 |
| 29 // Test element kind of objects |
| 30 |
| 31 var element_kind = { |
| 32 fast_elements : 1, |
| 33 fast_double_elements : 2, |
| 34 dictionary_elements : 3, |
| 35 external_byte_elements : 4, |
| 36 external_unsigned_byte_elements : 5, |
| 37 external_short_elements : 6, |
| 38 external_unsigned_short_elements : 7, |
| 39 external_int_elements : 8, |
| 40 external_unsigned_int_elements : 9, |
| 41 external_float_elements : 10, |
| 42 external_double_elements : 11, |
| 43 external_pixel_elements : 12 |
| 44 } |
| 45 |
| 46 // We expect an object to only be of one element kind. |
| 47 function assertKind(expected, obj){ |
| 48 assertEquals(expected == element_kind.fast_elements, |
| 49 %HasFastElements(obj)); |
| 50 assertEquals(expected == element_kind.fast_double_elements, |
| 51 %HasFastDoubleElements(obj)); |
| 52 assertEquals(expected == element_kind.dictionary_elements, |
| 53 %HasDictionaryElements(obj)); |
| 54 assertEquals(expected == element_kind.external_byte_elements, |
| 55 %HasExternalByteElements(obj)); |
| 56 assertEquals(expected == element_kind.external_unsigned_byte_elements, |
| 57 %HasExternalUnsignedByteElements(obj)); |
| 58 assertEquals(expected == element_kind.external_short_elements, |
| 59 %HasExternalShortElements(obj)); |
| 60 assertEquals(expected == element_kind.external_unsigned_short_elements, |
| 61 %HasExternalUnsignedShortElements(obj)); |
| 62 assertEquals(expected == element_kind.external_int_elements, |
| 63 %HasExternalIntElements(obj)); |
| 64 assertEquals(expected == element_kind.external_unsigned_int_elements, |
| 65 %HasExternalUnsignedIntElements(obj)); |
| 66 assertEquals(expected == element_kind.external_float_elements, |
| 67 %HasExternalFloatElements(obj)); |
| 68 assertEquals(expected == element_kind.external_double_elements, |
| 69 %HasExternalDoubleElements(obj)); |
| 70 assertEquals(expected == element_kind.external_pixel_elements, |
| 71 %HasExternalPixelElements(obj)); |
| 72 // every external kind is also an external array |
| 73 assertEquals(expected >= element_kind.external_byte_elements, |
| 74 %HasExternalArrayElements(obj)); |
| 75 } |
| 76 |
| 77 var me = {}; |
| 78 assertKind(element_kind.fast_elements, me); |
| 79 me.dance = 0xD15C0; |
| 80 me.drink = 0xC0C0A; |
| 81 assertKind(element_kind.fast_elements, me); |
| 82 |
| 83 var you = new Array(); |
| 84 for(i = 0; i < 1337; i++) { |
| 85 you[i] = i; |
| 86 } |
| 87 assertKind(element_kind.fast_elements, you); |
| 88 |
| 89 assertKind(element_kind.dictionary_elements, new Array(0xC0C0A)); |
| 90 |
| 91 // fast_double_elements not yet available |
| 92 |
| 93 |
| 94 assertKind(element_kind.external_byte_elements, new Int8Array(9001)); |
| 95 assertKind(element_kind.external_unsigned_byte_elements, new Uint8Array(007)); |
| 96 assertKind(element_kind.external_short_elements, new Int16Array(666)); |
| 97 assertKind(element_kind.external_unsigned_short_elements, new Uint16Array(42)); |
| 98 assertKind(element_kind.external_int_elements, new Int32Array(0xF)); |
| 99 assertKind(element_kind.external_unsigned_int_elements, new Uint32Array(23)); |
| 100 assertKind(element_kind.external_float_elements, new Float32Array(7)); |
| 101 assertKind(element_kind.external_double_elements, new Float64Array(0)); |
| 102 assertKind(element_kind.external_pixel_elements, new PixelArray(512)); |
OLD | NEW |