Chromium Code Reviews| 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 %DebugPrint(global); | |
|
Jakob Kummerow
2016/10/27 11:30:54
nit: leftover?
Igor Sheludko
2016/10/27 14:55:31
Done.
| |
| 59 | |
| 60 function A() { | |
| 61 this.z = "a"; | |
| 62 } | |
| 63 A.prototype = global.__proto__; | |
| 64 var a = new A(); | |
| 65 | |
| 66 global.__proto__ = a; | |
| 67 | |
| 68 function C() { | |
| 69 this.c = "c"; | |
| 70 } | |
| 71 C.prototype = global; | |
| 72 var c = new C(); | |
| 73 | |
| 74 function f(expected) { | |
| 75 var result = c.z; | |
| 76 assertEquals(expected, result); | |
| 77 } | |
| 78 f("a"); | |
| 79 f("a"); | |
| 80 f("a"); | |
| 81 %OptimizeFunctionOnNextCall(f); | |
| 82 f("a"); | |
| 83 | |
| 84 a.z = "z"; | |
| 85 f("z"); | |
| 86 f("z"); | |
| 87 f("z"); | |
| 88 | |
| 89 global.z = "bz"; | |
| 90 f("bz"); | |
| 91 f("bz"); | |
| 92 f("bz"); | |
| 93 })(); | |
| OLD | NEW |