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 // Flags: --allow-natives-syntax |
| 6 |
| 7 // Dictionary object in the prototype chain. |
| 8 (function() { |
| 9 function A() { |
| 10 this.z = "a"; |
| 11 } |
| 12 var a = new A(); |
| 13 |
| 14 function B() { |
| 15 this.b = "b"; |
| 16 } |
| 17 B.prototype = a; |
| 18 var b = new B(); |
| 19 |
| 20 // Ensure b stays slow. |
| 21 for (var i = 0; i < 1200; i++) { |
| 22 b["b"+i] = 0; |
| 23 } |
| 24 assertFalse(%HasFastProperties(b)); |
| 25 |
| 26 function C() { |
| 27 this.c = "c"; |
| 28 } |
| 29 C.prototype = b; |
| 30 var c = new C(); |
| 31 |
| 32 function f(expected) { |
| 33 assertFalse(%HasFastProperties(b)); |
| 34 var result = c.z; |
| 35 assertEquals(expected, result); |
| 36 } |
| 37 f("a"); |
| 38 f("a"); |
| 39 f("a"); |
| 40 %OptimizeFunctionOnNextCall(f); |
| 41 f("a"); |
| 42 |
| 43 a.z = "z"; |
| 44 f("z"); |
| 45 f("z"); |
| 46 f("z"); |
| 47 |
| 48 b.z = "bz"; |
| 49 f("bz"); |
| 50 f("bz"); |
| 51 f("bz"); |
| 52 })(); |
| 53 |
| 54 |
| 55 // Global object in the prototype chain. |
| 56 (function() { |
| 57 var global = this; |
| 58 |
| 59 function A() { |
| 60 this.z = "a"; |
| 61 } |
| 62 A.prototype = global.__proto__; |
| 63 var a = new A(); |
| 64 |
| 65 global.__proto__ = a; |
| 66 |
| 67 function C() { |
| 68 this.c = "c"; |
| 69 } |
| 70 C.prototype = global; |
| 71 var c = new C(); |
| 72 |
| 73 function f(expected) { |
| 74 var result = c.z; |
| 75 assertEquals(expected, result); |
| 76 } |
| 77 f("a"); |
| 78 f("a"); |
| 79 f("a"); |
| 80 %OptimizeFunctionOnNextCall(f); |
| 81 f("a"); |
| 82 |
| 83 a.z = "z"; |
| 84 f("z"); |
| 85 f("z"); |
| 86 f("z"); |
| 87 |
| 88 global.z = "bz"; |
| 89 f("bz"); |
| 90 f("bz"); |
| 91 f("bz"); |
| 92 })(); |
OLD | NEW |