Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: tests/language/regress_26175_test.dart

Issue 1861963007: Dart VM: Fix an order-of-evaluation bug in async code. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Merge upstream/master. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/ast_transformer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import "package:expect/expect.dart";
6 import "package:async_helper/async_helper.dart";
7
8 // Test that local variable reads and writes are sequenced correctly with
9 // respect to reads and writes in an awaited Future. See issue 26175.
10
11 // Reads are sequenced correctly with respect to writes in a Future.
12 Future test1() async {
13 var x = 'a';
14 f() async => x = 'b';
15 Expect.equals('abb', '${x}${await f()}${x}');
16 }
17
18 // Writes are sequenced correctly with respect to writes in a Future.
19 Future test2(ignore) async {
20 var x;
21 f() async => x = 'b';
22 Expect.equals('abb', '${x = 'a'}${await f()}${x}');
23 }
24
25 // Writes are sequenced correctly with respect to reads in a Future.
26 Future test3(ignore) async {
27 var x = 'a';
28 f() async => x;
29 Expect.equals('bbb', '${x = 'b'}${await f()}${x}');
30 }
31
32 // Repeat the same tests for static variables.
33 var cell = 'a';
34
35 asyncReadCell() async => cell;
36 asyncWriteCell(value) async => cell = value;
37
38 Future test4(ignore) async {
39 // This test assumes that it can read the initial value of cell.
40 Expect.equals('abb', '${cell}${await asyncWriteCell('b')}${cell}');
41 }
42
43 Future test5(ignore) async {
44 Expect.equals('abb', '${cell = 'a'}${await asyncWriteCell('b')}${cell}');
45 }
46
47 Future test6(ignore) async {
48 Expect.equals('bbb', '${cell = 'b'}${await asyncReadCell()}${cell}');
49 }
50
51 // Test that throwing is sequenced correctly with respect to other effects.
52 Future test7(ignore) async {
53 cell = 'a';
54 try {
55 Expect.equals('unreachable',
56 '${throw 0}${await asyncWriteCell('b')}${cell}');
57 } catch (_) {
58 Expect.equals('a', cell);
59 }
60 }
61
62 main() {
63 asyncStart();
64 test1()
65 .then(test2)
66 .then(test3)
67 .then(test4)
68 .then(test5)
69 .then(test6)
70 .then(test7)
71 .then((_) => asyncEnd());
72 }
OLDNEW
« no previous file with comments | « runtime/vm/ast_transformer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698