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 --nostress-opt --track-field-types | 5 // Flags: --allow-natives-syntax --nostress-opt --track-field-types |
6 // Flags: --crankshaft --no-always-opt | 6 // Flags: --crankshaft --no-always-opt |
7 | 7 |
8 (function() { | 8 (function() { |
9 var o = { text: "Hello World!" }; | 9 var o = { text: "Hello World!" }; |
10 function A() { | 10 function A() { |
| 11 // Assign twice to make the field non-constant. |
| 12 // TODO(ishell): update test once constant field tracking is done. |
| 13 this.a = {text: 'foo'}; |
11 this.a = o; | 14 this.a = o; |
12 } | 15 } |
13 function readA(x) { | 16 function readA(x) { |
14 return x.a; | 17 return x.a; |
15 } | 18 } |
16 var a = new A(); | 19 var a = new A(); |
17 assertUnoptimized(readA); | 20 assertUnoptimized(readA); |
18 readA(a); readA(a); readA(a); | 21 readA(a); readA(a); readA(a); |
19 %OptimizeFunctionOnNextCall(readA); | 22 %OptimizeFunctionOnNextCall(readA); |
20 assertEquals(readA(a), o); | 23 assertEquals(readA(a), o); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 x = JSON.parse('{"a":"Short"}'); | 104 x = JSON.parse('{"a":"Short"}'); |
102 })(); | 105 })(); |
103 | 106 |
104 (function() { | 107 (function() { |
105 var x = {y: {z: 1}}; | 108 var x = {y: {z: 1}}; |
106 x.y.z = 1.1; | 109 x.y.z = 1.1; |
107 })(); | 110 })(); |
108 | 111 |
109 (function() { | 112 (function() { |
110 function Foo(x) { this.x = x; } | 113 function Foo(x) { this.x = x; } |
| 114 // TODO(ishell): update test once constant field tracking is done. |
| 115 var f0 = new Foo({x: 0}); |
| 116 f0.x = {x: 0}; // make Foo.x non-constant here. |
111 var f1 = new Foo({x: 1}); | 117 var f1 = new Foo({x: 1}); |
112 var f2 = new Foo({x: 2}); | 118 var f2 = new Foo({x: 2}); |
113 var f3 = new Foo({x: 3}); | 119 var f3 = new Foo({x: 3}); |
114 function readX(f) { return f.x.x; } | 120 function readX(f) { return f.x.x; } |
115 assertEquals(readX(f1), 1); | 121 assertEquals(readX(f1), 1); |
116 assertEquals(readX(f2), 2); | 122 assertEquals(readX(f2), 2); |
117 assertUnoptimized(readX); | 123 assertUnoptimized(readX); |
118 %OptimizeFunctionOnNextCall(readX); | 124 %OptimizeFunctionOnNextCall(readX); |
119 assertEquals(readX(f3), 3); | 125 assertEquals(readX(f3), 3); |
120 assertOptimized(readX); | 126 assertOptimized(readX); |
(...skipping 16 matching lines...) Expand all Loading... |
137 })(); | 143 })(); |
138 | 144 |
139 (function() { | 145 (function() { |
140 function Narf(x) { this.x = x; } | 146 function Narf(x) { this.x = x; } |
141 var f1 = new Narf(1); | 147 var f1 = new Narf(1); |
142 var f2 = new Narf(2); | 148 var f2 = new Narf(2); |
143 var f3 = new Narf(3); | 149 var f3 = new Narf(3); |
144 function baz(f, y) { f.y = y; } | 150 function baz(f, y) { f.y = y; } |
145 baz(f1, {y: 9}); | 151 baz(f1, {y: 9}); |
146 baz(f2, {y: 9}); | 152 baz(f2, {y: 9}); |
| 153 baz(f2, {y: 9}); |
147 %OptimizeFunctionOnNextCall(baz); | 154 %OptimizeFunctionOnNextCall(baz); |
| 155 baz(f2, {y: 9}); |
148 baz(f3, {a: -1}); | 156 baz(f3, {a: -1}); |
149 assertUnoptimized(baz); | 157 assertUnoptimized(baz); |
150 })(); | 158 })(); |
151 | 159 |
152 (function() { | 160 (function() { |
153 function Foo(x) { this.x = x; this.a = x; } | 161 function Foo(x) { this.x = x; this.a = x; } |
154 function Bar(x) { this.x = x; this.b = x; } | 162 function Bar(x) { this.x = x; this.b = x; } |
155 function readA(o) { return o.x.a; } | 163 function readA(o) { return o.x.a; } |
156 var f = new Foo({a:1}); | 164 var f = new Foo({a:1}); |
157 var b = new Bar({a:2}); | 165 var b = new Bar({a:2}); |
158 assertEquals(readA(f), 1); | 166 assertEquals(readA(f), 1); |
159 assertEquals(readA(b), 2); | 167 assertEquals(readA(b), 2); |
160 assertEquals(readA(f), 1); | 168 assertEquals(readA(f), 1); |
161 assertEquals(readA(b), 2); | 169 assertEquals(readA(b), 2); |
162 %OptimizeFunctionOnNextCall(readA); | 170 %OptimizeFunctionOnNextCall(readA); |
163 assertEquals(readA(f), 1); | 171 assertEquals(readA(f), 1); |
164 assertEquals(readA(b), 2); | 172 assertEquals(readA(b), 2); |
165 assertOptimized(readA); | 173 assertOptimized(readA); |
166 f.a.y = 0; | 174 f.a.y = 0; |
167 assertUnoptimized(readA); | 175 assertUnoptimized(readA); |
168 })(); | 176 })(); |
OLD | NEW |