Home | History | Annotate | Download | only in regress
      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 // Test that Object.prototype.propertyIsEnumerable handles array indices
     29 // correctly.
     30 
     31 var p = Object.create({}, {
     32   a : { value : 42, enumerable : true },
     33   b : { value : 42, enumerable : false },
     34   1 : { value : 42, enumerable : true },
     35   2 : { value : 42, enumerable : false },
     36   f : { get: function(){}, enumerable: true },
     37   g : { get: function(){}, enumerable: false },
     38   11 : { get: function(){}, enumerable: true },
     39   12 : { get: function(){}, enumerable: false }
     40 });
     41 var o = Object.create(p, {
     42   c : { value : 42, enumerable : true },
     43   d : { value : 42, enumerable : false },
     44   3 : { value : 42, enumerable : true },
     45   4 : { value : 42, enumerable : false },
     46   h : { get: function(){}, enumerable: true },
     47   k : { get: function(){}, enumerable: false },
     48   13 : { get: function(){}, enumerable: true },
     49   14 : { get: function(){}, enumerable: false }
     50 });
     51 
     52 // Inherited properties are ignored.
     53 assertFalse(o.propertyIsEnumerable("a"));
     54 assertFalse(o.propertyIsEnumerable("b"));
     55 assertFalse(o.propertyIsEnumerable("1"));
     56 assertFalse(o.propertyIsEnumerable("2"));
     57 
     58 // Own properties.
     59 assertTrue(o.propertyIsEnumerable("c"));
     60 assertFalse(o.propertyIsEnumerable("d"));
     61 assertTrue(o.propertyIsEnumerable("3"));
     62 assertFalse(o.propertyIsEnumerable("4"));
     63 
     64 // Inherited accessors.
     65 assertFalse(o.propertyIsEnumerable("f"));
     66 assertFalse(o.propertyIsEnumerable("g"));
     67 assertFalse(o.propertyIsEnumerable("11"));
     68 assertFalse(o.propertyIsEnumerable("12"));
     69 
     70 // Own accessors.
     71 assertTrue(o.propertyIsEnumerable("h"));
     72 assertFalse(o.propertyIsEnumerable("k"));
     73 assertTrue(o.propertyIsEnumerable("13"));
     74 assertFalse(o.propertyIsEnumerable("14"));
     75 
     76 // Nonexisting properties.
     77 assertFalse(o.propertyIsEnumerable("xxx"));
     78 assertFalse(o.propertyIsEnumerable("999"));
     79 
     80 // String object properties.
     81 var o = Object("string");
     82 // Non-string property on String object.
     83 o[10] = 42;
     84 assertTrue(o.propertyIsEnumerable(10));
     85 assertFalse(o.propertyIsEnumerable(0));
     86 
     87 // Fast elements.
     88 var o = [1,2,3,4,5];
     89 assertTrue(o.propertyIsEnumerable(3));
     90