OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 /// Helper functions for running code in a Zone. | 5 /// Helper functions for running code in a Zone. |
6 library testing.zone_helper; | 6 library testing.zone_helper; |
7 | 7 |
8 import 'dart:async' show Completer, Future, ZoneSpecification, runZoned; | 8 import 'dart:async' show Completer, Future, ZoneSpecification, runZoned; |
9 | 9 |
10 import 'dart:io' show exit, stderr; | 10 import 'dart:io' show exit, stderr; |
(...skipping 30 matching lines...) Expand all Loading... |
41 stderr | 41 stderr |
42 .write("$errorString\n" + (stackTrace == null ? "" : "$stackTrace")); | 42 .write("$errorString\n" + (stackTrace == null ? "" : "$stackTrace")); |
43 stderr.flush(); | 43 stderr.flush(); |
44 exit(255); | 44 exit(255); |
45 } | 45 } |
46 } | 46 } |
47 | 47 |
48 ZoneSpecification specification = new ZoneSpecification(print: printWrapper); | 48 ZoneSpecification specification = new ZoneSpecification(print: printWrapper); |
49 | 49 |
50 ReceivePort errorPort = new ReceivePort(); | 50 ReceivePort errorPort = new ReceivePort(); |
51 Future errorFuture = errorPort.listen((List errors) { | 51 Future errorFuture = errorPort.listen((_errors) { |
| 52 List errors = _errors; |
52 Isolate.current.removeErrorListener(errorPort.sendPort); | 53 Isolate.current.removeErrorListener(errorPort.sendPort); |
53 errorPort.close(); | 54 errorPort.close(); |
54 var error = errors[0]; | 55 var error = errors[0]; |
55 var stackTrace = errors[1]; | 56 var stackTrace = errors[1]; |
56 if (stackTrace != null) { | 57 if (stackTrace != null) { |
57 stackTrace = new StackTrace.fromString(stackTrace); | 58 stackTrace = new StackTrace.fromString(stackTrace); |
58 } | 59 } |
59 handleUncaughtError(error, stackTrace); | 60 handleUncaughtError(error, stackTrace); |
60 }).asFuture(); | 61 }).asFuture(); |
61 | 62 |
(...skipping 17 matching lines...) Expand all Loading... |
79 /// [Isolate.addOnExitListener]. | 80 /// [Isolate.addOnExitListener]. |
80 Future acknowledgeControlMessages(Isolate isolate, {Capability resume}) { | 81 Future acknowledgeControlMessages(Isolate isolate, {Capability resume}) { |
81 ReceivePort ping = new ReceivePort(); | 82 ReceivePort ping = new ReceivePort(); |
82 Isolate.current.ping(ping.sendPort); | 83 Isolate.current.ping(ping.sendPort); |
83 if (resume == null) { | 84 if (resume == null) { |
84 return ping.first; | 85 return ping.first; |
85 } else { | 86 } else { |
86 return ping.first.then((_) => isolate.resume(resume)); | 87 return ping.first.then((_) => isolate.resume(resume)); |
87 } | 88 } |
88 } | 89 } |
OLD | NEW |