OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of dart.async; | 5 part of dart.async; |
6 | 6 |
7 /** The onValue and onError handlers return either a value or a future */ | 7 /** The onValue and onError handlers return either a value or a future */ |
8 typedef dynamic _FutureOnValue<T>(T value); | 8 typedef dynamic _FutureOnValue<T>(T value); |
9 /** Test used by [Future.catchError] to handle skip some errors. */ | 9 /** Test used by [Future.catchError] to handle skip some errors. */ |
10 typedef bool _FutureErrorTest(var error); | 10 typedef bool _FutureErrorTest(var error); |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 _propagateToListeners(this, listeners); | 303 _propagateToListeners(this, listeners); |
304 } | 304 } |
305 | 305 |
306 void _completeError(error, [StackTrace stackTrace]) { | 306 void _completeError(error, [StackTrace stackTrace]) { |
307 assert(!_isComplete); | 307 assert(!_isComplete); |
308 assert(_onValue == null); | 308 assert(_onValue == null); |
309 assert(_onError == null); | 309 assert(_onError == null); |
310 assert(_whenCompleteAction == null); | 310 assert(_whenCompleteAction == null); |
311 assert(_errorTest == null); | 311 assert(_errorTest == null); |
312 | 312 |
313 if (stackTrace != null) { | |
314 // Force the stack trace onto the error, even if it already had one. | |
315 _attachStackTrace(error, stackTrace); | |
316 } | |
317 | |
318 _Future listeners = _removeListeners(); | 313 _Future listeners = _removeListeners(); |
319 _setError(error, stackTrace); | 314 _setError(error, stackTrace); |
320 _propagateToListeners(this, listeners); | 315 _propagateToListeners(this, listeners); |
321 } | 316 } |
322 | 317 |
323 void _asyncComplete(value) { | 318 void _asyncComplete(value) { |
324 assert(!_isComplete); | 319 assert(!_isComplete); |
325 assert(_onValue == null); | 320 assert(_onValue == null); |
326 assert(_onError == null); | 321 assert(_onError == null); |
327 assert(_whenCompleteAction == null); | 322 assert(_whenCompleteAction == null); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 }); | 496 }); |
502 isPropagationAborted = true; | 497 isPropagationAborted = true; |
503 } | 498 } |
504 } | 499 } |
505 } catch (e, s) { | 500 } catch (e, s) { |
506 // Set the exception as error unless the error is the same as the | 501 // Set the exception as error unless the error is the same as the |
507 // original one. | 502 // original one. |
508 if (hasError && identical(source._error.error, e)) { | 503 if (hasError && identical(source._error.error, e)) { |
509 listenerValueOrError = source._error; | 504 listenerValueOrError = source._error; |
510 } else { | 505 } else { |
511 listenerValueOrError = new _AsyncError(_asyncError(e, s), s); | 506 listenerValueOrError = new _AsyncError(e, s); |
512 } | 507 } |
513 listenerHasValue = false; | 508 listenerHasValue = false; |
514 } | 509 } |
515 }); | 510 }); |
516 if (isPropagationAborted) return; | 511 if (isPropagationAborted) return; |
517 // If the listener's value is a future we need to chain it. | 512 // If the listener's value is a future we need to chain it. |
518 if (listenerHasValue && listenerValueOrError is Future) { | 513 if (listenerHasValue && listenerValueOrError is Future) { |
519 Future chainSource = listenerValueOrError; | 514 Future chainSource = listenerValueOrError; |
520 // Shortcut if the chain-source is already completed. Just continue the | 515 // Shortcut if the chain-source is already completed. Just continue the |
521 // loop. | 516 // loop. |
(...skipping 14 matching lines...) Expand all Loading... |
536 } else { | 531 } else { |
537 listeners = listener._removeListeners(); | 532 listeners = listener._removeListeners(); |
538 _AsyncError asyncError = listenerValueOrError; | 533 _AsyncError asyncError = listenerValueOrError; |
539 listener._setError(asyncError.error, asyncError.stackTrace); | 534 listener._setError(asyncError.error, asyncError.stackTrace); |
540 } | 535 } |
541 // Prepare for next round. | 536 // Prepare for next round. |
542 source = listener; | 537 source = listener; |
543 } | 538 } |
544 } | 539 } |
545 } | 540 } |
OLD | NEW |