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

Unified Diff: tests/lib_2/async/catch_errors.dart

Issue 2993213003: Migrated test block 167 to Dart 2.0. (Closed)
Patch Set: Created 3 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/lib/lib.status ('k') | tests/lib_2/async/catch_errors18_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib_2/async/catch_errors.dart
diff --git a/tests/lib_2/async/catch_errors.dart b/tests/lib_2/async/catch_errors.dart
new file mode 100644
index 0000000000000000000000000000000000000000..925ce2c2f269a3b1c3d3eb74acc86e0119078adc
--- /dev/null
+++ b/tests/lib_2/async/catch_errors.dart
@@ -0,0 +1,55 @@
+library catch_errors;
+
+import 'dart:async';
+
+Stream catchErrors(void body()) {
+ StreamController controller;
+
+ bool onError(e, st) {
+ controller.add(e);
+ return true;
+ }
+
+ void onListen() {
+ runZoned(body, onError: onError);
+ }
+
+ controller = new StreamController(onListen: onListen);
+ return controller.stream;
+}
+
+runZonedScheduleMicrotask(body(),
+ {void onScheduleMicrotask(void callback()), Function onError}) {
+ if (onScheduleMicrotask == null) {
+ return runZoned(body, onError: onError);
+ }
+ HandleUncaughtErrorHandler errorHandler;
+ if (onError != null) {
+ errorHandler = (Zone self, ZoneDelegate parent, Zone zone, error,
+ StackTrace stackTrace) {
+ try {
+ return self.parent.runUnary(onError, error);
+ } catch (e, s) {
+ if (identical(e, error)) {
+ return parent.handleUncaughtError(zone, error, stackTrace);
+ } else {
+ return parent.handleUncaughtError(zone, e, s);
+ }
+ }
+ };
+ }
+ ScheduleMicrotaskHandler asyncHandler;
+ if (onScheduleMicrotask != null) {
+ asyncHandler = (Zone self, ZoneDelegate parent, Zone zone, f()) {
+ self.parent.runUnary(onScheduleMicrotask, () => zone.runGuarded(f));
+ };
+ }
+ ZoneSpecification specification = new ZoneSpecification(
+ handleUncaughtError: errorHandler, scheduleMicrotask: asyncHandler);
+ Zone zone = Zone.current.fork(specification: specification);
+ if (onError != null) {
+ return zone.runGuarded(body);
+ } else {
+ return zone.run(body);
+ }
+}
« no previous file with comments | « tests/lib/lib.status ('k') | tests/lib_2/async/catch_errors18_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698