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

Side by Side Diff: test/dart_codegen/expect/async/future_impl.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 typedef dynamic _FutureOnValue<T>(T value);
3 typedef dynamic _FutureOnValue<T>(T value); 3 typedef bool _FutureErrorTest(var error);
4 typedef bool _FutureErrorTest(var error); 4 typedef _FutureAction();
5 typedef _FutureAction(); 5 abstract class _Completer<T> implements Completer<T> {final _Future<T> future = new _Future<T>();
6 abstract class _Completer<T> implements Completer<T> { 6 void complete([value]);
7 final _Future<T> future = new _Future<T>(); 7 void completeError(Object error, [StackTrace stackTrace]) {
8 void complete([value]); 8 error = _nonNullError(error);
9 void completeError(Object error, [StackTrace stackTrace]) { 9 if (!future._mayComplete) throw new StateError("Future already completed");
10 error = _nonNullError(error); 10 AsyncError replacement = Zone.current.errorCallback(error, stackTrace);
11 if (!future._mayComplete) throw new StateError("Future already completed"); 11 if (replacement != null) {
12 AsyncError replacement = Zone.current.errorCallback(error, stackTrace); 12 error = _nonNullError(replacement.error);
13 if (replacement != null) { 13 stackTrace = replacement.stackTrace;
14 error = _nonNullError(replacement.error); 14 }
15 stackTrace = replacement.stackTrace; 15 _completeError(error, stackTrace);
16 } 16 }
17 _completeError(error, stackTrace); 17 void _completeError(Object error, StackTrace stackTrace);
18 } 18 bool get isCompleted => !future._mayComplete;
19 void _completeError(Object error, StackTrace stackTrace); 19 }
20 bool get isCompleted => !future._mayComplete; 20 class _AsyncCompleter<T> extends _Completer<T> {void complete([value]) {
21 } 21 if (!future._mayComplete) throw new StateError("Future already completed");
22 class _AsyncCompleter<T> extends _Completer<T> { 22 future._asyncComplete(value);
23 void complete([value]) { 23 }
24 if (!future._mayComplete) throw new StateError("Future already completed"); 24 void _completeError(Object error, StackTrace stackTrace) {
25 future._asyncComplete(value); 25 future._asyncCompleteError(error, stackTrace);
26 } 26 }
27 void _completeError(Object error, StackTrace stackTrace) { 27 }
28 future._asyncCompleteError(error, stackTrace); 28 class _SyncCompleter<T> extends _Completer<T> {void complete([value]) {
29 } 29 if (!future._mayComplete) throw new StateError("Future already completed");
30 } 30 future._complete(value);
31 class _SyncCompleter<T> extends _Completer<T> { 31 }
32 void complete([value]) { 32 void _completeError(Object error, StackTrace stackTrace) {
33 if (!future._mayComplete) throw new StateError("Future already completed"); 33 future._completeError(error, stackTrace);
34 future._complete(value); 34 }
35 } 35 }
36 void _completeError(Object error, StackTrace stackTrace) { 36 class _FutureListener {static const int MASK_VALUE = 1;
37 future._completeError(error, stackTrace); 37 static const int MASK_ERROR = 2;
38 } 38 static const int MASK_TEST_ERROR = 4;
39 } 39 static const int MASK_WHENCOMPLETE = 8;
40 class _FutureListener { 40 static const int STATE_CHAIN = 0;
41 static const int MASK_VALUE = 1; 41 static const int STATE_THEN = MASK_VALUE;
42 static const int MASK_ERROR = 2; 42 static const int STATE_THEN_ONERROR = MASK_VALUE | MASK_ERROR;
43 static const int MASK_TEST_ERROR = 4; 43 static const int STATE_CATCHERROR = MASK_ERROR;
44 static const int MASK_WHENCOMPLETE = 8; 44 static const int STATE_CATCHERROR_TEST = MASK_ERROR | MASK_TEST_ERROR;
45 static const int STATE_CHAIN = 0; 45 static const int STATE_WHENCOMPLETE = MASK_WHENCOMPLETE;
46 static const int STATE_THEN = MASK_VALUE; 46 _FutureListener _nextListener = null;
47 static const int STATE_THEN_ONERROR = MASK_VALUE | MASK_ERROR; 47 final _Future result;
48 static const int STATE_CATCHERROR = MASK_ERROR; 48 final int state;
49 static const int STATE_CATCHERROR_TEST = MASK_ERROR | MASK_TEST_ERROR; 49 final Function callback;
50 static const int STATE_WHENCOMPLETE = MASK_WHENCOMPLETE; 50 final Function errorCallback;
51 _FutureListener _nextListener = null; 51 _FutureListener.then(this.result, _FutureOnValue onValue, Function errorCallbac k) : callback = onValue, errorCallback = errorCallback, state = (errorCallback = = null) ? STATE_THEN : STATE_THEN_ONERROR;
52 final _Future result; 52 _FutureListener.catchError(this.result, this.errorCallback, _FutureErrorTest te st) : callback = test, state = (test == null) ? STATE_CATCHERROR : STATE_CATCHER ROR_TEST;
53 final int state; 53 _FutureListener.whenComplete(this.result, _FutureAction onComplete) : callback = onComplete, errorCallback = null, state = STATE_WHENCOMPLETE;
54 final Function callback; 54 _FutureListener.chain(this.result) : callback = null, errorCallback = null, sta te = STATE_CHAIN;
55 final Function errorCallback; 55 Zone get _zone => result._zone;
56 _FutureListener.then( 56 bool get handlesValue => (state & MASK_VALUE != 0);
57 this.result, _FutureOnValue onValue, Function errorCallback) 57 bool get handlesError => (state & MASK_ERROR != 0);
58 : callback = onValue, 58 bool get hasErrorTest => (state == STATE_CATCHERROR_TEST);
59 errorCallback = errorCallback, 59 bool get handlesComplete => (state == STATE_WHENCOMPLETE);
60 state = (errorCallback == null) ? STATE_THEN : STATE_THEN_ONERROR; 60 _FutureOnValue get _onValue {
61 _FutureListener.catchError( 61 assert (handlesValue); return DDC$RT.cast(callback, Function, __t22, "CastGenera l", """line 112, column 12 of dart:async/future_impl.dart: """, callback is __t2 2, false);
62 this.result, this.errorCallback, _FutureErrorTest test) 62 }
63 : callback = test, 63 Function get _onError => errorCallback;
64 state = (test == null) ? STATE_CATCHERROR : STATE_CATCHERROR_TEST; 64 _FutureErrorTest get _errorTest {
65 _FutureListener.whenComplete(this.result, _FutureAction onComplete) 65 assert (hasErrorTest); return DDC$RT.cast(callback, Function, __t24, "CastGenera l", """line 117, column 12 of dart:async/future_impl.dart: """, callback is __t2 4, false);
66 : callback = onComplete, 66 }
67 errorCallback = null, 67 _FutureAction get _whenCompleteAction {
68 state = STATE_WHENCOMPLETE; 68 assert (handlesComplete); return DDC$RT.cast(callback, Function, __t26, "CastGen eral", """line 121, column 12 of dart:async/future_impl.dart: """, callback is _ _t26, false);
69 _FutureListener.chain(this.result) 69 }
70 : callback = null, 70 }
71 errorCallback = null, 71 class _Future<T> implements Future<T> {static const int _INCOMPLETE = 0;
72 state = STATE_CHAIN; 72 static const int _PENDING_COMPLETE = 1;
73 Zone get _zone => result._zone; 73 static const int _CHAINED = 2;
74 bool get handlesValue => (state & MASK_VALUE != 0); 74 static const int _VALUE = 4;
75 bool get handlesError => (state & MASK_ERROR != 0); 75 static const int _ERROR = 8;
76 bool get hasErrorTest => (state == STATE_CATCHERROR_TEST); 76 int _state = _INCOMPLETE;
77 bool get handlesComplete => (state == STATE_WHENCOMPLETE); 77 final Zone _zone = Zone.current;
78 _FutureOnValue get _onValue { 78 var _resultOrListeners;
79 assert(handlesValue); 79 _Future();
80 return DDC$RT.cast(callback, Function, __t22, "CastGeneral", 80 _Future.immediate(value) {
81 """line 112, column 12 of dart:async/future_impl.dart: """, 81 _asyncComplete(value);
82 callback is __t22, false); 82 }
83 } 83 _Future.immediateError(var error, [StackTrace stackTrace]) {
84 Function get _onError => errorCallback; 84 _asyncCompleteError(error, stackTrace);
85 _FutureErrorTest get _errorTest { 85 }
86 assert(hasErrorTest); 86 bool get _mayComplete => _state == _INCOMPLETE;
87 return DDC$RT.cast(callback, Function, __t24, "CastGeneral", 87 bool get _isChained => _state == _CHAINED;
88 """line 117, column 12 of dart:async/future_impl.dart: """, 88 bool get _isComplete => _state >= _VALUE;
89 callback is __t24, false); 89 bool get _hasValue => _state == _VALUE;
90 } 90 bool get _hasError => _state == _ERROR;
91 _FutureAction get _whenCompleteAction { 91 set _isChained(bool value) {
92 assert(handlesComplete); 92 if (value) {
93 return DDC$RT.cast(callback, Function, __t26, "CastGeneral", 93 assert (!_isComplete); _state = _CHAINED;
94 """line 121, column 12 of dart:async/future_impl.dart: """, 94 }
95 callback is __t26, false); 95 else {
96 } 96 assert (_isChained); _state = _INCOMPLETE;
97 } 97 }
98 class _Future<T> implements Future<T> { 98 }
99 static const int _INCOMPLETE = 0; 99 Future then(f(T value), {
100 static const int _PENDING_COMPLETE = 1; 100 Function onError}
101 static const int _CHAINED = 2; 101 ) {
102 static const int _VALUE = 4; 102 _Future result = new _Future();
103 static const int _ERROR = 8; 103 if (!identical(result._zone, _ROOT_ZONE)) {
104 int _state = _INCOMPLETE; 104 f = result._zone.registerUnaryCallback(DDC$RT.wrap((dynamic f(T __u27)) {
105 final Zone _zone = Zone.current; 105 dynamic c(T x0) => f(DDC$RT.cast(x0, dynamic, T, "CastParam", """line 208, colum n 46 of dart:async/future_impl.dart: """, x0 is T, false));
106 var _resultOrListeners; 106 return f == null ? null : c;
107 _Future(); 107 }
108 _Future.immediate(value) { 108 , f, DDC$RT.type((__t28<T> _) {
109 _asyncComplete(value); 109 }
110 } 110 ), __t22, "Wrap", """line 208, column 46 of dart:async/future_impl.dart: """, f is __t22));
111 _Future.immediateError(var error, [StackTrace stackTrace]) { 111 if (onError != null) {
112 _asyncCompleteError(error, stackTrace); 112 onError = _registerErrorHandler(onError, result._zone);
113 } 113 }
114 bool get _mayComplete => _state == _INCOMPLETE; 114 }
115 bool get _isChained => _state == _CHAINED; 115 _addListener(new _FutureListener.then(result, f, onError));
116 bool get _isComplete => _state >= _VALUE; 116 return result;
117 bool get _hasValue => _state == _VALUE; 117 }
118 bool get _hasError => _state == _ERROR; 118 Future catchError(Function onError, {
119 set _isChained(bool value) { 119 bool test(error)}
120 if (value) { 120 ) {
121 assert(!_isComplete); 121 _Future result = new _Future();
122 _state = _CHAINED; 122 if (!identical(result._zone, _ROOT_ZONE)) {
123 } else { 123 onError = _registerErrorHandler(onError, result._zone);
124 assert(_isChained); 124 if (test != null) test = ((__x32) => DDC$RT.wrap((dynamic f(dynamic __u31)) {
125 _state = _INCOMPLETE; 125 dynamic c(dynamic x0) => ((__x30) => DDC$RT.cast(__x30, dynamic, bool, "CastResu lt", """line 221, column 32 of dart:async/future_impl.dart: """, __x30 is bool, true))(f(x0));
126 } 126 return f == null ? null : c;
127 } 127 }
128 Future then(f(T value), {Function onError}) { 128 , __x32, __t22, __t24, "Wrap", """line 221, column 32 of dart:async/future_impl. dart: """, __x32 is __t24))(result._zone.registerUnaryCallback(test));
129 _Future result = new _Future(); 129 }
130 if (!identical(result._zone, _ROOT_ZONE)) { 130 _addListener(new _FutureListener.catchError(result, onError, test));
131 f = result._zone.registerUnaryCallback(DDC$RT.wrap((dynamic f(T __u27)) { 131 return result;
132 dynamic c(T x0) => f(DDC$RT.cast(x0, dynamic, T, "CastParam", 132 }
133 """line 208, column 46 of dart:async/future_impl.dart: """, x0 is T, 133 Future<T> whenComplete(action()) {
134 false)); 134 _Future result = new _Future<T>();
135 return f == null ? null : c; 135 if (!identical(result._zone, _ROOT_ZONE)) {
136 }, f, DDC$RT.type((__t28<T> _) {}), __t22, "Wrap", 136 action = result._zone.registerCallback(action);
137 """line 208, column 46 of dart:async/future_impl.dart: """, 137 }
138 f is __t22)); 138 _addListener(new _FutureListener.whenComplete(result, action));
139 if (onError != null) { 139 return DDC$RT.cast(result, DDC$RT.type((_Future<dynamic> _) {
140 onError = _registerErrorHandler(onError, result._zone); 140 }
141 ), DDC$RT.type((Future<T> _) {
142 }
143 ), "CastDynamic", """line 233, column 12 of dart:async/future_impl.dart: """, re sult is Future<T>, false);
144 }
145 Stream<T> asStream() => ((__x33) => DDC$RT.cast(__x33, DDC$RT.type((Stream<dyna mic> _) {
146 }
147 ), DDC$RT.type((Stream<T> _) {
148 }
149 ), "CastExact", """line 236, column 27 of dart:async/future_impl.dart: """, __x3 3 is Stream<T>, false))(new Stream.fromFuture(this));
150 void _markPendingCompletion() {
151 if (!_mayComplete) throw new StateError("Future already completed");
152 _state = _PENDING_COMPLETE;
153 }
154 T get _value {
155 assert (_isComplete && _hasValue); return DDC$RT.cast(_resultOrListeners, dynami c, T, "CastGeneral", """line 245, column 12 of dart:async/future_impl.dart: """, _resultOrListeners is T, false);
156 }
157 AsyncError get _error {
158 assert (_isComplete && _hasError); return DDC$RT.cast(_resultOrListeners, dynami c, AsyncError, "CastGeneral", """line 250, column 12 of dart:async/future_impl.d art: """, _resultOrListeners is AsyncError, true);
159 }
160 void _setValue(T value) {
161 assert (!_isComplete); _state = _VALUE;
162 _resultOrListeners = value;
163 }
164 void _setErrorObject(AsyncError error) {
165 assert (!_isComplete); _state = _ERROR;
166 _resultOrListeners = error;
167 }
168 void _setError(Object error, StackTrace stackTrace) {
169 _setErrorObject(new AsyncError(error, stackTrace));
170 }
171 void _addListener(_FutureListener listener) {
172 assert (listener._nextListener == null); if (_isComplete) {
173 _zone.scheduleMicrotask(() {
174 _propagateToListeners(this, listener);
175 }
176 );
177 }
178 else {
179 listener._nextListener = DDC$RT.cast(_resultOrListeners, dynamic, _FutureListene r, "CastGeneral", """line 277, column 32 of dart:async/future_impl.dart: """, _r esultOrListeners is _FutureListener, true);
180 _resultOrListeners = listener;
181 }
182 }
183 _FutureListener _removeListeners() {
184 assert (!_isComplete); _FutureListener current = DDC$RT.cast(_resultOrListeners, dynamic, _FutureListener, "CastGeneral", """line 286, column 31 of dart:async/f uture_impl.dart: """, _resultOrListeners is _FutureListener, true);
185 _resultOrListeners = null;
186 _FutureListener prev = null;
187 while (current != null) {
188 _FutureListener next = current._nextListener;
189 current._nextListener = prev;
190 prev = current;
191 current = next;
192 }
193 return prev;
194 }
195 static void _chainForeignFuture(Future source, _Future target) {
196 assert (!target._isComplete); assert (source is! _Future); target._isChained = t rue;
197 source.then((value) {
198 assert (target._isChained); target._completeWithValue(value);
199 }
200 , onError: (error, [stackTrace]) {
201 assert (target._isChained); target._completeError(error, DDC$RT.cast(stackTrace, dynamic, StackTrace, "CastGeneral", """line 317, column 38 of dart:async/future _impl.dart: """, stackTrace is StackTrace, true));
202 }
203 );
204 }
205 static void _chainCoreFuture(_Future source, _Future target) {
206 assert (!target._isComplete); assert (source is _Future); target._isChained = tr ue;
207 _FutureListener listener = new _FutureListener.chain(target);
208 if (source._isComplete) {
209 _propagateToListeners(source, listener);
210 }
211 else {
212 source._addListener(listener);
213 }
214 }
215 void _complete(value) {
216 assert (!_isComplete); if (value is Future) {
217 if (value is _Future) {
218 _chainCoreFuture(DDC$RT.cast(value, dynamic, DDC$RT.type((_Future<dynamic> _) {
219 }
220 ), "CastGeneral", """line 341, column 26 of dart:async/future_impl.dart: """, va lue is _Future<dynamic>, true), this);
221 }
222 else {
223 _chainForeignFuture(DDC$RT.cast(value, dynamic, DDC$RT.type((Future<dynamic> _) {
224 }
225 ), "CastGeneral", """line 343, column 29 of dart:async/future_impl.dart: """, va lue is Future<dynamic>, true), this);
226 }
227 }
228 else {
229 _FutureListener listeners = _removeListeners();
230 _setValue(DDC$RT.cast(value, dynamic, T, "CastGeneral", """line 347, column 17 of dart:async/future_impl.dart: """, value is T, false));
231 _propagateToListeners(this, listeners);
232 }
233 }
234 void _completeWithValue(value) {
235 assert (!_isComplete); assert (value is! Future); _FutureListener listeners = _r emoveListeners();
236 _setValue(DDC$RT.cast(value, dynamic, T, "CastGeneral", """line 357, column 15 of dart:async/future_impl.dart: """, value is T, false));
237 _propagateToListeners(this, listeners);
238 }
239 void _completeError(error, [StackTrace stackTrace]) {
240 assert (!_isComplete); _FutureListener listeners = _removeListeners();
241 _setError(error, stackTrace);
242 _propagateToListeners(this, listeners);
243 }
244 void _asyncComplete(value) {
245 assert (!_isComplete); if (value == null) {
246 }
247 else if (value is Future) {
248 Future<T> typedFuture = DDC$RT.cast(value, dynamic, DDC$RT.type((Future<T> _) {
249 }
250 ), "CastGeneral", """line 386, column 31 of dart:async/future_impl.dart: """, va lue is Future<T>, false);
251 if (typedFuture is _Future) {
252 _Future<T> coreFuture = DDC$RT.cast(typedFuture, DDC$RT.type((Future<T> _) {
253 }
254 ), DDC$RT.type((_Future<T> _) {
255 }
256 ), "CastGeneral", """line 388, column 33 of dart:async/future_impl.dart: """, ty pedFuture is _Future<T>, false);
257 if (coreFuture._isComplete && coreFuture._hasError) {
258 _markPendingCompletion();
259 _zone.scheduleMicrotask(() {
260 _chainCoreFuture(coreFuture, this);
261 }
262 );
263 }
264 else {
265 _chainCoreFuture(coreFuture, this);
266 }
267 }
268 else {
269 _chainForeignFuture(typedFuture, this);
270 }
271 return;}
272 else {
273 T typedValue = DDC$RT.cast(value, dynamic, T, "CastGeneral", """line 407, column 22 of dart:async/future_impl.dart: """, value is T, false);
274 }
275 _markPendingCompletion();
276 _zone.scheduleMicrotask(() {
277 _completeWithValue(value);
278 }
279 );
280 }
281 void _asyncCompleteError(error, StackTrace stackTrace) {
282 assert (!_isComplete); _markPendingCompletion();
283 _zone.scheduleMicrotask(() {
284 _completeError(error, stackTrace);
285 }
286 );
287 }
288 static void _propagateToListeners(_Future source, _FutureListener listeners) {
289 while (true) {
290 assert (source._isComplete); bool hasError = source._hasError;
291 if (listeners == null) {
292 if (hasError) {
293 AsyncError asyncError = source._error;
294 source._zone.handleUncaughtError(asyncError.error, asyncError.stackTrace);
295 }
296 return;}
297 while (listeners._nextListener != null) {
298 _FutureListener listener = listeners;
299 listeners = listener._nextListener;
300 listener._nextListener = null;
301 _propagateToListeners(source, listener);
302 }
303 _FutureListener listener = listeners;
304 bool listenerHasValue = true;
305 final sourceValue = hasError ? null : source._value;
306 var listenerValueOrError = sourceValue;
307 bool isPropagationAborted = false;
308 if (hasError || (listener.handlesValue || listener.handlesComplete)) {
309 Zone zone = listener._zone;
310 if (hasError && !source._zone.inSameErrorZone(zone)) {
311 AsyncError asyncError = source._error;
312 source._zone.handleUncaughtError(asyncError.error, asyncError.stackTrace);
313 return;}
314 Zone oldZone;
315 if (!identical(Zone.current, zone)) {
316 oldZone = Zone._enter(zone);
317 }
318 bool handleValueCallback() {
319 try {
320 listenerValueOrError = zone.runUnary(listener._onValue, sourceValue);
321 return true;
322 }
323 catch (e, s) {
324 listenerValueOrError = new AsyncError(e, s);
325 return false;
326 }
327 }
328 void handleError() {
329 AsyncError asyncError = source._error;
330 bool matchesTest = true;
331 if (listener.hasErrorTest) {
332 _FutureErrorTest test = listener._errorTest;
333 try {
334 matchesTest = ((__x34) => DDC$RT.cast(__x34, dynamic, bool, "CastGeneral", " ""line 499, column 29 of dart:async/future_impl.dart: """, __x34 is bool, true)) (zone.runUnary(test, asyncError.error));
335 }
336 catch (e, s) {
337 listenerValueOrError = identical(asyncError.error, e) ? asyncError : new Asy ncError(e, s);
338 listenerHasValue = false;
339 return;}
340 }
341 Function errorCallback = listener._onError;
342 if (matchesTest && errorCallback != null) {
343 try {
344 if (errorCallback is ZoneBinaryCallback) {
345 listenerValueOrError = zone.runBinary(errorCallback, asyncError.error, asy ncError.stackTrace);
141 } 346 }
142 } 347 else {
143 _addListener(new _FutureListener.then(result, f, onError)); 348 listenerValueOrError = zone.runUnary(DDC$RT.cast(errorCallback, Function, __t22, "CastGeneral", """line 515, column 54 of dart:async/future_impl.dart: """ , errorCallback is __t22, false), asyncError.error);
144 return result;
145 }
146 Future catchError(Function onError, {bool test(error)}) {
147 _Future result = new _Future();
148 if (!identical(result._zone, _ROOT_ZONE)) {
149 onError = _registerErrorHandler(onError, result._zone);
150 if (test != null) test = ((__x32) => DDC$RT.wrap(
151 (dynamic f(dynamic __u31)) {
152 dynamic c(dynamic x0) => ((__x30) => DDC$RT.cast(__x30, dynamic, bool,
153 "CastResult",
154 """line 221, column 32 of dart:async/future_impl.dart: """,
155 __x30 is bool, true))(f(x0));
156 return f == null ? null : c;
157 }, __x32, __t22, __t24, "Wrap",
158 """line 221, column 32 of dart:async/future_impl.dart: """,
159 __x32 is __t24))(result._zone.registerUnaryCallback(test));
160 }
161 _addListener(new _FutureListener.catchError(result, onError, test));
162 return result;
163 }
164 Future<T> whenComplete(action()) {
165 _Future result = new _Future<T>();
166 if (!identical(result._zone, _ROOT_ZONE)) {
167 action = result._zone.registerCallback(action);
168 }
169 _addListener(new _FutureListener.whenComplete(result, action));
170 return DDC$RT.cast(result, DDC$RT.type((_Future<dynamic> _) {}),
171 DDC$RT.type((Future<T> _) {}), "CastDynamic",
172 """line 233, column 12 of dart:async/future_impl.dart: """,
173 result is Future<T>, false);
174 }
175 Stream<T> asStream() => ((__x33) => DDC$RT.cast(__x33,
176 DDC$RT.type((Stream<dynamic> _) {}), DDC$RT.type((Stream<T> _) {}),
177 "CastExact", """line 236, column 27 of dart:async/future_impl.dart: """,
178 __x33 is Stream<T>, false))(new Stream.fromFuture(this));
179 void _markPendingCompletion() {
180 if (!_mayComplete) throw new StateError("Future already completed");
181 _state = _PENDING_COMPLETE;
182 }
183 T get _value {
184 assert(_isComplete && _hasValue);
185 return DDC$RT.cast(_resultOrListeners, dynamic, T, "CastGeneral",
186 """line 245, column 12 of dart:async/future_impl.dart: """,
187 _resultOrListeners is T, false);
188 }
189 AsyncError get _error {
190 assert(_isComplete && _hasError);
191 return DDC$RT.cast(_resultOrListeners, dynamic, AsyncError, "CastGeneral",
192 """line 250, column 12 of dart:async/future_impl.dart: """,
193 _resultOrListeners is AsyncError, true);
194 }
195 void _setValue(T value) {
196 assert(!_isComplete);
197 _state = _VALUE;
198 _resultOrListeners = value;
199 }
200 void _setErrorObject(AsyncError error) {
201 assert(!_isComplete);
202 _state = _ERROR;
203 _resultOrListeners = error;
204 }
205 void _setError(Object error, StackTrace stackTrace) {
206 _setErrorObject(new AsyncError(error, stackTrace));
207 }
208 void _addListener(_FutureListener listener) {
209 assert(listener._nextListener == null);
210 if (_isComplete) {
211 _zone.scheduleMicrotask(() {
212 _propagateToListeners(this, listener);
213 });
214 } else {
215 listener._nextListener = DDC$RT.cast(_resultOrListeners, dynamic,
216 _FutureListener, "CastGeneral",
217 """line 277, column 32 of dart:async/future_impl.dart: """,
218 _resultOrListeners is _FutureListener, true);
219 _resultOrListeners = listener;
220 }
221 }
222 _FutureListener _removeListeners() {
223 assert(!_isComplete);
224 _FutureListener current = DDC$RT.cast(_resultOrListeners, dynamic,
225 _FutureListener, "CastGeneral",
226 """line 286, column 31 of dart:async/future_impl.dart: """,
227 _resultOrListeners is _FutureListener, true);
228 _resultOrListeners = null;
229 _FutureListener prev = null;
230 while (current != null) {
231 _FutureListener next = current._nextListener;
232 current._nextListener = prev;
233 prev = current;
234 current = next;
235 }
236 return prev;
237 }
238 static void _chainForeignFuture(Future source, _Future target) {
239 assert(!target._isComplete);
240 assert(source is! _Future);
241 target._isChained = true;
242 source.then((value) {
243 assert(target._isChained);
244 target._completeWithValue(value);
245 }, onError: (error, [stackTrace]) {
246 assert(target._isChained);
247 target._completeError(error, DDC$RT.cast(stackTrace, dynamic, StackTrace,
248 "CastGeneral",
249 """line 317, column 38 of dart:async/future_impl.dart: """,
250 stackTrace is StackTrace, true));
251 });
252 }
253 static void _chainCoreFuture(_Future source, _Future target) {
254 assert(!target._isComplete);
255 assert(source is _Future);
256 target._isChained = true;
257 _FutureListener listener = new _FutureListener.chain(target);
258 if (source._isComplete) {
259 _propagateToListeners(source, listener);
260 } else {
261 source._addListener(listener);
262 }
263 }
264 void _complete(value) {
265 assert(!_isComplete);
266 if (value is Future) {
267 if (value is _Future) {
268 _chainCoreFuture(DDC$RT.cast(value, dynamic,
269 DDC$RT.type((_Future<dynamic> _) {}), "CastGeneral",
270 """line 341, column 26 of dart:async/future_impl.dart: """,
271 value is _Future<dynamic>, true), this);
272 } else {
273 _chainForeignFuture(DDC$RT.cast(value, dynamic,
274 DDC$RT.type((Future<dynamic> _) {}), "CastGeneral",
275 """line 343, column 29 of dart:async/future_impl.dart: """,
276 value is Future<dynamic>, true), this);
277 } 349 }
278 } else { 350 }
279 _FutureListener listeners = _removeListeners(); 351 catch (e, s) {
280 _setValue(DDC$RT.cast(value, dynamic, T, "CastGeneral", 352 listenerValueOrError = identical(asyncError.error, e) ? asyncError : new Asy ncError(e, s);
281 """line 347, column 17 of dart:async/future_impl.dart: """, 353 listenerHasValue = false;
282 value is T, false)); 354 return;}
283 _propagateToListeners(this, listeners); 355 listenerHasValue = true;
284 } 356 }
285 } 357 else {
286 void _completeWithValue(value) { 358 listenerValueOrError = asyncError;
287 assert(!_isComplete); 359 listenerHasValue = false;
288 assert(value is! Future); 360 }
289 _FutureListener listeners = _removeListeners(); 361 }
290 _setValue(DDC$RT.cast(value, dynamic, T, "CastGeneral", 362 void handleWhenCompleteCallback() {
291 """line 357, column 15 of dart:async/future_impl.dart: """, value is T, 363 var completeResult;
292 false)); 364 try {
293 _propagateToListeners(this, listeners); 365 completeResult = zone.run(listener._whenCompleteAction);
294 } 366 }
295 void _completeError(error, [StackTrace stackTrace]) { 367 catch (e, s) {
296 assert(!_isComplete); 368 if (hasError && identical(source._error.error, e)) {
297 _FutureListener listeners = _removeListeners(); 369 listenerValueOrError = source._error;
298 _setError(error, stackTrace); 370 }
299 _propagateToListeners(this, listeners); 371 else {
300 } 372 listenerValueOrError = new AsyncError(e, s);
301 void _asyncComplete(value) { 373 }
302 assert(!_isComplete); 374 listenerHasValue = false;
303 if (value == null) {} else if (value is Future) { 375 return;}
304 Future<T> typedFuture = DDC$RT.cast(value, dynamic, 376 if (completeResult is Future) {
305 DDC$RT.type((Future<T> _) {}), "CastGeneral", 377 _Future result = listener.result;
306 """line 386, column 31 of dart:async/future_impl.dart: """, 378 result._isChained = true;
307 value is Future<T>, false); 379 isPropagationAborted = true;
308 if (typedFuture is _Future) { 380 completeResult.then((ignored) {
309 _Future<T> coreFuture = DDC$RT.cast(typedFuture, 381 _propagateToListeners(source, new _FutureListener.chain(result));
310 DDC$RT.type((Future<T> _) {}), DDC$RT.type((_Future<T> _) {}), 382 }
311 "CastGeneral", 383 , onError: (error, [stackTrace]) {
312 """line 388, column 33 of dart:async/future_impl.dart: """, 384 if (completeResult is! _Future) {
313 typedFuture is _Future<T>, false); 385 completeResult = new _Future();
314 if (coreFuture._isComplete && coreFuture._hasError) { 386 completeResult._setError(error, stackTrace);
315 _markPendingCompletion();
316 _zone.scheduleMicrotask(() {
317 _chainCoreFuture(coreFuture, this);
318 });
319 } else {
320 _chainCoreFuture(coreFuture, this);
321 }
322 } else {
323 _chainForeignFuture(typedFuture, this);
324 } 387 }
325 return; 388 _propagateToListeners(DDC$RT.cast(completeResult, dynamic, DDC$RT.type((_Fu ture<dynamic> _) {
326 } else {
327 T typedValue = DDC$RT.cast(value, dynamic, T, "CastGeneral",
328 """line 407, column 22 of dart:async/future_impl.dart: """,
329 value is T, false);
330 }
331 _markPendingCompletion();
332 _zone.scheduleMicrotask(() {
333 _completeWithValue(value);
334 });
335 }
336 void _asyncCompleteError(error, StackTrace stackTrace) {
337 assert(!_isComplete);
338 _markPendingCompletion();
339 _zone.scheduleMicrotask(() {
340 _completeError(error, stackTrace);
341 });
342 }
343 static void _propagateToListeners(_Future source, _FutureListener listeners) {
344 while (true) {
345 assert(source._isComplete);
346 bool hasError = source._hasError;
347 if (listeners == null) {
348 if (hasError) {
349 AsyncError asyncError = source._error;
350 source._zone.handleUncaughtError(
351 asyncError.error, asyncError.stackTrace);
352 }
353 return;
354 } 389 }
355 while (listeners._nextListener != null) { 390 ), "CastGeneral", """line 559, column 37 of dart:async/future_impl.dart: """ , completeResult is _Future<dynamic>, true), new _FutureListener.chain(result));
356 _FutureListener listener = listeners; 391 }
357 listeners = listener._nextListener; 392 );
358 listener._nextListener = null; 393 }
359 _propagateToListeners(source, listener); 394 }
360 } 395 if (!hasError) {
361 _FutureListener listener = listeners; 396 if (listener.handlesValue) {
362 bool listenerHasValue = true; 397 listenerHasValue = handleValueCallback();
363 final sourceValue = hasError ? null : source._value; 398 }
364 var listenerValueOrError = sourceValue; 399 }
365 bool isPropagationAborted = false; 400 else {
366 if (hasError || (listener.handlesValue || listener.handlesComplete)) { 401 handleError();
367 Zone zone = listener._zone; 402 }
368 if (hasError && !source._zone.inSameErrorZone(zone)) { 403 if (listener.handlesComplete) {
369 AsyncError asyncError = source._error; 404 handleWhenCompleteCallback();
370 source._zone.handleUncaughtError( 405 }
371 asyncError.error, asyncError.stackTrace); 406 if (oldZone != null) Zone._leave(oldZone);
372 return; 407 if (isPropagationAborted) return; if (listenerHasValue && !identical(sourceValu e, listenerValueOrError) && listenerValueOrError is Future) {
373 } 408 Future chainSource = DDC$RT.cast(listenerValueOrError, dynamic, DDC$RT.type((Fut ure<dynamic> _) {
374 Zone oldZone; 409 }
375 if (!identical(Zone.current, zone)) { 410 ), "CastGeneral", """line 585, column 32 of dart:async/future_impl.dart: """, li stenerValueOrError is Future<dynamic>, true);
376 oldZone = Zone._enter(zone); 411 _Future result = listener.result;
377 } 412 if (chainSource is _Future) {
378 bool handleValueCallback() { 413 if (chainSource._isComplete) {
379 try { 414 result._isChained = true;
380 listenerValueOrError = 415 source = chainSource;
381 zone.runUnary(listener._onValue, sourceValue); 416 listeners = new _FutureListener.chain(result);
382 return true; 417 continue;
383 } catch (e, s) { 418 }
384 listenerValueOrError = new AsyncError(e, s); 419 else {
385 return false; 420 _chainCoreFuture(chainSource, result);
386 } 421 }
387 } 422 }
388 void handleError() { 423 else {
389 AsyncError asyncError = source._error; 424 _chainForeignFuture(chainSource, result);
390 bool matchesTest = true; 425 }
391 if (listener.hasErrorTest) { 426 return;}
392 _FutureErrorTest test = listener._errorTest; 427 }
393 try { 428 _Future result = listener.result;
394 matchesTest = ((__x34) => DDC$RT.cast(__x34, dynamic, bool, 429 listeners = result._removeListeners();
395 "CastGeneral", 430 if (listenerHasValue) {
396 """line 499, column 29 of dart:async/future_impl.dart: """, 431 result._setValue(listenerValueOrError);
397 __x34 is bool, true))(zone.runUnary(test, asyncError.error)); 432 }
398 } catch (e, s) { 433 else {
399 listenerValueOrError = identical(asyncError.error, e) 434 AsyncError asyncError = DDC$RT.cast(listenerValueOrError, dynamic, AsyncError, " CastGeneral", """line 610, column 33 of dart:async/future_impl.dart: """, listen erValueOrError is AsyncError, true);
400 ? asyncError 435 result._setErrorObject(asyncError);
401 : new AsyncError(e, s); 436 }
402 listenerHasValue = false; 437 source = result;
403 return; 438 }
404 } 439 }
405 } 440 Future timeout(Duration timeLimit, {
406 Function errorCallback = listener._onError; 441 onTimeout()}
407 if (matchesTest && errorCallback != null) { 442 ) {
408 try { 443 if (_isComplete) return new _Future.immediate(this);
409 if (errorCallback is ZoneBinaryCallback) { 444 _Future result = new _Future();
410 listenerValueOrError = zone.runBinary( 445 Timer timer;
411 errorCallback, asyncError.error, asyncError.stackTrace); 446 if (onTimeout == null) {
412 } else { 447 timer = new Timer(timeLimit, () {
413 listenerValueOrError = zone.runUnary(DDC$RT.cast(errorCallback, 448 result._completeError(new TimeoutException("Future not completed", timeLimit));
414 Function, __t22, "CastGeneral", 449 }
415 """line 515, column 54 of dart:async/future_impl.dart: """, 450 );
416 errorCallback is __t22, false), asyncError.error); 451 }
417 } 452 else {
418 } catch (e, s) { 453 Zone zone = Zone.current;
419 listenerValueOrError = identical(asyncError.error, e) 454 onTimeout = zone.registerCallback(onTimeout);
420 ? asyncError 455 timer = new Timer(timeLimit, () {
421 : new AsyncError(e, s); 456 try {
422 listenerHasValue = false; 457 result._complete(zone.run(onTimeout));
423 return; 458 }
424 } 459 catch (e, s) {
425 listenerHasValue = true; 460 result._completeError(e, s);
426 } else { 461 }
427 listenerValueOrError = asyncError; 462 }
428 listenerHasValue = false; 463 );
429 } 464 }
430 } 465 this.then((T v) {
431 void handleWhenCompleteCallback() { 466 if (timer.isActive) {
432 var completeResult; 467 timer.cancel();
433 try { 468 result._completeWithValue(v);
434 completeResult = zone.run(listener._whenCompleteAction); 469 }
435 } catch (e, s) { 470 }
436 if (hasError && identical(source._error.error, e)) { 471 , onError: (e, s) {
437 listenerValueOrError = source._error; 472 if (timer.isActive) {
438 } else { 473 timer.cancel();
439 listenerValueOrError = new AsyncError(e, s); 474 result._completeError(e, DDC$RT.cast(s, dynamic, StackTrace, "CastGeneral", """ line 646, column 34 of dart:async/future_impl.dart: """, s is StackTrace, true)) ;
440 } 475 }
441 listenerHasValue = false; 476 }
442 return; 477 );
443 } 478 return result;
444 if (completeResult is Future) { 479 }
445 _Future result = listener.result; 480 }
446 result._isChained = true; 481 typedef dynamic __t22(dynamic __u23);
447 isPropagationAborted = true; 482 typedef bool __t24(dynamic __u25);
448 completeResult.then((ignored) { 483 typedef dynamic __t26();
449 _propagateToListeners(source, new _FutureListener.chain(result)); 484 typedef dynamic __t28<T>(T __u29);
450 }, onError: (error, [stackTrace]) {
451 if (completeResult is! _Future) {
452 completeResult = new _Future();
453 completeResult._setError(error, stackTrace);
454 }
455 _propagateToListeners(DDC$RT.cast(completeResult, dynamic,
456 DDC$RT.type((_Future<dynamic> _) {}), "CastGeneral",
457 """line 559, column 37 of dart:async/future_impl.dart: """,
458 completeResult is _Future<dynamic>,
459 true), new _FutureListener.chain(result));
460 });
461 }
462 }
463 if (!hasError) {
464 if (listener.handlesValue) {
465 listenerHasValue = handleValueCallback();
466 }
467 } else {
468 handleError();
469 }
470 if (listener.handlesComplete) {
471 handleWhenCompleteCallback();
472 }
473 if (oldZone != null) Zone._leave(oldZone);
474 if (isPropagationAborted) return;
475 if (listenerHasValue &&
476 !identical(sourceValue, listenerValueOrError) &&
477 listenerValueOrError is Future) {
478 Future chainSource = DDC$RT.cast(listenerValueOrError, dynamic,
479 DDC$RT.type((Future<dynamic> _) {}), "CastGeneral",
480 """line 585, column 32 of dart:async/future_impl.dart: """,
481 listenerValueOrError is Future<dynamic>, true);
482 _Future result = listener.result;
483 if (chainSource is _Future) {
484 if (chainSource._isComplete) {
485 result._isChained = true;
486 source = chainSource;
487 listeners = new _FutureListener.chain(result);
488 continue;
489 } else {
490 _chainCoreFuture(chainSource, result);
491 }
492 } else {
493 _chainForeignFuture(chainSource, result);
494 }
495 return;
496 }
497 }
498 _Future result = listener.result;
499 listeners = result._removeListeners();
500 if (listenerHasValue) {
501 result._setValue(listenerValueOrError);
502 } else {
503 AsyncError asyncError = DDC$RT.cast(listenerValueOrError, dynamic,
504 AsyncError, "CastGeneral",
505 """line 610, column 33 of dart:async/future_impl.dart: """,
506 listenerValueOrError is AsyncError, true);
507 result._setErrorObject(asyncError);
508 }
509 source = result;
510 }
511 }
512 Future timeout(Duration timeLimit, {onTimeout()}) {
513 if (_isComplete) return new _Future.immediate(this);
514 _Future result = new _Future();
515 Timer timer;
516 if (onTimeout == null) {
517 timer = new Timer(timeLimit, () {
518 result._completeError(
519 new TimeoutException("Future not completed", timeLimit));
520 });
521 } else {
522 Zone zone = Zone.current;
523 onTimeout = zone.registerCallback(onTimeout);
524 timer = new Timer(timeLimit, () {
525 try {
526 result._complete(zone.run(onTimeout));
527 } catch (e, s) {
528 result._completeError(e, s);
529 }
530 });
531 }
532 this.then((T v) {
533 if (timer.isActive) {
534 timer.cancel();
535 result._completeWithValue(v);
536 }
537 }, onError: (e, s) {
538 if (timer.isActive) {
539 timer.cancel();
540 result._completeError(e, DDC$RT.cast(s, dynamic, StackTrace,
541 "CastGeneral",
542 """line 646, column 34 of dart:async/future_impl.dart: """,
543 s is StackTrace, true));
544 }
545 });
546 return result;
547 }
548 }
549 typedef dynamic __t22(dynamic __u23);
550 typedef bool __t24(dynamic __u25);
551 typedef dynamic __t26();
552 typedef dynamic __t28<T>(T __u29);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698