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