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

Unified Diff: sdk/lib/async/future_impl.dart

Issue 1025133004: Make Completer.complete handle a Future with a misbehaving "then" call. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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 | « no previous file | tests/lib/async/future_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/async/future_impl.dart
diff --git a/sdk/lib/async/future_impl.dart b/sdk/lib/async/future_impl.dart
index a0cfeb16efe9b05e4778085a0988824e46168236..a7e4b61f9e1ffcc40a63f2a4493eaa795e67bcff 100644
--- a/sdk/lib/async/future_impl.dart
+++ b/sdk/lib/async/future_impl.dart
@@ -304,18 +304,25 @@ class _Future<T> implements Future<T> {
// Mark the target as chained (and as such half-completed).
target._isChained = true;
- source.then((value) {
- assert(target._isChained);
- target._completeWithValue(value);
- },
- // TODO(floitsch): eventually we would like to make this non-optional
- // and dependent on the listeners of the target future. If none of
- // the target future's listeners want to have the stack trace we don't
- // need a trace.
- onError: (error, [stackTrace]) {
- assert(target._isChained);
- target._completeError(error, stackTrace);
+ try {
+ source.then((value) {
+ assert(target._isChained);
+ target._completeWithValue(value);
+ },
+ // TODO(floitsch): eventually we would like to make this non-optional
+ // and dependent on the listeners of the target future. If none of
+ // the target future's listeners want to have the stack trace we don't
+ // need a trace.
+ onError: (error, [stackTrace]) {
+ assert(target._isChained);
+ target._completeError(error, stackTrace);
+ });
+ } catch (e, s) {
+ // The `then` call threw synchronously. This should never happen!
Søren Gjesse 2015/03/23 09:07:36 Maybe explain "This should never happen!" - I assu
Lasse Reichstein Nielsen 2015/03/23 09:43:54 The _Future implementation never reaches here. To
+ scheduleMicrotask(() {
+ target._completeError(e, s);
});
+ }
}
// Take the value (when completed) of source and complete target with that
@@ -399,7 +406,7 @@ class _Future<T> implements Future<T> {
} else {
// Case 2 from above. Chain the future immidiately.
// Note that we are still completing asynchronously (through
- // _chainForeignFuture)..
+ // _chainForeignFuture).
_chainForeignFuture(typedFuture, this);
}
return;
« no previous file with comments | « no previous file | tests/lib/async/future_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698