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

Side by Side Diff: tests/isolate/error_exit_at_spawn_test.dart

Issue 1244733002: - Implement VM parts of https://codereview.chromium.org/1240743003/ (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Update isolate.status file as expected. Created 5 years, 5 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
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 library error_exit_at_spawn;
6
7 import "dart:isolate";
8 import "dart:async";
9 import "package:async_helper/async_helper.dart";
10 import "package:expect/expect.dart";
11
12 isomain(replyPort) {
13 RawReceivePort port = new RawReceivePort();
14 port.handler = (v) {
15 switch (v) {
16 case 0:
17 replyPort.send(42);
18 break;
19 case 1:
20 throw new ArgumentError("whoops");
21 case 2:
22 throw new RangeError.value(37);
23 case 3:
24 port.close();
25 }
26 };
27 replyPort.send(port.sendPort);
28 }
29
30 main(){
31 asyncStart();
32 // Setup the port for communication with the newly spawned isolate.
33 RawReceivePort reply = new RawReceivePort(null);
34 SendPort sendPort;
35 int state = 0;
36 reply.handler = (port) {
37 sendPort = port;
38 port.send(state);
39 reply.handler = (v) {
40 Expect.equals(0, state);
41 Expect.equals(42, v);
42 state++;
43 sendPort.send(state);
44 };
45 };
46
47 // Capture errors from other isolate as raw messages.
48 RawReceivePort errorPort = new RawReceivePort();
49 errorPort.handler = (message) {
50 String error = message[0];
51 String stack = message[1];
52 switch (state) {
53 case 1:
54 Expect.equals(new ArgumentError("whoops").toString(), "$error");
55 state++;
56 sendPort.send(state);
57 break;
58 case 2:
59 Expect.equals(new RangeError.value(37).toString(), "$error");
60 state++;
61 sendPort.send(state);
62 reply.close();
63 errorPort.close();
64 break;
65 default:
66 throw "Bad state for error: $state: $error";
67 }
68 };
69
70 // Get exit notifications from other isolate as raw messages.
71 RawReceivePort exitPort = new RawReceivePort();
72 exitPort.handler = (message) {
73 // onExit ports registered at spawn cannot have a particular message
74 // associated.
75 Expect.equals(null, message);
76 // Only exit after sending the termination message.
77 Expect.equals(3, state);
78 exitPort.close();
79 asyncEnd();
80 };
81
82 Isolate.spawn(isomain,
83 reply.sendPort,
84 // Setup handlers as part of spawn.
85 errorsAreFatal: false,
86 onError: errorPort.sendPort,
87 onExit: exitPort.sendPort);
88 }
OLDNEW
« no previous file with comments | « tests/isolate/error_at_spawnuri_test.dart ('k') | tests/isolate/error_exit_at_spawnuri_iso.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698