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 // VMOptions=--optimization_counter_threshold=100 | 4 // VMOptions=--optimization_counter_threshold=100 |
5 | 5 |
6 // Test field type tracking and field list-length tracking in the presence of | 6 // Test field type tracking and field list-length tracking in the presence of |
7 // multiple isolates. | 7 // multiple isolates. |
8 | 8 |
9 import "dart:isolate"; | 9 import "dart:isolate"; |
10 import "dart:async"; | 10 import "dart:async"; |
11 import "package:expect/expect.dart"; | 11 import "package:expect/expect.dart"; |
| 12 import 'package:async_helper/async_helper.dart'; |
12 | 13 |
13 class A { | 14 class A { |
14 A(this.a); | 15 A(this.a); |
15 var a; | 16 var a; |
16 } | 17 } |
17 | 18 |
18 class B extends A { | 19 class B extends A { |
19 B(a, this.b) : super(a) { } | 20 B(a, this.b) : super(a) { } |
20 | 21 |
21 var b; | 22 var b; |
22 } | 23 } |
23 | 24 |
24 f1(SendPort send_port) { | 25 f1(SendPort send_port) { |
25 send_port.send(new B("foo", "bar")); | 26 send_port.send(new B("foo", "bar")); |
26 } | 27 } |
27 | 28 |
28 test_b(B obj) => obj.a + obj.b; | 29 test_b(B obj) => obj.a + obj.b; |
29 | 30 |
30 test_field_type() { | 31 test_field_type() { |
31 var receive_port = new ReceivePort(); | 32 var receive_port = new ReceivePort(); |
| 33 asyncStart(); |
32 Future<Isolate> isolate = Isolate.spawn(f1, receive_port.sendPort); | 34 Future<Isolate> isolate = Isolate.spawn(f1, receive_port.sendPort); |
33 B b = new B(1, 2); | 35 B b = new B(1, 2); |
34 for (var i = 0; i < 200; i++) { test_b(b); } | 36 for (var i = 0; i < 200; i++) { test_b(b); } |
35 Expect.equals(3, test_b(b)); | 37 Expect.equals(3, test_b(b)); |
36 Future<B> item = receive_port.first; | 38 Future<B> item = receive_port.first; |
37 item.then((B value) { | 39 item.then((B value) { |
38 Expect.equals("foobar", test_b(value)); | 40 Expect.equals("foobar", test_b(value)); |
39 receive_port.close(); | 41 receive_port.close(); |
| 42 asyncEnd(); |
40 }); | 43 }); |
41 } | 44 } |
42 | 45 |
43 class C { | 46 class C { |
44 C(this.list); | 47 C(this.list); |
45 final List list; | 48 final List list; |
46 } | 49 } |
47 | 50 |
48 f2(SendPort send_port) { | 51 f2(SendPort send_port) { |
49 send_port.send(new C(new List(1))); | 52 send_port.send(new C(new List(1))); |
50 } | 53 } |
51 | 54 |
52 test_c(C obj) => obj.list[9999]; | 55 test_c(C obj) => obj.list[9999]; |
53 | 56 |
54 test_list_length() { | 57 test_list_length() { |
55 var receive_port = new ReceivePort(); | 58 var receive_port = new ReceivePort(); |
| 59 asyncStart(); |
56 Future<Isolate> isolate = Isolate.spawn(f2, receive_port.sendPort); | 60 Future<Isolate> isolate = Isolate.spawn(f2, receive_port.sendPort); |
57 C c = new C(new List(10000)); | 61 C c = new C(new List(10000)); |
58 for (var i = 0; i < 200; i++) { test_c(c); } | 62 for (var i = 0; i < 200; i++) { test_c(c); } |
59 Expect.equals(null, test_c(c)); | 63 Expect.equals(null, test_c(c)); |
60 Future<C> item = receive_port.first; | 64 Future<C> item = receive_port.first; |
61 item.then((C value) { | 65 item.then((C value) { |
62 Expect.throws(() => test_c(value), (e) => e is RangeError); | 66 Expect.throws(() => test_c(value), (e) => e is RangeError); |
63 receive_port.close(); | 67 receive_port.close(); |
| 68 asyncEnd(); |
64 }); | 69 }); |
65 } | 70 } |
66 | 71 |
67 main() { | 72 main() { |
68 test_field_type(); | 73 test_field_type(); |
69 test_list_length(); | 74 test_list_length(); |
70 } | 75 } |
OLD | NEW |