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

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

Issue 598993002: Add missing null-tests to async error functions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add co19 issue number to status file. Created 6 years, 3 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 | « sdk/lib/async/broadcast_stream_controller.dart ('k') | sdk/lib/async/future_impl.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/async/future.dart
diff --git a/sdk/lib/async/future.dart b/sdk/lib/async/future.dart
index a4971be56e435eadfe74a19b681376117065893b..508dc07f852494bae5daef5cfbc7ab6c1c17cdb7 100644
--- a/sdk/lib/async/future.dart
+++ b/sdk/lib/async/future.dart
@@ -187,13 +187,16 @@ abstract class Future<T> {
/**
* A future that completes with an error in the next event-loop iteration.
*
- * Use [Completer] to create a Future and complete it later.
+ * If [error] is `null`, it is replaced by a [NullThrownError].
+ *
+ * Use [Completer] to create a future and complete it later.
*/
factory Future.error(Object error, [StackTrace stackTrace]) {
+ error = _nonNullError(error);
if (!identical(Zone.current, _ROOT_ZONE)) {
AsyncError replacement = Zone.current.errorCallback(error, stackTrace);
if (replacement != null) {
- error = replacement.error;
+ error = _nonNullError(replacement.error);
stackTrace = replacement.stackTrace;
}
}
@@ -663,10 +666,13 @@ abstract class Completer<T> {
// for error replacement first.
void _completeWithErrorCallback(_Future result, error, stackTrace) {
AsyncError replacement = Zone.current.errorCallback(error, stackTrace);
- if (replacement == null) {
- result._completeError(error, stackTrace);
- } else {
- result._completeError(replacement.error, replacement.stackTrace);
+ if (replacement != null) {
+ error = _nonNullError(replacement.error);
+ stackTrace = replacement.stackTrace;
}
+ result._completeError(error, stackTrace);
}
+/** Helper function that converts `null` to a [NullThrownError]. */
+Object _nonNullError(Object error) =>
+ (error != null) ? error : new NullThrownError();
« no previous file with comments | « sdk/lib/async/broadcast_stream_controller.dart ('k') | sdk/lib/async/future_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698