OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 17 matching lines...) Loading... |
28 // Flags: --allow-natives-syntax | 28 // Flags: --allow-natives-syntax |
29 | 29 |
30 // Handy abbreviations. | 30 // Handy abbreviations. |
31 var dp = Object.defineProperty; | 31 var dp = Object.defineProperty; |
32 var gop = Object.getOwnPropertyDescriptor; | 32 var gop = Object.getOwnPropertyDescriptor; |
33 | 33 |
34 function getter() { return 111; } | 34 function getter() { return 111; } |
35 function setter(x) { print(222); } | 35 function setter(x) { print(222); } |
36 function anotherGetter() { return 333; } | 36 function anotherGetter() { return 333; } |
37 function anotherSetter(x) { print(444); } | 37 function anotherSetter(x) { print(444); } |
38 var obj1, obj2; | 38 var obj1, obj2, obj3, obj4; |
39 | 39 |
40 // Two objects with the same getter. | 40 // Two objects with the same getter. |
41 obj1 = {}; | 41 obj1 = {}; |
42 dp(obj1, "alpha", { get: getter }); | 42 dp(obj1, "alpha", { get: getter }); |
43 obj2 = {}; | 43 obj2 = {}; |
44 dp(obj2, "alpha", { get: getter }); | 44 dp(obj2, "alpha", { get: getter }); |
45 assertTrue(%HaveSameMap(obj1, obj2)); | 45 assertTrue(%HaveSameMap(obj1, obj2)); |
46 | 46 |
47 // Two objects with the same getter, oldskool. | 47 // Two objects with the same getter, oldskool. |
48 obj1 = {}; | 48 obj1 = {}; |
(...skipping 118 matching lines...) Loading... |
167 assertEquals(setter, gop(obj1, "oscar").set); | 167 assertEquals(setter, gop(obj1, "oscar").set); |
168 | 168 |
169 // Re-adding the same getter/attributes pair. | 169 // Re-adding the same getter/attributes pair. |
170 obj1 = {}; | 170 obj1 = {}; |
171 dp(obj1, "papa", { get: getter, configurable: true }); | 171 dp(obj1, "papa", { get: getter, configurable: true }); |
172 dp(obj1, "papa", { get: getter, set: setter, configurable: true }); | 172 dp(obj1, "papa", { get: getter, set: setter, configurable: true }); |
173 assertEquals(getter, gop(obj1, "papa").get); | 173 assertEquals(getter, gop(obj1, "papa").get); |
174 assertEquals(setter, gop(obj1, "papa").set); | 174 assertEquals(setter, gop(obj1, "papa").set); |
175 assertTrue(gop(obj1, "papa").configurable); | 175 assertTrue(gop(obj1, "papa").configurable); |
176 assertFalse(gop(obj1, "papa").enumerable); | 176 assertFalse(gop(obj1, "papa").enumerable); |
| 177 |
| 178 // Two objects with the same getter on the prototype chain. |
| 179 obj1 = {}; |
| 180 dp(obj1, "quebec", { get: getter }); |
| 181 obj2 = Object.create(obj1); |
| 182 obj3 = Object.create(obj2); |
| 183 obj4 = Object.create(obj2); |
| 184 assertTrue(%HaveSameMap(obj3, obj4)); |
| 185 |
| 186 // Two objects with the same setter on the prototype chain. |
| 187 obj1 = {}; |
| 188 dp(obj1, "romeo", { set: setter }); |
| 189 obj2 = Object.create(obj1); |
| 190 obj3 = Object.create(obj2); |
| 191 obj4 = Object.create(obj2); |
| 192 assertTrue(%HaveSameMap(obj3, obj4)); |
OLD | NEW |