Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: tests/language/src/OptimizedSetterTest.dart

Issue 10248007: test rename overhaul: step 8 - language tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4 // Test various setter situations, testing special cases in optimizing compiler.
5
6 class A {
7 int field = 0;
8 }
9
10 class B extends A {
11 }
12
13
14 void sameImplicitSetter() {
15 oneTarget(var a, var v) {
16 a.field = v;
17 }
18
19 A a = new A();
20 B b = new B();
21 // Optimize 'oneTarget' for one class, one target.
22 for (int i = 0; i < 2000; i++) {
23 oneTarget(a, 5);
24 Expect.equals(5, a.field);
25 }
26 // Deoptimize 'oneTarget', since class B is not expected.
27 oneTarget(b, 6);
28 Expect.equals(6, b.field);
29 // Optimize 'oneTarget' for A and B classes, one target.
30 for (int i = 0; i < 2000; i++) {
31 oneTarget(a, 7);
32 Expect.equals(7, a.field);
33 }
34 oneTarget(b, 8);
35 Expect.equals(8, b.field);
36 }
37
38
39 // Deoptimize when no feedback exists.
40 void setterNoFeedback() {
41 maybeSet(var a, var v, bool set_it) {
42 if (set_it) {
43 return a.field = v;
44 }
45 return -1;
46 }
47
48 A a = new A();
49 for (int i = 0; i < 2000; i++) {
50 var r = maybeSet(a, 5, false);
51 Expect.equals(0, a.field);
52 Expect.equals(-1, r);
53 }
54 var r = maybeSet(a, 5, true);
55 Expect.equals(5, a.field);
56 Expect.equals(5, r);
57 for (int i = 0; i < 2000; i++) {
58 var r = maybeSet(a, 6, true);
59 Expect.equals(6, a.field);
60 Expect.equals(6, r);
61 }
62 }
63
64 // Check non-implicit setter
65 class X {
66 int pField = 0;
67 set field(v) { pField = v; }
68 get field() => 10;
69 }
70
71 void sameNotImplicitSetter() {
72 oneTarget(var a, var v) {
73 return a.field = v;
74 }
75
76 incField(var a) {
77 a.field++;
78 }
79
80 X x = new X();
81 for (int i = 0; i < 2000; i++) {
82 var r = oneTarget(x, 3);
83 Expect.equals(3, x.pField);
84 Expect.equals(3, r);
85 }
86 oneTarget(x, 0);
87 for (int i = 0; i < 2000; i++) {
88 incField(x);
89 }
90 Expect.equals(11, x.pField);
91 }
92
93 class Y {
94 int field = 0;
95 }
96
97
98 multiImplicitSetter() {
99 oneTarget(var a, var v) {
100 return a.field = v;
101 }
102
103 // Both classes 'Y' and 'A' have a distinct field getter.
104 A a = new A();
105 Y y = new Y();
106 for (int i = 0; i < 2000; i++) {
107 var r = oneTarget(a, 5);
108 Expect.equals(5, a.field);
109 Expect.equals(5, r);
110 r = oneTarget(y, 6);
111 Expect.equals(6, y.field);
112 Expect.equals(6, r);
113 }
114 }
115
116 class Z {
117 int pField = 0;
118 set field(v) { pField = v; }
119 get field() => 10;
120 }
121
122 multiNotImplicitSetter() {
123 oneTarget(var a, var v) {
124 return a.field = v;
125 }
126
127 Y y = new Y();
128 Z z = new Z();
129 for (int i = 0; i < 2000; i++) {
130 var r = oneTarget(y, 8);
131 Expect.equals(8, y.field);
132 Expect.equals(8, r);
133 r = oneTarget(z, 12);
134 Expect.equals(12, z.pField);
135 Expect.equals(12, r);
136 }
137 A a = new A();
138 var r = oneTarget(a, 11);
139 Expect.equals(11, a.field);
140 Expect.equals(11, r);
141 }
142
143 void main() {
144 for (int i = 0; i< 2000; i++) {}
145 sameImplicitSetter();
146 setterNoFeedback();
147 sameNotImplicitSetter();
148
149 multiImplicitSetter();
150 multiNotImplicitSetter();
151 }
OLDNEW
« no previous file with comments | « tests/language/src/OptimizationTest.dart ('k') | tests/language/src/OptionalParameterSyntaxTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698