OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012, 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 that fast method extraction returns correct closure. |
| 5 |
| 6 class A { |
| 7 var f; |
| 8 A(this.f); |
| 9 foo() => 40 + f; |
| 10 } |
| 11 |
| 12 class B { |
| 13 var f; |
| 14 B(this.f); |
| 15 foo() => -40 - f; |
| 16 } |
| 17 |
| 18 class X { } |
| 19 |
| 20 class C<T> { |
| 21 foo(v) => v is T; |
| 22 } |
| 23 |
| 24 class ChaA { |
| 25 final magic; |
| 26 ChaA(magic) : this.magic = magic; |
| 27 |
| 28 foo() { |
| 29 Expect.isTrue(this is ChaA); |
| 30 Expect.equals("magicA", magic); |
| 31 return "A"; |
| 32 } |
| 33 |
| 34 bar() => foo; |
| 35 } |
| 36 |
| 37 class ChaB extends ChaA { |
| 38 ChaB(magic) : super(magic); |
| 39 |
| 40 foo() { |
| 41 Expect.isTrue(this is ChaB); |
| 42 Expect.equals("magicB", magic); |
| 43 return "B"; |
| 44 } |
| 45 } |
| 46 |
| 47 mono(a) { |
| 48 var f = a.foo; |
| 49 return f(); |
| 50 } |
| 51 |
| 52 poly(a) { |
| 53 var f = a.foo; |
| 54 return f(); |
| 55 } |
| 56 |
| 57 types(a, b) { |
| 58 var f = a.foo; |
| 59 Expect.isTrue(f(b)); |
| 60 } |
| 61 |
| 62 cha(a) { |
| 63 var f = a.bar(); |
| 64 return f(); |
| 65 } |
| 66 |
| 67 extractFromNull() { |
| 68 var f = (null).toString; |
| 69 Expect.equals("null", f()); |
| 70 } |
| 71 |
| 72 main() { |
| 73 var a = new A(2); |
| 74 var b = new B(2); |
| 75 for (var i = 0; i < 10000; i++) { |
| 76 Expect.equals(42, mono(a)); |
| 77 } |
| 78 |
| 79 for (var i = 0; i < 10000; i++) { |
| 80 Expect.equals(42, poly(a)); |
| 81 Expect.equals(-42, poly(b)); |
| 82 } |
| 83 |
| 84 var c = new C<X>(); |
| 85 var x = new X(); |
| 86 for (var i = 0; i < 10000; i++) { |
| 87 types(c, x); |
| 88 } |
| 89 |
| 90 var chaA = new ChaA("magicA"); |
| 91 for (var i = 0; i < 10000; i++) { |
| 92 Expect.equals("A", cha(chaA)); |
| 93 } |
| 94 |
| 95 var chaB = new ChaB("magicB"); |
| 96 for (var i = 0; i < 10000; i++) { |
| 97 Expect.equals("B", cha(chaB)); |
| 98 } |
| 99 |
| 100 for (var i = 0; i < 10000; i++) { |
| 101 extractFromNull(); |
| 102 } |
| 103 } |
| 104 |
OLD | NEW |