OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 // VMOptions=--enable_async --optimization-counter-threshold=10 |
| 6 |
| 7 import 'package:expect/expect.dart'; |
| 8 |
| 9 import 'dart:async'; |
| 10 |
| 11 int globalVariable = 1; |
| 12 int topLevelFoo(int param) => 1; |
| 13 int get topLevelGetter => globalVariable; |
| 14 int set topLevelSetter(val) { |
| 15 globalVariable = val; |
| 16 } |
| 17 |
| 18 class C { |
| 19 static int staticField = 1; |
| 20 static int get staticGetter => staticField; |
| 21 static int set staticSetter(val) { |
| 22 staticField = val; |
| 23 } |
| 24 static int staticFoo(int param) => param; |
| 25 |
| 26 int field = 1; |
| 27 int get getter => field; |
| 28 int set setter(val) { |
| 29 field = val; |
| 30 } |
| 31 int foo(int param) => param; |
| 32 } |
| 33 |
| 34 dummy() => 1; |
| 35 |
| 36 staticMembers() async { |
| 37 var a = C.staticField + await dummy(); |
| 38 Expect.equals(a, 2); |
| 39 var f = (C.staticField = 1) + await dummy(); |
| 40 Expect.equals(f, 2); |
| 41 var b = C.staticGetter + await dummy(); |
| 42 Expect.equals(b, 2); |
| 43 var c = (C.staticSetter = 1) + await dummy(); |
| 44 Expect.equals(c, 2); |
| 45 var d = C.staticFoo(2) + await dummy(); |
| 46 Expect.equals(d, 3); |
| 47 var e = C.staticField + |
| 48 C.staticGetter + |
| 49 (C.staticSetter = 1) + |
| 50 C.staticFoo(1) + |
| 51 await dummy(); |
| 52 Expect.equals(e, 5); |
| 53 } |
| 54 |
| 55 topLevelMembers() async { |
| 56 var a = globalVariable + await dummy(); |
| 57 Expect.equals(a, 2); |
| 58 var b = topLevelGetter + await dummy(); |
| 59 Expect.equals(b, 2); |
| 60 var c = (topLevelSetter = 1) + await dummy(); |
| 61 Expect.equals(c, 2); |
| 62 var d = topLevelFoo(1) + await dummy(); |
| 63 Expect.equals(d, 2); |
| 64 var e = globalVariable + |
| 65 topLevelGetter + |
| 66 (topLevelSetter = 1) + |
| 67 topLevelFoo(1) + |
| 68 await dummy(); |
| 69 Expect.equals(e, 5); |
| 70 } |
| 71 |
| 72 instanceMembers() async { |
| 73 var inst = new C(); |
| 74 var a = inst.field + await dummy(); |
| 75 Expect.equals(a, 2); |
| 76 var b = inst.getter + await dummy(); |
| 77 Expect.equals(b, 2); |
| 78 var c = (inst.setter = 1) + await dummy(); |
| 79 Expect.equals(c, 2); |
| 80 var d = inst.foo(1) + await dummy(); |
| 81 Expect.equals(d, 2); |
| 82 var e = inst.field + |
| 83 inst.getter + |
| 84 (inst.setter = 1) + |
| 85 inst.foo(1) + |
| 86 await dummy(); |
| 87 Expect.equals(e, 5); |
| 88 } |
| 89 |
| 90 await() => 4; |
| 91 nonAsyncFunction() => await(); |
| 92 |
| 93 others() async { |
| 94 var a = "${globalVariable} ${await dummy()} " + await "someString"; |
| 95 Expect.equals(a, "1 1 someString"); |
| 96 try { |
| 97 var c = new C(); |
| 98 var d = c.nooooo() + await bar(); |
| 99 } catch (e) {} |
| 100 var cnt = 2; |
| 101 var b = [1,2,3]; |
| 102 b[cnt] = await dummy(); |
| 103 Expect.equals(b[cnt], 1); |
| 104 var e = b[0] + await dummy(); |
| 105 Expect.equals(e, 2); |
| 106 Expect.equals(nonAsyncFunction(), 4); |
| 107 } |
| 108 |
| 109 conditionals() async { |
| 110 var a = false; |
| 111 var b = true; |
| 112 var c = (a || b) || await dummy(); |
| 113 Expect.isTrue(c); |
| 114 var d = (a || b) ? a : await dummy(); |
| 115 Expect.isFalse(d); |
| 116 var e = (a is int) ? await dummy() : 2; |
| 117 Expect.equals(e, 2); |
| 118 try { |
| 119 var f = (a is intt) ? await dummy() : 2; |
| 120 } catch(e) {} |
| 121 } |
| 122 |
| 123 main() { |
| 124 for (int i = 0; i < 10; i++) { |
| 125 staticMembers(); |
| 126 topLevelMembers(); |
| 127 instanceMembers(); |
| 128 conditionals(); |
| 129 others(); |
| 130 } |
| 131 } |
| 132 |
OLD | NEW |