Chromium Code Reviews| 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; |