regress-1692.js revision 3ef787dbeca8a5fb1086949cda830dccee07bfbd
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
31var 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});
41var 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.
53assertFalse(o.propertyIsEnumerable("a"));
54assertFalse(o.propertyIsEnumerable("b"));
55assertFalse(o.propertyIsEnumerable("1"));
56assertFalse(o.propertyIsEnumerable("2"));
57
58// Own properties.
59assertTrue(o.propertyIsEnumerable("c"));
60assertFalse(o.propertyIsEnumerable("d"));
61assertTrue(o.propertyIsEnumerable("3"));
62assertFalse(o.propertyIsEnumerable("4"));
63
64// Inherited accessors.
65assertFalse(o.propertyIsEnumerable("f"));
66assertFalse(o.propertyIsEnumerable("g"));
67assertFalse(o.propertyIsEnumerable("11"));
68assertFalse(o.propertyIsEnumerable("12"));
69
70// Own accessors.
71assertTrue(o.propertyIsEnumerable("h"));
72assertFalse(o.propertyIsEnumerable("k"));
73assertTrue(o.propertyIsEnumerable("13"));
74assertFalse(o.propertyIsEnumerable("14"));
75
76// Nonexisting properties.
77assertFalse(o.propertyIsEnumerable("xxx"));
78assertFalse(o.propertyIsEnumerable("999"));
79
80// String object properties.
81var o = Object("string");
82// Non-string property on String object.
83o[10] = 42;
84assertTrue(o.propertyIsEnumerable(10));
85assertFalse(o.propertyIsEnumerable(0));
86
87// Fast elements.
88var o = [1,2,3,4,5];
89assertTrue(o.propertyIsEnumerable(3));
90