OLD | NEW |
| (Empty) |
1 // Copyright 2016 the V8 project authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 function allKeys(object) { | |
6 var keys = []; | |
7 for (var key in object) { | |
8 keys.push(key); | |
9 } | |
10 return keys; | |
11 } | |
12 | |
13 var a = { a1: true, a2: true}; | |
14 var b = { b1: true, b2: true}; | |
15 a.__proto__ = b; | |
16 | |
17 assertEquals(['a1', 'a2', 'b1', 'b2'], allKeys(a)); | |
18 assertEquals(['b1', 'b2'], allKeys(b)); | |
19 | |
20 // Adding a non-enumerable property to either a or b shouldn't change | |
21 // the result. | |
22 var propertyDescriptor = { | |
23 enumerable: false, | |
24 configurable: true, | |
25 writable: true, | |
26 value: true | |
27 }; | |
28 | |
29 Object.defineProperty(a, 'a3', propertyDescriptor); | |
30 assertEquals(['a1', 'a2', 'b1', 'b2'], allKeys(a)); | |
31 assertEquals(['b1', 'b2'], allKeys(b)); | |
32 | |
33 Object.defineProperty(b, 'b3', propertyDescriptor); | |
34 assertEquals(['a1', 'a2', 'b1', 'b2'], allKeys(a)); | |
35 assertEquals(['b1', 'b2'], allKeys(b)); | |
36 | |
37 // A non-enumerable property shadows an enumerable version on the prototype | |
38 // chain. | |
39 b['a3'] = true; | |
40 assertEquals(['a1', 'a2', 'b1', 'b2'], allKeys(a)); | |
41 assertEquals(['b1', 'b2', 'a3'], allKeys(b)); | |
42 | |
43 // Try the same with indexed-properties. | |
44 var aIndex = {0:true, 1:true}; | |
45 var bIndex = {10:true, 11:true}; | |
46 aIndex.__proto__= bIndex; | |
47 assertEquals(['0', '1', '10', '11'], allKeys(aIndex)); | |
48 assertEquals(['10', '11'], allKeys(bIndex)); | |
49 | |
50 Object.defineProperty(aIndex, 2, propertyDescriptor); | |
51 Object.defineProperty(bIndex, 12, propertyDescriptor); | |
52 assertEquals(['0', '1', '10', '11'], allKeys(aIndex)); | |
53 assertEquals(['10', '11'], allKeys(bIndex)); | |
54 | |
55 bIndex[2] = 2; | |
56 assertEquals(['0', '1', '10', '11'], allKeys(aIndex)); | |
57 assertEquals(['2', '10', '11'], allKeys(bIndex)); | |
OLD | NEW |