OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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 library illegal_msg_function_test; | 5 library illegal_msg_function_test; |
6 | 6 |
7 import "dart:isolate"; | 7 import "dart:isolate"; |
8 import "dart:async" show Future; | 8 import "dart:async" show Future; |
9 import "package:unittest/unittest.dart"; | 9 import "package:unittest/unittest.dart"; |
10 import "remote_unittest_helper.dart"; | 10 import "remote_unittest_helper.dart"; |
11 | 11 |
12 funcFoo(x) => x + 2; | |
13 | |
14 echo(sendPort) { | 12 echo(sendPort) { |
15 var port = new ReceivePort(); | 13 var port = new ReceivePort(); |
16 sendPort.send(port.sendPort); | 14 sendPort.send(port.sendPort); |
17 port.listen((msg) { | 15 port.listen((msg) { |
18 sendPort.send("echoing ${msg(1)}}"); | 16 sendPort.send("echoing ${msg(1)}}"); |
19 }); | 17 }); |
20 } | 18 } |
21 | 19 |
22 void main([args, port]) { | 20 void main([args, port]) { |
23 if (testRemote(main, port)) return; | 21 if (testRemote(main, port)) return; |
24 test("msg_function", () { | 22 test("msg_function", () { |
25 var function = funcFoo; | 23 var function = (x) => x + 2; |
26 ReceivePort port = new ReceivePort(); | 24 ReceivePort port = new ReceivePort(); |
27 Future spawn = Isolate.spawn(echo, port.sendPort); | 25 Future spawn = Isolate.spawn(echo, port.sendPort); |
28 var caught_exception = false; | 26 var caught_exception = false; |
29 var stream = port.asBroadcastStream(); | 27 var stream = port.asBroadcastStream(); |
30 stream.first.then(expectAsync((snd) { | 28 stream.first.then(expectAsync((snd) { |
31 try { | 29 try { |
32 snd.send(function); | 30 snd.send(function); |
33 } catch (e) { | 31 } catch (e) { |
34 caught_exception = true; | 32 caught_exception = true; |
35 } | 33 } |
36 | 34 |
37 if (caught_exception) { | 35 if (caught_exception) { |
38 port.close(); | 36 port.close(); |
39 } else { | 37 } else { |
40 stream.first.then(expectAsync((msg) { | 38 stream.first.then(expectAsync((msg) { |
41 print("from worker ${msg}"); | 39 print("from worker ${msg}"); |
42 })); | 40 })); |
43 } | 41 } |
44 expect(caught_exception, isTrue); | 42 expect(caught_exception, isTrue); |
45 })); | 43 })); |
46 }); | 44 }); |
47 } | 45 } |
OLD | NEW |