Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1 | // Copyright 2008 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 | // ---------------- |
| 29 | // Check fast objects |
| 30 | |
| 31 | var o = { }; |
| 32 | assertFalse(0 in o); |
| 33 | assertFalse('x' in o); |
| 34 | assertFalse('y' in o); |
| 35 | assertTrue('toString' in o, "toString"); |
| 36 | |
| 37 | var o = { x: 12 }; |
| 38 | assertFalse(0 in o); |
| 39 | assertTrue('x' in o); |
| 40 | assertFalse('y' in o); |
| 41 | assertTrue('toString' in o, "toString"); |
| 42 | |
| 43 | var o = { x: 12, y: 15 }; |
| 44 | assertFalse(0 in o); |
| 45 | assertTrue('x' in o); |
| 46 | assertTrue('y' in o); |
| 47 | assertTrue('toString' in o, "toString"); |
| 48 | |
| 49 | |
| 50 | // ---------------- |
| 51 | // Check dense arrays |
| 52 | |
| 53 | var a = [ ]; |
| 54 | assertFalse(0 in a); |
| 55 | assertFalse(1 in a); |
| 56 | assertFalse('0' in a); |
| 57 | assertFalse('1' in a); |
| 58 | assertTrue('toString' in a, "toString"); |
| 59 | |
| 60 | var a = [ 1 ]; |
| 61 | assertTrue(0 in a); |
| 62 | assertFalse(1 in a); |
| 63 | assertTrue('0' in a); |
| 64 | assertFalse('1' in a); |
| 65 | assertTrue('toString' in a, "toString"); |
| 66 | |
| 67 | var a = [ 1, 2 ]; |
| 68 | assertTrue(0 in a); |
| 69 | assertTrue(1 in a); |
| 70 | assertTrue('0' in a); |
| 71 | assertTrue('1' in a); |
| 72 | assertTrue('toString' in a, "toString"); |
| 73 | |
| 74 | var a = [ 1, 2 ]; |
| 75 | assertFalse(0.001 in a); |
| 76 | assertTrue(-0 in a); |
| 77 | assertTrue(+0 in a); |
| 78 | assertFalse('0.0' in a); |
| 79 | assertFalse('1.0' in a); |
| 80 | assertFalse(NaN in a); |
| 81 | assertFalse(Infinity in a); |
| 82 | assertFalse(-Infinity in a); |
| 83 | |
| 84 | var a = []; |
| 85 | a[1] = 2; |
| 86 | assertFalse(0 in a); |
| 87 | assertTrue(1 in a); |
| 88 | assertFalse(2 in a); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 89 | assertFalse('0' in a); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 90 | assertTrue('1' in a); |
| 91 | assertFalse('2' in a); |
| 92 | assertTrue('toString' in a, "toString"); |
| 93 | |
| 94 | |
| 95 | // ---------------- |
| 96 | // Check dictionary ("normalized") objects |
| 97 | |
| 98 | var o = {}; |
| 99 | for (var i = 0x0020; i < 0x02ff; i += 2) { |
| 100 | o['char:' + String.fromCharCode(i)] = i; |
| 101 | } |
| 102 | for (var i = 0x0020; i < 0x02ff; i += 2) { |
| 103 | assertTrue('char:' + String.fromCharCode(i) in o); |
| 104 | assertFalse('char:' + String.fromCharCode(i + 1) in o); |
| 105 | } |
| 106 | assertTrue('toString' in o, "toString"); |
| 107 | |
| 108 | var o = {}; |
| 109 | o[Math.pow(2,30)-1] = 0; |
| 110 | o[Math.pow(2,31)-1] = 0; |
| 111 | o[1] = 0; |
| 112 | assertFalse(0 in o); |
| 113 | assertTrue(1 in o); |
| 114 | assertFalse(2 in o); |
| 115 | assertFalse(Math.pow(2,30)-2 in o); |
| 116 | assertTrue(Math.pow(2,30)-1 in o); |
| 117 | assertFalse(Math.pow(2,30)-0 in o); |
| 118 | assertTrue(Math.pow(2,31)-1 in o); |
| 119 | assertFalse(0.001 in o); |
| 120 | assertFalse('0.0' in o); |
| 121 | assertFalse('1.0' in o); |
| 122 | assertFalse(NaN in o); |
| 123 | assertFalse(Infinity in o); |
| 124 | assertFalse(-Infinity in o); |
| 125 | assertFalse(-0 in o); |
| 126 | assertFalse(+0 in o); |
| 127 | assertTrue('toString' in o, "toString"); |
| 128 | |
| 129 | |
| 130 | // ---------------- |
| 131 | // Check sparse arrays |
| 132 | |
| 133 | var a = []; |
| 134 | a[Math.pow(2,30)-1] = 0; |
| 135 | a[Math.pow(2,31)-1] = 0; |
| 136 | a[1] = 0; |
| 137 | assertFalse(0 in a, "0 in a"); |
| 138 | assertTrue(1 in a, "1 in a"); |
| 139 | assertFalse(2 in a, "2 in a"); |
| 140 | assertFalse(Math.pow(2,30)-2 in a, "Math.pow(2,30)-2 in a"); |
| 141 | assertTrue(Math.pow(2,30)-1 in a, "Math.pow(2,30)-1 in a"); |
| 142 | assertFalse(Math.pow(2,30)-0 in a, "Math.pow(2,30)-0 in a"); |
| 143 | assertTrue(Math.pow(2,31)-1 in a, "Math.pow(2,31)-1 in a"); |
| 144 | assertFalse(0.001 in a, "0.001 in a"); |
| 145 | assertFalse('0.0' in a,"'0.0' in a"); |
| 146 | assertFalse('1.0' in a,"'1.0' in a"); |
| 147 | assertFalse(NaN in a,"NaN in a"); |
| 148 | assertFalse(Infinity in a,"Infinity in a"); |
| 149 | assertFalse(-Infinity in a,"-Infinity in a"); |
| 150 | assertFalse(-0 in a,"-0 in a"); |
| 151 | assertFalse(+0 in a,"+0 in a"); |
| 152 | assertTrue('toString' in a, "toString"); |
| 153 | |
| 154 | // ------------- |
| 155 | // Check negative indices in arrays. |
| 156 | var a = []; |
| 157 | assertFalse(-1 in a); |
| 158 | a[-1] = 43; |
| 159 | assertTrue(-1 in a); |