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

Side by Side Diff: test/dart_codegen/expect/async/stream_pipe.dart

Issue 963593002: Disable formatting and add new-lines to make tests faster. (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 9 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
OLDNEW
1 part of dart.async; 1 part of dart.async;
2 2 _runUserCode(userCode(), onSuccess(value), onError(error, StackTrace stackTrace )) {
3 _runUserCode(
4 userCode(), onSuccess(value), onError(error, StackTrace stackTrace)) {
5 try { 3 try {
6 onSuccess(userCode()); 4 onSuccess(userCode());
7 } catch (e, s) { 5 }
6 catch (e, s) {
8 AsyncError replacement = Zone.current.errorCallback(e, s); 7 AsyncError replacement = Zone.current.errorCallback(e, s);
9 if (replacement == null) { 8 if (replacement == null) {
10 onError(e, s); 9 onError(e, s);
11 } else { 10 }
11 else {
12 var error = _nonNullError(replacement.error); 12 var error = _nonNullError(replacement.error);
13 var stackTrace = replacement.stackTrace; 13 var stackTrace = replacement.stackTrace;
14 onError(error, stackTrace); 14 onError(error, stackTrace);
15 } 15 }
16 } 16 }
17 } 17 }
18 void _cancelAndError(StreamSubscription subscription, _Future future, error, 18 void _cancelAndError(StreamSubscription subscription, _Future future, error, St ackTrace stackTrace) {
19 StackTrace stackTrace) {
20 var cancelFuture = subscription.cancel(); 19 var cancelFuture = subscription.cancel();
21 if (cancelFuture is Future) { 20 if (cancelFuture is Future) {
22 cancelFuture.whenComplete(() => future._completeError(error, stackTrace)); 21 cancelFuture.whenComplete(() => future._completeError(error, stackTrace));
23 } else { 22 }
23 else {
24 future._completeError(error, stackTrace); 24 future._completeError(error, stackTrace);
25 } 25 }
26 } 26 }
27 void _cancelAndErrorWithReplacement(StreamSubscription subscription, 27 void _cancelAndErrorWithReplacement(StreamSubscription subscription, _Future fu ture, error, StackTrace stackTrace) {
28 _Future future, error, StackTrace stackTrace) {
29 AsyncError replacement = Zone.current.errorCallback(error, stackTrace); 28 AsyncError replacement = Zone.current.errorCallback(error, stackTrace);
30 if (replacement != null) { 29 if (replacement != null) {
31 error = _nonNullError(replacement.error); 30 error = _nonNullError(replacement.error);
32 stackTrace = replacement.stackTrace; 31 stackTrace = replacement.stackTrace;
33 } 32 }
34 _cancelAndError(subscription, future, error, stackTrace); 33 _cancelAndError(subscription, future, error, stackTrace);
35 } 34 }
36 _cancelAndErrorClosure(StreamSubscription subscription, _Future future) => 35 _cancelAndErrorClosure(StreamSubscription subscription, _Future future) => ((er ror, StackTrace stackTrace) => _cancelAndError(subscription, future, error, stac kTrace));
37 ((error, StackTrace stackTrace) => 36 void _cancelAndValue(StreamSubscription subscription, _Future future, value) {
38 _cancelAndError(subscription, future, error, stackTrace));
39 void _cancelAndValue(StreamSubscription subscription, _Future future, value) {
40 var cancelFuture = subscription.cancel(); 37 var cancelFuture = subscription.cancel();
41 if (cancelFuture is Future) { 38 if (cancelFuture is Future) {
42 cancelFuture.whenComplete(() => future._complete(value)); 39 cancelFuture.whenComplete(() => future._complete(value));
43 } else { 40 }
41 else {
44 future._complete(value); 42 future._complete(value);
45 } 43 }
46 } 44 }
47 abstract class _ForwardingStream<S, T> extends Stream<T> { 45 abstract class _ForwardingStream<S, T> extends Stream<T> {final Stream<S> _sour ce;
48 final Stream<S> _source; 46 _ForwardingStream(this._source);
49 _ForwardingStream(this._source); 47 bool get isBroadcast => _source.isBroadcast;
50 bool get isBroadcast => _source.isBroadcast; 48 StreamSubscription<T> listen(void onData(T value), {
51 StreamSubscription<T> listen(void onData(T value), 49 Function onError, void onDone(), bool cancelOnError}
52 {Function onError, void onDone(), bool cancelOnError}) { 50 ) {
53 cancelOnError = identical(true, cancelOnError); 51 cancelOnError = identical(true, cancelOnError);
54 return _createSubscription(onData, onError, onDone, cancelOnError); 52 return _createSubscription(onData, onError, onDone, cancelOnError);
55 } 53 }
56 StreamSubscription<T> _createSubscription(void onData(T data), 54 StreamSubscription<T> _createSubscription(void onData(T data), Function onError , void onDone(), bool cancelOnError) {
57 Function onError, void onDone(), bool cancelOnError) { 55 return new _ForwardingStreamSubscription<S, T>(this, onData, onError, onDone, cancelOnError);
58 return new _ForwardingStreamSubscription<S, T>( 56 }
59 this, onData, onError, onDone, cancelOnError); 57 void _handleData(S data, _EventSink<T> sink) {
60 } 58 var outputData = data;
61 void _handleData(S data, _EventSink<T> sink) { 59 sink._add(outputData);
62 var outputData = data; 60 }
63 sink._add(outputData); 61 void _handleError(error, StackTrace stackTrace, _EventSink<T> sink) {
64 } 62 sink._addError(error, stackTrace);
65 void _handleError(error, StackTrace stackTrace, _EventSink<T> sink) { 63 }
66 sink._addError(error, stackTrace); 64 void _handleDone(_EventSink<T> sink) {
67 } 65 sink._close();
68 void _handleDone(_EventSink<T> sink) { 66 }
69 sink._close(); 67 }
70 } 68 class _ForwardingStreamSubscription<S, T> extends _BufferingStreamSubscription< T> {final _ForwardingStream<S, T> _stream;
71 } 69 StreamSubscription<S> _subscription;
72 class _ForwardingStreamSubscription<S, T> 70 _ForwardingStreamSubscription(this._stream, void onData(T data), Function onErr or, void onDone(), bool cancelOnError) : super(onData, onError, onDone, cancelOn Error) {
73 extends _BufferingStreamSubscription<T> { 71 _subscription = _stream._source.listen(_handleData, onError: _handleError, onDon e: _handleDone);
74 final _ForwardingStream<S, T> _stream; 72 }
75 StreamSubscription<S> _subscription; 73 void _add(T data) {
76 _ForwardingStreamSubscription(this._stream, void onData(T data), 74 if (_isClosed) return; super._add(data);
77 Function onError, void onDone(), bool cancelOnError) 75 }
78 : super(onData, onError, onDone, cancelOnError) { 76 void _addError(Object error, StackTrace stackTrace) {
79 _subscription = _stream._source.listen(_handleData, 77 if (_isClosed) return; super._addError(error, stackTrace);
80 onError: _handleError, onDone: _handleDone); 78 }
81 } 79 void _onPause() {
82 void _add(T data) { 80 if (_subscription == null) return; _subscription.pause();
83 if (_isClosed) return; 81 }
84 super._add(data); 82 void _onResume() {
85 } 83 if (_subscription == null) return; _subscription.resume();
86 void _addError(Object error, StackTrace stackTrace) { 84 }
87 if (_isClosed) return; 85 Future _onCancel() {
88 super._addError(error, stackTrace); 86 if (_subscription != null) {
89 } 87 StreamSubscription subscription = _subscription;
90 void _onPause() { 88 _subscription = null;
91 if (_subscription == null) return; 89 subscription.cancel();
92 _subscription.pause(); 90 }
93 } 91 return null;
94 void _onResume() { 92 }
95 if (_subscription == null) return; 93 void _handleData(S data) {
96 _subscription.resume(); 94 _stream._handleData(data, this);
97 } 95 }
98 Future _onCancel() { 96 void _handleError(error, StackTrace stackTrace) {
99 if (_subscription != null) { 97 _stream._handleError(error, stackTrace, this);
100 StreamSubscription subscription = _subscription; 98 }
101 _subscription = null; 99 void _handleDone() {
102 subscription.cancel(); 100 _stream._handleDone(this);
103 } 101 }
104 return null; 102 }
105 } 103 typedef bool _Predicate<T>(T value);
106 void _handleData(S data) { 104 void _addErrorWithReplacement(_EventSink sink, error, stackTrace) {
107 _stream._handleData(data, this); 105 AsyncError replacement = Zone.current.errorCallback(error, DDC$RT.cast(stackTrac e, dynamic, StackTrace, "CastGeneral", """line 191, column 62 of dart:async/stre am_pipe.dart: """, stackTrace is StackTrace, true));
108 } 106 if (replacement != null) {
109 void _handleError(error, StackTrace stackTrace) { 107 error = _nonNullError(replacement.error);
110 _stream._handleError(error, stackTrace, this); 108 stackTrace = replacement.stackTrace;
111 } 109 }
112 void _handleDone() { 110 sink._addError(error, DDC$RT.cast(stackTrace, dynamic, StackTrace, "CastGeneral ", """line 196, column 25 of dart:async/stream_pipe.dart: """, stackTrace is Sta ckTrace, true));
113 _stream._handleDone(this); 111 }
114 } 112 class _WhereStream<T> extends _ForwardingStream<T, T> {final _Predicate<T> _tes t;
115 } 113 _WhereStream(Stream<T> source, bool test(T value)) : _test = test, super(source );
116 typedef bool _Predicate<T>(T value); 114 void _handleData(T inputEvent, _EventSink<T> sink) {
117 void _addErrorWithReplacement(_EventSink sink, error, stackTrace) { 115 bool satisfies;
118 AsyncError replacement = Zone.current.errorCallback(error, DDC$RT.cast( 116 try {
119 stackTrace, dynamic, StackTrace, "CastGeneral", 117 satisfies = _test(inputEvent);
120 """line 191, column 62 of dart:async/stream_pipe.dart: """, 118 }
121 stackTrace is StackTrace, true)); 119 catch (e, s) {
122 if (replacement != null) { 120 _addErrorWithReplacement(sink, e, s);
123 error = _nonNullError(replacement.error); 121 return;}
124 stackTrace = replacement.stackTrace; 122 if (satisfies) {
125 } 123 sink._add(inputEvent);
126 sink._addError(error, DDC$RT.cast(stackTrace, dynamic, StackTrace, 124 }
127 "CastGeneral", """line 196, column 25 of dart:async/stream_pipe.dart: """, 125 }
128 stackTrace is StackTrace, true)); 126 }
129 } 127 typedef T _Transformation<S, T>(S value);
130 class _WhereStream<T> extends _ForwardingStream<T, T> { 128 class _MapStream<S, T> extends _ForwardingStream<S, T> {final _Transformation _ transform;
131 final _Predicate<T> _test; 129 _MapStream(Stream<S> source, T transform(S event)) : this._transform = transfor m, super(source);
132 _WhereStream(Stream<T> source, bool test(T value)) 130 void _handleData(S inputEvent, _EventSink<T> sink) {
133 : _test = test, 131 T outputEvent;
134 super(source); 132 try {
135 void _handleData(T inputEvent, _EventSink<T> sink) { 133 outputEvent = ((__x117) => DDC$RT.cast(__x117, dynamic, T, "CastGeneral", """lin e 235, column 21 of dart:async/stream_pipe.dart: """, __x117 is T, false))(_tran sform(inputEvent));
136 bool satisfies; 134 }
137 try { 135 catch (e, s) {
138 satisfies = _test(inputEvent); 136 _addErrorWithReplacement(sink, e, s);
139 } catch (e, s) { 137 return;}
140 _addErrorWithReplacement(sink, e, s); 138 sink._add(outputEvent);
141 return; 139 }
142 } 140 }
143 if (satisfies) { 141 class _ExpandStream<S, T> extends _ForwardingStream<S, T> {final _Transformatio n<S, Iterable<T>> _expand;
144 sink._add(inputEvent); 142 _ExpandStream(Stream<S> source, Iterable<T> expand(S event)) : this._expand = e xpand, super(source);
145 } 143 void _handleData(S inputEvent, _EventSink<T> sink) {
146 } 144 try {
147 } 145 for (T value in _expand(inputEvent)) {
148 typedef T _Transformation<S, T>(S value); 146 sink._add(value);
149 class _MapStream<S, T> extends _ForwardingStream<S, T> { 147 }
150 final _Transformation _transform; 148 }
151 _MapStream(Stream<S> source, T transform(S event)) 149 catch (e, s) {
152 : this._transform = transform, 150 _addErrorWithReplacement(sink, e, s);
153 super(source); 151 }
154 void _handleData(S inputEvent, _EventSink<T> sink) { 152 }
155 T outputEvent; 153 }
156 try { 154 typedef bool _ErrorTest(error);
157 outputEvent = ((__x117) => DDC$RT.cast(__x117, dynamic, T, "CastGeneral", 155 class _HandleErrorStream<T> extends _ForwardingStream<T, T> {final Function _tr ansform;
158 """line 235, column 21 of dart:async/stream_pipe.dart: """, 156 final _ErrorTest _test;
159 __x117 is T, false))(_transform(inputEvent)); 157 _HandleErrorStream(Stream<T> source, Function onError, bool test(error)) : this ._transform = onError, this._test = test, super(source);
160 } catch (e, s) { 158 void _handleError(Object error, StackTrace stackTrace, _EventSink<T> sink) {
161 _addErrorWithReplacement(sink, e, s); 159 bool matches = true;
162 return; 160 if (_test != null) {
163 } 161 try {
164 sink._add(outputEvent); 162 matches = _test(error);
165 } 163 }
166 } 164 catch (e, s) {
167 class _ExpandStream<S, T> extends _ForwardingStream<S, T> { 165 _addErrorWithReplacement(sink, e, s);
168 final _Transformation<S, Iterable<T>> _expand; 166 return;}
169 _ExpandStream(Stream<S> source, Iterable<T> expand(S event)) 167 }
170 : this._expand = expand, 168 if (matches) {
171 super(source); 169 try {
172 void _handleData(S inputEvent, _EventSink<T> sink) { 170 _invokeErrorHandler(_transform, error, stackTrace);
173 try { 171 }
174 for (T value in _expand(inputEvent)) { 172 catch (e, s) {
175 sink._add(value); 173 if (identical(e, error)) {
176 } 174 sink._addError(error, stackTrace);
177 } catch (e, s) { 175 }
178 _addErrorWithReplacement(sink, e, s); 176 else {
179 } 177 _addErrorWithReplacement(sink, e, s);
180 } 178 }
181 } 179 return;}
182 typedef bool _ErrorTest(error); 180 }
183 class _HandleErrorStream<T> extends _ForwardingStream<T, T> { 181 else {
184 final Function _transform; 182 sink._addError(error, stackTrace);
185 final _ErrorTest _test; 183 }
186 _HandleErrorStream(Stream<T> source, Function onError, bool test(error)) 184 }
187 : this._transform = onError, 185 }
188 this._test = test, 186 class _TakeStream<T> extends _ForwardingStream<T, T> {int _remaining;
189 super(source); 187 _TakeStream(Stream<T> source, int count) : this._remaining = count, super(sourc e) {
190 void _handleError(Object error, StackTrace stackTrace, _EventSink<T> sink) { 188 if (count is! int) throw new ArgumentError(count);
191 bool matches = true; 189 }
192 if (_test != null) { 190 void _handleData(T inputEvent, _EventSink<T> sink) {
193 try { 191 if (_remaining > 0) {
194 matches = _test(error); 192 sink._add(inputEvent);
195 } catch (e, s) { 193 _remaining -= 1;
196 _addErrorWithReplacement(sink, e, s); 194 if (_remaining == 0) {
197 return; 195 sink._close();
198 } 196 }
199 } 197 }
200 if (matches) { 198 }
201 try { 199 }
202 _invokeErrorHandler(_transform, error, stackTrace); 200 class _TakeWhileStream<T> extends _ForwardingStream<T, T> {final _Predicate<T> _test;
203 } catch (e, s) { 201 _TakeWhileStream(Stream<T> source, bool test(T value)) : this._test = test, sup er(source);
204 if (identical(e, error)) { 202 void _handleData(T inputEvent, _EventSink<T> sink) {
205 sink._addError(error, stackTrace); 203 bool satisfies;
206 } else { 204 try {
207 _addErrorWithReplacement(sink, e, s); 205 satisfies = _test(inputEvent);
208 } 206 }
209 return; 207 catch (e, s) {
210 } 208 _addErrorWithReplacement(sink, e, s);
211 } else { 209 sink._close();
212 sink._addError(error, stackTrace); 210 return;}
213 } 211 if (satisfies) {
214 } 212 sink._add(inputEvent);
215 } 213 }
216 class _TakeStream<T> extends _ForwardingStream<T, T> { 214 else {
217 int _remaining; 215 sink._close();
218 _TakeStream(Stream<T> source, int count) 216 }
219 : this._remaining = count, 217 }
220 super(source) { 218 }
221 if (count is! int) throw new ArgumentError(count); 219 class _SkipStream<T> extends _ForwardingStream<T, T> {int _remaining;
222 } 220 _SkipStream(Stream<T> source, int count) : this._remaining = count, super(sourc e) {
223 void _handleData(T inputEvent, _EventSink<T> sink) { 221 if (count is! int || count < 0) throw new ArgumentError(count);
224 if (_remaining > 0) { 222 }
225 sink._add(inputEvent); 223 void _handleData(T inputEvent, _EventSink<T> sink) {
226 _remaining -= 1; 224 if (_remaining > 0) {
227 if (_remaining == 0) { 225 _remaining--;
228 sink._close(); 226 return;}
229 } 227 sink._add(inputEvent);
230 } 228 }
231 } 229 }
232 } 230 class _SkipWhileStream<T> extends _ForwardingStream<T, T> {final _Predicate<T> _test;
233 class _TakeWhileStream<T> extends _ForwardingStream<T, T> { 231 bool _hasFailed = false;
234 final _Predicate<T> _test; 232 _SkipWhileStream(Stream<T> source, bool test(T value)) : this._test = test, sup er(source);
235 _TakeWhileStream(Stream<T> source, bool test(T value)) 233 void _handleData(T inputEvent, _EventSink<T> sink) {
236 : this._test = test, 234 if (_hasFailed) {
237 super(source); 235 sink._add(inputEvent);
238 void _handleData(T inputEvent, _EventSink<T> sink) { 236 return;}
239 bool satisfies; 237 bool satisfies;
240 try { 238 try {
241 satisfies = _test(inputEvent); 239 satisfies = _test(inputEvent);
242 } catch (e, s) { 240 }
243 _addErrorWithReplacement(sink, e, s); 241 catch (e, s) {
244 sink._close(); 242 _addErrorWithReplacement(sink, e, s);
245 return; 243 _hasFailed = true;
246 } 244 return;}
247 if (satisfies) { 245 if (!satisfies) {
248 sink._add(inputEvent); 246 _hasFailed = true;
249 } else { 247 sink._add(inputEvent);
250 sink._close(); 248 }
251 } 249 }
252 } 250 }
253 } 251 typedef bool _Equality<T>(T a, T b);
254 class _SkipStream<T> extends _ForwardingStream<T, T> { 252 class _DistinctStream<T> extends _ForwardingStream<T, T> {static var _SENTINEL = new Object();
255 int _remaining; 253 _Equality<T> _equals;
256 _SkipStream(Stream<T> source, int count) 254 var _previous = _SENTINEL;
257 : this._remaining = count, 255 _DistinctStream(Stream<T> source, bool equals(T a, T b)) : _equals = equals, su per(source);
258 super(source) { 256 void _handleData(T inputEvent, _EventSink<T> sink) {
259 if (count is! int || count < 0) throw new ArgumentError(count); 257 if (identical(_previous, _SENTINEL)) {
260 } 258 _previous = inputEvent;
261 void _handleData(T inputEvent, _EventSink<T> sink) { 259 return sink._add(inputEvent);
262 if (_remaining > 0) { 260 }
263 _remaining--; 261 else {
264 return; 262 bool isEqual;
265 } 263 try {
266 sink._add(inputEvent); 264 if (_equals == null) {
267 } 265 isEqual = (_previous == inputEvent);
268 } 266 }
269 class _SkipWhileStream<T> extends _ForwardingStream<T, T> { 267 else {
270 final _Predicate<T> _test; 268 isEqual = _equals(DDC$RT.cast(_previous, dynamic, T, "CastGeneral", """line 426, column 29 of dart:async/stream_pipe.dart: """, _previous is T, false), inputEve nt);
271 bool _hasFailed = false; 269 }
272 _SkipWhileStream(Stream<T> source, bool test(T value)) 270 }
273 : this._test = test, 271 catch (e, s) {
274 super(source); 272 _addErrorWithReplacement(sink, e, s);
275 void _handleData(T inputEvent, _EventSink<T> sink) { 273 return null;
276 if (_hasFailed) { 274 }
277 sink._add(inputEvent); 275 if (!isEqual) {
278 return; 276 sink._add(inputEvent);
279 } 277 _previous = inputEvent;
280 bool satisfies; 278 }
281 try { 279 }
282 satisfies = _test(inputEvent); 280 }
283 } catch (e, s) { 281 }
284 _addErrorWithReplacement(sink, e, s);
285 _hasFailed = true;
286 return;
287 }
288 if (!satisfies) {
289 _hasFailed = true;
290 sink._add(inputEvent);
291 }
292 }
293 }
294 typedef bool _Equality<T>(T a, T b);
295 class _DistinctStream<T> extends _ForwardingStream<T, T> {
296 static var _SENTINEL = new Object();
297 _Equality<T> _equals;
298 var _previous = _SENTINEL;
299 _DistinctStream(Stream<T> source, bool equals(T a, T b))
300 : _equals = equals,
301 super(source);
302 void _handleData(T inputEvent, _EventSink<T> sink) {
303 if (identical(_previous, _SENTINEL)) {
304 _previous = inputEvent;
305 return sink._add(inputEvent);
306 } else {
307 bool isEqual;
308 try {
309 if (_equals == null) {
310 isEqual = (_previous == inputEvent);
311 } else {
312 isEqual = _equals(DDC$RT.cast(_previous, dynamic, T, "CastGeneral",
313 """line 426, column 29 of dart:async/stream_pipe.dart: """,
314 _previous is T, false), inputEvent);
315 }
316 } catch (e, s) {
317 _addErrorWithReplacement(sink, e, s);
318 return null;
319 }
320 if (!isEqual) {
321 sink._add(inputEvent);
322 _previous = inputEvent;
323 }
324 }
325 }
326 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698