Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 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 --dead-code-elimination --expose-gc |
| 6 | |
| 7 | var training = {}; |
| 8 | training.a = "nop"; |
| 9 | training.slow = "nop"; |
| 10 | delete training.slow; // Dictionary-mode properties => slow-mode for-in. |
| 11 | |
| 12 | var keepalive = {}; |
| 13 | keepalive.a = "nop"; // Keep a map early in the transition chain alive. |
| 14 | |
| 15 | function GetReal() { |
| 16 | var r = {}; |
| 17 | r.a = "nop"; |
| 18 | r.b = "nop"; |
| 19 | r.c = "dictionarize", |
| 20 | r.d = "gc"; |
| 21 | r.e = "result"; |
| 22 | return r; |
| 23 | }; |
| 24 | |
| 25 | function SideEffect(object, action) { |
| 26 | if (action === "dictionarize") { |
| 27 | delete object.a; |
| 28 | } else if (action === "gc") { |
| 29 | gc(); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | function foo(object) { |
| 34 | for (var key in object) { |
| 35 | SideEffect(object, object[key]); |
| 36 | } |
| 37 | return key; |
| 38 | } |
| 39 | |
| 40 | // Collect type feedback for slow-mode for-in. |
| 41 | foo(training); |
| 42 | SideEffect({a: 0}, "dictionarize"); |
| 43 | SideEffect({}, "gc"); |
| 44 | |
| 45 | // Compile for slow-mode objects... |
| 46 | %OptimizeFunctionOnNextCall(foo); |
| 47 | // ...and pass in a fast-mode object. |
| 48 | assertEquals("e", foo(GetReal())); |