blob: 0e38cdc27de85f6c98bbcc5d1f77c11fc57a1d81 [file] [log] [blame]
Ben Murdoch097c5b22016-05-18 11:27:45 +01001// 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
7var training = {};
8training.a = "nop";
9training.slow = "nop";
10delete training.slow; // Dictionary-mode properties => slow-mode for-in.
11
12var keepalive = {};
13keepalive.a = "nop"; // Keep a map early in the transition chain alive.
14
15function 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
25function SideEffect(object, action) {
26 if (action === "dictionarize") {
27 delete object.a;
28 } else if (action === "gc") {
29 gc();
30 }
31}
32
33function 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.
41foo(training);
42SideEffect({a: 0}, "dictionarize");
43SideEffect({}, "gc");
44
45// Compile for slow-mode objects...
46%OptimizeFunctionOnNextCall(foo);
47// ...and pass in a fast-mode object.
48assertEquals("e", foo(GetReal()));