 Chromium Code Reviews
 Chromium Code Reviews Issue 2718643003:
  fix future onError handler wrapping to avoid cast error  (Closed)
    
  
    Issue 2718643003:
  fix future onError handler wrapping to avoid cast error  (Closed) 
  | 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 FutureOr<T> _FutureOnValue<S, T>(S value); | 8 typedef FutureOr<T> _FutureOnValue<S, T>(S 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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 _resultOrListeners = source; | 230 _resultOrListeners = source; | 
| 231 } | 231 } | 
| 232 | 232 | 
| 233 Future<E> then<E>( | 233 Future<E> then<E>( | 
| 234 FutureOr<E> f(T value), { Function onError }) { | 234 FutureOr<E> f(T value), { Function onError }) { | 
| 235 Zone currentZone = Zone.current; | 235 Zone currentZone = Zone.current; | 
| 236 ZoneUnaryCallback registered; | 236 ZoneUnaryCallback registered; | 
| 237 if (!identical(currentZone, _ROOT_ZONE)) { | 237 if (!identical(currentZone, _ROOT_ZONE)) { | 
| 238 f = currentZone.registerUnaryCallback<FutureOr<E>, T>(f); | 238 f = currentZone.registerUnaryCallback<FutureOr<E>, T>(f); | 
| 239 if (onError != null) { | 239 if (onError != null) { | 
| 240 onError = _registerErrorHandler<T>(onError, currentZone); | 240 onError = _registerErrorHandler(onError, currentZone); | 
| 
floitsch
2017/02/27 13:19:04
This was a mistake. It should have been `_register
 
Jennifer Messerly
2017/02/27 18:41:02
okay. I can fix it that way, however: at least a c
 
floitsch
2017/02/27 19:02:39
I will have a look tomorrow.
If you have these pla
 | |
| 241 } | 241 } | 
| 242 } | 242 } | 
| 243 return _thenNoZoneRegistration<E>(f, onError); | 243 return _thenNoZoneRegistration<E>(f, onError); | 
| 244 } | 244 } | 
| 245 | 245 | 
| 246 // This method is used by async/await. | 246 // This method is used by async/await. | 
| 247 Future<E> _thenNoZoneRegistration<E>(f(T value), Function onError) { | 247 Future<E> _thenNoZoneRegistration<E>(f(T value), Function onError) { | 
| 248 _Future<E> result = new _Future<E>(); | 248 _Future<E> result = new _Future<E>(); | 
| 249 _addListener(new _FutureListener<T, E>.then(result, f, onError)); | 249 _addListener(new _FutureListener<T, E>.then(result, f, onError)); | 
| 250 return result; | 250 return result; | 
| 251 } | 251 } | 
| 252 | 252 | 
| 253 Future<T> catchError(Function onError, { bool test(error) }) { | 253 Future<T> catchError(Function onError, { bool test(error) }) { | 
| 254 _Future<T> result = new _Future<T>(); | 254 _Future<T> result = new _Future<T>(); | 
| 255 if (!identical(result._zone, _ROOT_ZONE)) { | 255 if (!identical(result._zone, _ROOT_ZONE)) { | 
| 256 onError = _registerErrorHandler<T>(onError, result._zone); | 256 onError = _registerErrorHandler(onError, result._zone); | 
| 257 if (test != null) test = result._zone.registerUnaryCallback(test); | 257 if (test != null) test = result._zone.registerUnaryCallback(test); | 
| 258 } | 258 } | 
| 259 _addListener(new _FutureListener<T, T>.catchError( | 259 _addListener(new _FutureListener<T, T>.catchError( | 
| 260 result, onError, test)); | 260 result, onError, test)); | 
| 261 return result; | 261 return result; | 
| 262 } | 262 } | 
| 263 | 263 | 
| 264 Future<T> whenComplete(action()) { | 264 Future<T> whenComplete(action()) { | 
| 265 _Future<T> result = new _Future<T>(); | 265 _Future<T> result = new _Future<T>(); | 
| 266 if (!identical(result._zone, _ROOT_ZONE)) { | 266 if (!identical(result._zone, _ROOT_ZONE)) { | 
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 737 } | 737 } | 
| 738 }, onError: (e, s) { | 738 }, onError: (e, s) { | 
| 739 if (timer.isActive) { | 739 if (timer.isActive) { | 
| 740 timer.cancel(); | 740 timer.cancel(); | 
| 741 result._completeError(e, s); | 741 result._completeError(e, s); | 
| 742 } | 742 } | 
| 743 }); | 743 }); | 
| 744 return result; | 744 return result; | 
| 745 } | 745 } | 
| 746 } | 746 } | 
| OLD | NEW |