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

Side by Side Diff: sdk/lib/async/stream_pipe.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: 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 unified diff | Download patch | Annotate | Revision Log
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 /** Runs user code and takes actions depending on success or failure. */ 7 /** Runs user code and takes actions depending on success or failure. */
8 _runUserCode(userCode(), 8 _runUserCode(userCode(),
9 onSuccess(value), 9 onSuccess(value),
10 onError(error, StackTrace stackTrace)) { 10 onError(error, StackTrace stackTrace)) {
11 try { 11 try {
12 onSuccess(userCode()); 12 onSuccess(userCode());
13 } catch (e, s) { 13 } catch (e, s) {
14 AsyncError replacement = Zone.current.errorCallback(e, s); 14 AsyncError replacement = Zone.current.errorCallback(e, s);
15 if (replacement == null) { 15 if (replacement == null) {
16 onError(e, s); 16 onError(e, s);
17 } else { 17 } else {
18 onError(replacement.error, replacement.stackTrace); 18 var error = replacement.error;
19 if (error == null) error = new NullThrownError();
20 var stackTrace = replacement.stackTrace;
21 onError(error, stackTrace);
19 } 22 }
20 } 23 }
21 } 24 }
22 25
23 /** Helper function to cancel a subscription and wait for the potential future, 26 /** Helper function to cancel a subscription and wait for the potential future,
24 before completing with an error. */ 27 before completing with an error. */
25 void _cancelAndError(StreamSubscription subscription, 28 void _cancelAndError(StreamSubscription subscription,
26 _Future future, 29 _Future future,
27 error, 30 error,
28 StackTrace stackTrace) { 31 StackTrace stackTrace) {
29 var cancelFuture = subscription.cancel(); 32 var cancelFuture = subscription.cancel();
30 if (cancelFuture is Future) { 33 if (cancelFuture is Future) {
31 cancelFuture.whenComplete(() => future._completeError(error, stackTrace)); 34 cancelFuture.whenComplete(() => future._completeError(error, stackTrace));
32 } else { 35 } else {
33 future._completeError(error, stackTrace); 36 future._completeError(error, stackTrace);
34 } 37 }
35 } 38 }
36 39
37 void _cancelAndErrorWithReplacement(StreamSubscription subscription, 40 void _cancelAndErrorWithReplacement(StreamSubscription subscription,
38 _Future future, 41 _Future future,
39 error, StackTrace stackTrace) { 42 error, StackTrace stackTrace) {
40 AsyncError replacement = Zone.current.errorCallback(error, stackTrace); 43 AsyncError replacement = Zone.current.errorCallback(error, stackTrace);
41 if (replacement != null) { 44 if (replacement != null) {
42 error = replacement.error; 45 error = replacement.error;
46 if (error == null) error = new NullThrownError();
43 stackTrace = replacement.stackTrace; 47 stackTrace = replacement.stackTrace;
44 } 48 }
45 _cancelAndError(subscription, future, error, stackTrace); 49 _cancelAndError(subscription, future, error, stackTrace);
46 } 50 }
47 51
48 /** Helper function to make an onError argument to [_runUserCode]. */ 52 /** Helper function to make an onError argument to [_runUserCode]. */
49 _cancelAndErrorClosure(StreamSubscription subscription, _Future future) => 53 _cancelAndErrorClosure(StreamSubscription subscription, _Future future) =>
50 ((error, StackTrace stackTrace) => _cancelAndError( 54 ((error, StackTrace stackTrace) => _cancelAndError(
51 subscription, future, error, stackTrace)); 55 subscription, future, error, stackTrace));
52 56
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 } 184 }
181 185
182 // ------------------------------------------------------------------- 186 // -------------------------------------------------------------------
183 // Stream transformers used by the default Stream implementation. 187 // Stream transformers used by the default Stream implementation.
184 // ------------------------------------------------------------------- 188 // -------------------------------------------------------------------
185 189
186 typedef bool _Predicate<T>(T value); 190 typedef bool _Predicate<T>(T value);
187 191
188 void _addErrorWithReplacement(_EventSink sink, error, stackTrace) { 192 void _addErrorWithReplacement(_EventSink sink, error, stackTrace) {
189 AsyncError replacement = Zone.current.errorCallback(error, stackTrace); 193 AsyncError replacement = Zone.current.errorCallback(error, stackTrace);
190 if (replacement == null) { 194 if (replacement != null) {
191 sink._addError(error, stackTrace); 195 error = replacement.error;
192 } else { 196 if (error == null) error = new NullThrownError();
193 sink._addError(replacement.error, replacement.stackTrace); 197 stackTrace = replacement.stackTrace;
194 } 198 }
199 sink._addError(error, stackTrace);
195 } 200 }
196 201
197 202
198 class _WhereStream<T> extends _ForwardingStream<T, T> { 203 class _WhereStream<T> extends _ForwardingStream<T, T> {
199 final _Predicate<T> _test; 204 final _Predicate<T> _test;
200 205
201 _WhereStream(Stream<T> source, bool test(T value)) 206 _WhereStream(Stream<T> source, bool test(T value))
202 : _test = test, super(source); 207 : _test = test, super(source);
203 208
204 void _handleData(T inputEvent, _EventSink<T> sink) { 209 void _handleData(T inputEvent, _EventSink<T> sink) {
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 _addErrorWithReplacement(sink, e, s); 432 _addErrorWithReplacement(sink, e, s);
428 return null; 433 return null;
429 } 434 }
430 if (!isEqual) { 435 if (!isEqual) {
431 sink._add(inputEvent); 436 sink._add(inputEvent);
432 _previous = inputEvent; 437 _previous = inputEvent;
433 } 438 }
434 } 439 }
435 } 440 }
436 } 441 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698