OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 | 4 |
5 // dart2js regression test for issue 8781. | 5 // dart2js regression test for issue 8781. |
6 | 6 |
7 import "dart:mirrors" show reflect; | 7 import "dart:mirrors" show reflect; |
8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
9 | 9 |
10 class N { | 10 class N { |
11 var outgoing; | 11 var outgoing; |
12 var incoming; | 12 var incoming; |
13 N(this.outgoing, this.incoming); | 13 N(this.outgoing, this.incoming); |
14 } | 14 } |
15 | 15 |
16 class A { | 16 class A { |
17 int offset = 0; | 17 int offset = 0; |
18 var list; | 18 var list; |
19 var node; | 19 var node; |
20 | 20 |
21 A(node) : node = node, list = node.outgoing; | 21 A(node) |
| 22 : node = node, |
| 23 list = node.outgoing; |
22 | 24 |
23 next() { | 25 next() { |
24 // dart2js used to update [offset] twice: once in the optimized | 26 // dart2js used to update [offset] twice: once in the optimized |
25 // version, which would bailout to the non-optimized version | 27 // version, which would bailout to the non-optimized version |
26 // because [list] is not an Array, and once in the non-optimized | 28 // because [list] is not an Array, and once in the non-optimized |
27 // version. | 29 // version. |
28 var edge = list[offset++]; | 30 var edge = list[offset++]; |
29 if (list == node.outgoing) { | 31 if (list == node.outgoing) { |
30 list = node.incoming; | 32 list = node.incoming; |
31 offset = 0; | 33 offset = 0; |
32 } else | 34 } else |
33 list = null; | 35 list = null; |
34 return edge; | 36 return edge; |
35 } | 37 } |
36 } | 38 } |
37 | 39 |
38 class L { | 40 class L { |
39 final list; | 41 final list; |
40 L(this.list); | 42 L(this.list); |
41 // Use noSuchMethod to defeat type inferencing. | 43 // Use noSuchMethod to defeat type inferencing. |
42 noSuchMethod(mirror) => reflect(list).delegate(mirror); | 44 noSuchMethod(mirror) => reflect(list).delegate(mirror); |
43 } | 45 } |
44 | 46 |
45 main () { | 47 main() { |
46 var o = new A(new N(new L([1]), new L([2]))); | 48 var o = new A(new N(new L([1]), new L([2]))); |
47 | 49 |
48 for (var i = 1; i <= 2; i++) | 50 for (var i = 1; i <= 2; i++) Expect.equals(i, o.next()); |
49 Expect.equals(i, o.next()); | |
50 | 51 |
51 Expect.equals(null, o.list); | 52 Expect.equals(null, o.list); |
52 } | 53 } |
OLD | NEW |