OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 | 6 |
7 class A { | 7 class A { |
8 bar([var optional = 1]) => 498 + optional; | 8 bar([var optional = 1]) => 498 + optional; |
9 bar2({ namedOptional: 2 }) => 40 + namedOptional; | 9 bar2({namedOptional: 2}) => 40 + namedOptional; |
10 bar3(x, [var optional = 3]) => x + 498 + optional; | 10 bar3(x, [var optional = 3]) => x + 498 + optional; |
11 bar4(x, { namedOptional: 4 }) => 422 + x + namedOptional; | 11 bar4(x, {namedOptional: 4}) => 422 + x + namedOptional; |
12 | 12 |
13 // Gee is the same as bar, but we make sure that gee is used. Potentially | 13 // Gee is the same as bar, but we make sure that gee is used. Potentially |
14 // this yields different code if the redirecting stub exists. | 14 // this yields different code if the redirecting stub exists. |
15 gee([var optional = 1]) => 498 + optional; | 15 gee([var optional = 1]) => 498 + optional; |
16 gee2({ namedOptional: 2 }) => 40 + namedOptional; | 16 gee2({namedOptional: 2}) => 40 + namedOptional; |
17 gee3(x, [var optional = 3]) => x + 498 + optional; | 17 gee3(x, [var optional = 3]) => x + 498 + optional; |
18 gee4(x, { namedOptional: 4 }) => 422 + x + namedOptional; | 18 gee4(x, {namedOptional: 4}) => 422 + x + namedOptional; |
19 | 19 |
20 // Use identifiers that could be intercepted. | 20 // Use identifiers that could be intercepted. |
21 add([var optional = 33]) => 1234 + optional; | 21 add([var optional = 33]) => 1234 + optional; |
22 trim({ namedOptional: 22 }) => 1313 + namedOptional; | 22 trim({namedOptional: 22}) => 1313 + namedOptional; |
23 sublist(x, [optional = 44]) => 4321 + optional + x; | 23 sublist(x, [optional = 44]) => 4321 + optional + x; |
24 splitMapJoin(x, { onMatch: 55, onNonMatch: 66}) => | 24 splitMapJoin(x, {onMatch: 55, onNonMatch: 66}) => |
25 111 + x + onMatch + onNonMatch; | 25 111 + x + onMatch + onNonMatch; |
26 | 26 |
27 // Other interceptable identifiers, but all of them are used. | 27 // Other interceptable identifiers, but all of them are used. |
28 shuffle([var optional = 121]) => 12342 + optional; | 28 shuffle([var optional = 121]) => 12342 + optional; |
29 toList({ growable: 2233 }) => 13131 + growable; | 29 toList({growable: 2233}) => 13131 + growable; |
30 lastIndexOf(x, [optional = 424]) => 14321 + optional + x; | 30 lastIndexOf(x, [optional = 424]) => 14321 + optional + x; |
31 lastWhere(x, { orElse: 555 }) => x + 1213 + 555; | 31 lastWhere(x, {orElse: 555}) => x + 1213 + 555; |
32 } | 32 } |
33 | 33 |
34 class B extends A { | 34 class B extends A { |
35 // The closure `super.bar` is invoked without the optional argument. | 35 // The closure `super.bar` is invoked without the optional argument. |
36 // Dart2js must not generate a `bar$0 => bar$1(null)` closure, since that | 36 // Dart2js must not generate a `bar$0 => bar$1(null)` closure, since that |
37 // would redirect to B's `bar$1`. Instead it must enforce that `bar$0` in | 37 // would redirect to B's `bar$1`. Instead it must enforce that `bar$0` in |
38 // `A` redirects to A's bar$1. | 38 // `A` redirects to A's bar$1. |
39 foo() => confuse(super.bar)(); | 39 foo() => confuse(super.bar)(); |
40 foo2() => confuse(super.bar)(2); | 40 foo2() => confuse(super.bar)(2); |
41 foo3() => confuse(super.bar2)(); | 41 foo3() => confuse(super.bar2)(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 bar2({ namedOptional }) => -1; // //# 01: continued | 76 bar2({ namedOptional }) => -1; // //# 01: continued |
77 bar3(x, [var optional]) => -1; // //# 01: continued | 77 bar3(x, [var optional]) => -1; // //# 01: continued |
78 bar4(x, { namedOptional }) => -1; //# 01: continued | 78 bar4(x, { namedOptional }) => -1; //# 01: continued |
79 | 79 |
80 gee([var optional]) => -1; // //# 01: continued | 80 gee([var optional]) => -1; // //# 01: continued |
81 gee2({ namedOptional }) => -1; // //# 01: continued | 81 gee2({ namedOptional }) => -1; // //# 01: continued |
82 gee3(x, [var optional]) => -1; // //# 01: continued | 82 gee3(x, [var optional]) => -1; // //# 01: continued |
83 gee4(x, { namedOptional }) => -1; //# 01: continued | 83 gee4(x, { namedOptional }) => -1; //# 01: continued |
84 | 84 |
85 add([var optional = 33]) => -1; | 85 add([var optional = 33]) => -1; |
86 trim({ namedOptional: 22 }) => -1; | 86 trim({namedOptional: 22}) => -1; |
87 sublist(x, [optional = 44]) => -1; | 87 sublist(x, [optional = 44]) => -1; |
88 splitMapJoin(x, { onMatch: 55, onNonMatch: 66}) => -1; | 88 splitMapJoin(x, {onMatch: 55, onNonMatch: 66}) => -1; |
89 | 89 |
90 shuffle([var optional = 121]) => -1; | 90 shuffle([var optional = 121]) => -1; |
91 toList({ growable: 2233 }) => -1; | 91 toList({growable: 2233}) => -1; |
92 lastIndexOf(x, [optional = 424]) => -1; | 92 lastIndexOf(x, [optional = 424]) => -1; |
93 lastWhere(x, { orElse: 555 }) => -1; | 93 lastWhere(x, {orElse: 555}) => -1; |
94 } | 94 } |
95 | 95 |
96 confuse(x) { | 96 confuse(x) { |
97 if (new DateTime.now().millisecondsSinceEpoch == 42) return confuse(x - 1); | 97 if (new DateTime.now().millisecondsSinceEpoch == 42) return confuse(x - 1); |
98 return x; | 98 return x; |
99 } | 99 } |
100 | 100 |
101 main() { | 101 main() { |
102 var list = [new A(), new B(), [], "foo" ]; | 102 var list = [new A(), new B(), [], "foo"]; |
103 var a = list[confuse(0)]; | 103 var a = list[confuse(0)]; |
104 var b = list[confuse(1)]; | 104 var b = list[confuse(1)]; |
105 var ignored = list[confuse(2)]; | 105 var ignored = list[confuse(2)]; |
106 var ignored2 = list[confuse(3)]; | 106 var ignored2 = list[confuse(3)]; |
107 | 107 |
108 var t = b.gee() + b.gee2() + b.gee3(9) + b.gee4(19); | 108 var t = b.gee() + b.gee2() + b.gee3(9) + b.gee4(19); |
109 Expect.equals(-4, t); //# 01: continued | 109 Expect.equals(-4, t); //# 01: continued |
110 t = b.shuffle() + b.toList() + b.lastIndexOf(1) + b.lastWhere(2); | 110 t = b.shuffle() + b.toList() + b.lastIndexOf(1) + b.lastWhere(2); |
111 Expect.equals(-4, t); | 111 Expect.equals(-4, t); |
112 | 112 |
(...skipping 26 matching lines...) Expand all Loading... |
139 | 139 |
140 Expect.equals(12463, b.fooIntercept21()); | 140 Expect.equals(12463, b.fooIntercept21()); |
141 Expect.equals(12344, b.fooIntercept22()); | 141 Expect.equals(12344, b.fooIntercept22()); |
142 Expect.equals(15364, b.fooIntercept23()); | 142 Expect.equals(15364, b.fooIntercept23()); |
143 Expect.equals(13208, b.fooIntercept24()); | 143 Expect.equals(13208, b.fooIntercept24()); |
144 Expect.equals(14742, b.fooIntercept25()); | 144 Expect.equals(14742, b.fooIntercept25()); |
145 Expect.equals(14291, b.fooIntercept26()); | 145 Expect.equals(14291, b.fooIntercept26()); |
146 Expect.equals(1768, b.fooIntercept27()); | 146 Expect.equals(1768, b.fooIntercept27()); |
147 Expect.equals(1771, b.fooIntercept28()); | 147 Expect.equals(1771, b.fooIntercept28()); |
148 } | 148 } |
OLD | NEW |