| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Flags: --allow-natives-syntax | 5 // Flags: --allow-natives-syntax |
| 6 | 6 |
| 7 // Test loading existent and nonexistent properties from dictionary | 7 // Test loading existent and nonexistent properties from dictionary |
| 8 // mode objects. | 8 // mode objects. |
| 9 | 9 |
| 10 function SlowObject() { | 10 function SlowObject() { |
| 11 this.foo = 1; | 11 this.foo = 1; |
| 12 this.bar = 2; | 12 this.bar = 2; |
| 13 this.qux = 3; | 13 this.qux = 3; |
| 14 this.z = 4; |
| 14 delete this.qux; | 15 delete this.qux; |
| 15 assertFalse(%HasFastProperties(this)); | 16 assertFalse(%HasFastProperties(this)); |
| 16 } | 17 } |
| 17 function SlowObjectWithBaz() { | 18 function SlowObjectWithBaz() { |
| 18 var o = new SlowObject(); | 19 var o = new SlowObject(); |
| 19 o.baz = 4; | 20 o.baz = 4; |
| 20 return o; | 21 return o; |
| 21 } | 22 } |
| 22 | 23 |
| 23 function Load(o) { | 24 function Load(o) { |
| 24 return o.baz; | 25 return o.baz; |
| 25 } | 26 } |
| 26 | 27 |
| 27 for (var i = 0; i < 10; i++) { | 28 for (var i = 0; i < 10; i++) { |
| 28 var o1 = new SlowObject(); | 29 var o1 = new SlowObject(); |
| 29 var o2 = SlowObjectWithBaz(); | 30 var o2 = SlowObjectWithBaz(); |
| 30 assertEquals(undefined, Load(o1)); | 31 assertEquals(undefined, Load(o1)); |
| 31 assertEquals(4, Load(o2)); | 32 assertEquals(4, Load(o2)); |
| 32 } | 33 } |
| 33 | 34 |
| 34 // Test objects getting optimized as fast prototypes. | 35 // Test objects getting optimized as fast prototypes. |
| 35 | 36 |
| 36 function SlowPrototype() { | 37 function SlowPrototype() { |
| 37 this.foo = 1; | 38 this.foo = 1; |
| 38 } | 39 } |
| 39 SlowPrototype.prototype.bar = 2; | 40 SlowPrototype.prototype.bar = 2; |
| 40 SlowPrototype.prototype.baz = 3; | 41 SlowPrototype.prototype.baz = 3; |
| 42 SlowPrototype.prototype.z = 4; |
| 41 delete SlowPrototype.prototype.baz; | 43 delete SlowPrototype.prototype.baz; |
| 42 assertFalse(%HasFastProperties(SlowPrototype.prototype)); | 44 assertFalse(%HasFastProperties(SlowPrototype.prototype)); |
| 43 var slow_proto = new SlowPrototype; | 45 var slow_proto = new SlowPrototype; |
| 44 // ICs make prototypes fast. | 46 // ICs make prototypes fast. |
| 45 function ic() { return slow_proto.bar; } | 47 function ic() { return slow_proto.bar; } |
| 46 ic(); | 48 ic(); |
| 47 ic(); | 49 ic(); |
| 48 assertTrue(%HasFastProperties(slow_proto.__proto__)); | 50 assertTrue(%HasFastProperties(slow_proto.__proto__)); |
| 49 | 51 |
| 50 // Prototypes stay fast even after deleting properties. | 52 // Prototypes stay fast even after deleting properties. |
| 51 assertTrue(%HasFastProperties(SlowPrototype.prototype)); | 53 assertTrue(%HasFastProperties(SlowPrototype.prototype)); |
| 52 var fast_proto = new SlowPrototype(); | 54 var fast_proto = new SlowPrototype(); |
| 53 assertTrue(%HasFastProperties(SlowPrototype.prototype)); | 55 assertTrue(%HasFastProperties(SlowPrototype.prototype)); |
| 54 assertTrue(%HasFastProperties(fast_proto.__proto__)); | 56 assertTrue(%HasFastProperties(fast_proto.__proto__)); |
| OLD | NEW |