| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // VMOptions=-DUSE_CPS_IR=true | 4 // VMOptions=-DUSE_CPS_IR=true |
| 5 | 5 |
| 6 // Tests of interceptors. | 6 // Tests of interceptors. |
| 7 | 7 |
| 8 library constructor_test; | 8 library constructor_test; |
| 9 | 9 |
| 10 import 'js_backend_cps_ir.dart'; | 10 import 'js_backend_cps_ir.dart'; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 var y; | 61 var y; |
| 62 Sub(x, this.y) : super(x) { | 62 Sub(x, this.y) : super(x) { |
| 63 print(x); | 63 print(x); |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 main() { | 66 main() { |
| 67 print(new Sub(1, 2).x); | 67 print(new Sub(1, 2).x); |
| 68 }""", | 68 }""", |
| 69 r""" | 69 r""" |
| 70 function(x, y) { | 70 function(x, y) { |
| 71 var v0; | 71 var v0 = new V.Sub(y, x); |
| 72 v0 = new V.Sub(y, x); | |
| 73 v0.Base0$0(); | 72 v0.Base0$0(); |
| 74 v0.Sub$2(x, y); | 73 v0.Sub$2(x, y); |
| 75 return v0; | 74 return v0; |
| 76 }"""), | 75 }"""), |
| 77 | 76 |
| 78 const TestEntry.forMethod('generative_constructor(Sub#)', """ | 77 const TestEntry.forMethod('generative_constructor(Sub#)', """ |
| 79 class Base0 { | 78 class Base0 { |
| 80 Base0() { | 79 Base0() { |
| 81 print('Base0'); | 80 print('Base0'); |
| 82 } | 81 } |
| 83 } | 82 } |
| 84 class Base extends Base0 { | 83 class Base extends Base0 { |
| 85 var x; | 84 var x; |
| 86 Base(x1) : x = (() => ++x1) { | 85 Base(x1) : x = (() => ++x1) { |
| 87 print(x1); // use boxed x1 | 86 print(x1); // use boxed x1 |
| 88 } | 87 } |
| 89 } | 88 } |
| 90 class Sub extends Base { | 89 class Sub extends Base { |
| 91 var y; | 90 var y; |
| 92 Sub(x, this.y) : super(x) { | 91 Sub(x, this.y) : super(x) { |
| 93 print(x); | 92 print(x); |
| 94 } | 93 } |
| 95 } | 94 } |
| 96 main() { | 95 main() { |
| 97 print(new Sub(1, 2).x); | 96 print(new Sub(1, 2).x); |
| 98 }""", | 97 }""", |
| 99 r""" | 98 r""" |
| 100 function(x, y) { | 99 function(x, y) { |
| 101 var _box_0, v0; | 100 var _box_0 = {}, v0; |
| 102 _box_0 = {}; | |
| 103 _box_0._captured_x1_0 = x; | 101 _box_0._captured_x1_0 = x; |
| 104 v0 = new V.Sub(y, new V.Base_closure(_box_0)); | 102 v0 = new V.Sub(y, new V.Base_closure(_box_0)); |
| 105 v0.Base0$0(); | 103 v0.Base0$0(); |
| 106 v0.Base$1(_box_0); | 104 v0.Base$1(_box_0); |
| 107 v0.Sub$2(x, y); | 105 v0.Sub$2(x, y); |
| 108 return v0; | 106 return v0; |
| 109 }"""), | 107 }"""), |
| 110 | 108 |
| 111 const TestEntry.forMethod('generative_constructor(Sub#)', """ | 109 const TestEntry.forMethod('generative_constructor(Sub#)', """ |
| 112 foo(x) { | 110 foo(x) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 123 var y2; | 121 var y2; |
| 124 var y3; | 122 var y3; |
| 125 Sub() : y2 = foo('y2'), super(), y3 = foo('y3'); | 123 Sub() : y2 = foo('y2'), super(), y3 = foo('y3'); |
| 126 } | 124 } |
| 127 main() { | 125 main() { |
| 128 new Sub(); | 126 new Sub(); |
| 129 } | 127 } |
| 130 """, | 128 """, |
| 131 r""" | 129 r""" |
| 132 function() { | 130 function() { |
| 133 var v0, v1, v2, v3, v4; | 131 var v0 = V.foo("y1"), v1 = V.foo("y2"), v2 = V.foo("x1"), v3 = V.foo("x3"), v4
= V.foo("x2"); |
| 134 v0 = V.foo("y1"); | |
| 135 v1 = V.foo("y2"); | |
| 136 v2 = V.foo("x1"); | |
| 137 v3 = V.foo("x3"); | |
| 138 v4 = V.foo("x2"); | |
| 139 return new V.Sub(v0, v1, V.foo("y3"), v2, v4, v3); | 132 return new V.Sub(v0, v1, V.foo("y3"), v2, v4, v3); |
| 140 }"""), | 133 }"""), |
| 141 | 134 |
| 142 | 135 |
| 143 const TestEntry.forMethod('generative_constructor(Foo#)', """ | 136 const TestEntry.forMethod('generative_constructor(Foo#)', """ |
| 144 class Bar { | 137 class Bar { |
| 145 Bar(x, {y, z: 'z', w: '_', q}) { | 138 Bar(x, {y, z: 'z', w: '_', q}) { |
| 146 print(x); | 139 print(x); |
| 147 print(y); | 140 print(y); |
| 148 print(z); | 141 print(z); |
| 149 print(w); | 142 print(w); |
| 150 print(q); | 143 print(q); |
| 151 } | 144 } |
| 152 } | 145 } |
| 153 class Foo extends Bar { | 146 class Foo extends Bar { |
| 154 Foo() : super('x', y: 'y', w: 'w'); | 147 Foo() : super('x', y: 'y', w: 'w'); |
| 155 } | 148 } |
| 156 main() { | 149 main() { |
| 157 new Foo(); | 150 new Foo(); |
| 158 } | 151 } |
| 159 """, | 152 """, |
| 160 r""" | 153 r""" |
| 161 function() { | 154 function() { |
| 162 var v0; | 155 var v0 = new V.Foo(); |
| 163 v0 = new V.Foo(); | |
| 164 v0.Bar$5$q$w$y$z("x", null, "w", "y", "z"); | 156 v0.Bar$5$q$w$y$z("x", null, "w", "y", "z"); |
| 165 return v0; | 157 return v0; |
| 166 }"""), | 158 }"""), |
| 167 const TestEntry(r""" | 159 const TestEntry(r""" |
| 168 class C<T> { | 160 class C<T> { |
| 169 foo() => T; | 161 foo() => T; |
| 170 } | 162 } |
| 171 main() { | 163 main() { |
| 172 print(new C<int>().foo()); | 164 print(new C<int>().foo()); |
| 173 }""", r""" | 165 }""", r""" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 188 }"""), | 180 }"""), |
| 189 const TestEntry.forMethod('generative_constructor(C#)', r""" | 181 const TestEntry.forMethod('generative_constructor(C#)', r""" |
| 190 class C<T> { | 182 class C<T> { |
| 191 C() { print(T); } | 183 C() { print(T); } |
| 192 foo() => print(T); | 184 foo() => print(T); |
| 193 } | 185 } |
| 194 main() { | 186 main() { |
| 195 new C<int>(); | 187 new C<int>(); |
| 196 }""", r""" | 188 }""", r""" |
| 197 function($T) { | 189 function($T) { |
| 198 var v0; | 190 var v0 = H.setRuntimeTypeInfo(new V.C(), [$T]); |
| 199 v0 = H.setRuntimeTypeInfo(new V.C(), [$T]); | |
| 200 v0.C$0(); | 191 v0.C$0(); |
| 201 return v0; | 192 return v0; |
| 202 }"""), | 193 }"""), |
| 203 const TestEntry.forMethod('generative_constructor(C#)', r""" | 194 const TestEntry.forMethod('generative_constructor(C#)', r""" |
| 204 class C<T> { | 195 class C<T> { |
| 205 var x; | 196 var x; |
| 206 C() : x = new D<T>(); | 197 C() : x = new D<T>(); |
| 207 } | 198 } |
| 208 class D<T> { | 199 class D<T> { |
| 209 foo() => T; | 200 foo() => T; |
| 210 } | 201 } |
| 211 main() { | 202 main() { |
| 212 print(new C<int>().x.foo()); | 203 print(new C<int>().x.foo()); |
| 213 }""", r""" | 204 }""", r""" |
| 214 function($T) { | 205 function($T) { |
| 215 return H.setRuntimeTypeInfo(new V.C(V.D$($T)), [$T]); | 206 return H.setRuntimeTypeInfo(new V.C(V.D$($T)), [$T]); |
| 216 }"""), | 207 }"""), |
| 217 ]; | 208 ]; |
| 218 | 209 |
| 219 void main() { | 210 void main() { |
| 220 runTests(tests); | 211 runTests(tests); |
| 221 } | 212 } |
| OLD | NEW |