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

Side by Side Diff: sdk/lib/async/future.dart

Issue 2796363005: Fix bug in doWhile where it completes an error synchronously with an error. (Closed)
Patch Set: Created 3 years, 8 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 /// A type representing values that are either `Future<T>` or `T`. 7 /// A type representing values that are either `Future<T>` or `T`.
8 /// 8 ///
9 /// This class declaration is a public stand-in for an internal 9 /// This class declaration is a public stand-in for an internal
10 /// future-or-value generic type. References to this class are resolved to the 10 /// future-or-value generic type. References to this class are resolved to the
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 _Future doneSignal = new _Future(); 478 _Future doneSignal = new _Future();
479 var nextIteration; 479 var nextIteration;
480 // Bind this callback explicitly so that each iteration isn't bound in the 480 // Bind this callback explicitly so that each iteration isn't bound in the
481 // context of all the previous iterations' callbacks. 481 // context of all the previous iterations' callbacks.
482 nextIteration = Zone.current.bindUnaryCallback((bool keepGoing) { 482 nextIteration = Zone.current.bindUnaryCallback((bool keepGoing) {
483 if (keepGoing) { 483 if (keepGoing) {
484 FutureOr<bool> result; 484 FutureOr<bool> result;
485 try { 485 try {
486 result = f(); 486 result = f();
487 } catch (error, stackTrace) { 487 } catch (error, stackTrace) {
488 _completeWithErrorCallback(doneSignal, error, stackTrace); 488 // Cannot use _completeWithErrorCallback because it completes
489 // the future synchronously.
490 _asyncCompleteWithErrorCallback(doneSignal, error, stackTrace);
489 return; 491 return;
490 } 492 }
491 if (result is Future<bool>) { 493 if (result is Future<bool>) {
492 result.then(nextIteration, onError: doneSignal._completeError); 494 result.then(nextIteration, onError: doneSignal._completeError);
493 return; 495 return;
494 } 496 }
495 nextIteration(result); 497 nextIteration(result);
496 } else { 498 } else {
497 doneSignal._complete(null); 499 doneSignal._complete(null);
498 } 500 }
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 // for error replacement first. 868 // for error replacement first.
867 void _completeWithErrorCallback(_Future result, error, stackTrace) { 869 void _completeWithErrorCallback(_Future result, error, stackTrace) {
868 AsyncError replacement = Zone.current.errorCallback(error, stackTrace); 870 AsyncError replacement = Zone.current.errorCallback(error, stackTrace);
869 if (replacement != null) { 871 if (replacement != null) {
870 error = _nonNullError(replacement.error); 872 error = _nonNullError(replacement.error);
871 stackTrace = replacement.stackTrace; 873 stackTrace = replacement.stackTrace;
872 } 874 }
873 result._completeError(error, stackTrace); 875 result._completeError(error, stackTrace);
874 } 876 }
875 877
878 // Like [_completeWIthErrorCallback] but completes asynchronously.
eernst 2017/04/06 11:45:57 Typo: `WIth` --> `With`.
879 void _asyncCompleteWithErrorCallback(_Future result, error, stackTrace) {
880 AsyncError replacement = Zone.current.errorCallback(error, stackTrace);
881 if (replacement != null) {
882 error = _nonNullError(replacement.error);
883 stackTrace = replacement.stackTrace;
884 }
885 result._asyncCompleteError(error, stackTrace);
886 }
887
876 /** Helper function that converts `null` to a [NullThrownError]. */ 888 /** Helper function that converts `null` to a [NullThrownError]. */
877 Object _nonNullError(Object error) => error ?? new NullThrownError(); 889 Object _nonNullError(Object error) => error ?? new NullThrownError();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698