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

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

Issue 1010893004: Allow S->T <: dynamic->T (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Add comment 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 typedef dynamic _FutureOnValue<T>(T value); 2 typedef dynamic _FutureOnValue<T>(T value);
3 typedef bool _FutureErrorTest(var error); 3 typedef bool _FutureErrorTest(var error);
4 typedef _FutureAction(); 4 typedef _FutureAction();
5 abstract class _Completer<T> implements Completer<T> {final _Future<T> future = new _Future<T>(); 5 abstract class _Completer<T> implements Completer<T> {final _Future<T> future = new _Future<T>();
6 void complete([value]); 6 void complete([value]);
7 void completeError(Object error, [StackTrace stackTrace]) { 7 void completeError(Object error, [StackTrace stackTrace]) {
8 error = _nonNullError(error); 8 error = _nonNullError(error);
9 if (!future._mayComplete) throw new StateError("Future already completed"); 9 if (!future._mayComplete) throw new StateError("Future already completed");
10 AsyncError replacement = Zone.current.errorCallback(error, stackTrace); 10 AsyncError replacement = Zone.current.errorCallback(error, stackTrace);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 _FutureListener.then(this.result, _FutureOnValue onValue, Function errorCallbac k) : callback = onValue, errorCallback = errorCallback, state = (errorCallback = = null) ? STATE_THEN : STATE_THEN_ONERROR; 51 _FutureListener.then(this.result, _FutureOnValue onValue, Function errorCallbac k) : callback = onValue, errorCallback = errorCallback, state = (errorCallback = = null) ? STATE_THEN : STATE_THEN_ONERROR;
52 _FutureListener.catchError(this.result, this.errorCallback, _FutureErrorTest te st) : callback = test, state = (test == null) ? STATE_CATCHERROR : STATE_CATCHER ROR_TEST; 52 _FutureListener.catchError(this.result, this.errorCallback, _FutureErrorTest te st) : callback = test, state = (test == null) ? STATE_CATCHERROR : STATE_CATCHER ROR_TEST;
53 _FutureListener.whenComplete(this.result, _FutureAction onComplete) : callback = onComplete, errorCallback = null, state = STATE_WHENCOMPLETE; 53 _FutureListener.whenComplete(this.result, _FutureAction onComplete) : callback = onComplete, errorCallback = null, state = STATE_WHENCOMPLETE;
54 _FutureListener.chain(this.result) : callback = null, errorCallback = null, sta te = STATE_CHAIN; 54 _FutureListener.chain(this.result) : callback = null, errorCallback = null, sta te = STATE_CHAIN;
55 Zone get _zone => result._zone; 55 Zone get _zone => result._zone;
56 bool get handlesValue => (state & MASK_VALUE != 0); 56 bool get handlesValue => (state & MASK_VALUE != 0);
57 bool get handlesError => (state & MASK_ERROR != 0); 57 bool get handlesError => (state & MASK_ERROR != 0);
58 bool get hasErrorTest => (state == STATE_CATCHERROR_TEST); 58 bool get hasErrorTest => (state == STATE_CATCHERROR_TEST);
59 bool get handlesComplete => (state == STATE_WHENCOMPLETE); 59 bool get handlesComplete => (state == STATE_WHENCOMPLETE);
60 _FutureOnValue get _onValue { 60 _FutureOnValue get _onValue {
61 assert (handlesValue); return DEVC$RT.cast(callback, Function, __t22, "CastGener al", """line 112, column 12 of dart:async/future_impl.dart: """, callback is __t 22, false); 61 assert (handlesValue); return DEVC$RT.cast(callback, Function, __t14, "CastGener al", """line 112, column 12 of dart:async/future_impl.dart: """, callback is __t 14, false);
62 } 62 }
63 Function get _onError => errorCallback; 63 Function get _onError => errorCallback;
64 _FutureErrorTest get _errorTest { 64 _FutureErrorTest get _errorTest {
65 assert (hasErrorTest); return DEVC$RT.cast(callback, Function, __t24, "CastGener al", """line 117, column 12 of dart:async/future_impl.dart: """, callback is __t 24, false); 65 assert (hasErrorTest); return DEVC$RT.cast(callback, Function, __t16, "CastGener al", """line 117, column 12 of dart:async/future_impl.dart: """, callback is __t 16, false);
66 } 66 }
67 _FutureAction get _whenCompleteAction { 67 _FutureAction get _whenCompleteAction {
68 assert (handlesComplete); return DEVC$RT.cast(callback, Function, __t26, "CastGe neral", """line 121, column 12 of dart:async/future_impl.dart: """, callback is __t26, false); 68 assert (handlesComplete); return DEVC$RT.cast(callback, Function, __t18, "CastGe neral", """line 121, column 12 of dart:async/future_impl.dart: """, callback is __t18, false);
69 } 69 }
70 } 70 }
71 class _Future<T> implements Future<T> {static const int _INCOMPLETE = 0; 71 class _Future<T> implements Future<T> {static const int _INCOMPLETE = 0;
72 static const int _PENDING_COMPLETE = 1; 72 static const int _PENDING_COMPLETE = 1;
73 static const int _CHAINED = 2; 73 static const int _CHAINED = 2;
74 static const int _VALUE = 4; 74 static const int _VALUE = 4;
75 static const int _ERROR = 8; 75 static const int _ERROR = 8;
76 int _state = _INCOMPLETE; 76 int _state = _INCOMPLETE;
77 final Zone _zone = Zone.current; 77 final Zone _zone = Zone.current;
78 var _resultOrListeners; 78 var _resultOrListeners;
(...skipping 15 matching lines...) Expand all
94 } 94 }
95 else { 95 else {
96 assert (_isChained); _state = _INCOMPLETE; 96 assert (_isChained); _state = _INCOMPLETE;
97 } 97 }
98 } 98 }
99 Future then(f(T value), { 99 Future then(f(T value), {
100 Function onError} 100 Function onError}
101 ) { 101 ) {
102 _Future result = new _Future(); 102 _Future result = new _Future();
103 if (!identical(result._zone, _ROOT_ZONE)) { 103 if (!identical(result._zone, _ROOT_ZONE)) {
104 f = result._zone.registerUnaryCallback(DEVC$RT.wrap((dynamic f(T __u27)) { 104 f = ((__x22) => DEVC$RT.wrap((dynamic f(dynamic __u19)) {
105 dynamic c(T x0) => f(DEVC$RT.cast(x0, dynamic, T, "CastParam", """line 208, colu mn 46 of dart:async/future_impl.dart: """, x0 is T, false)); 105 dynamic c(dynamic x0) => f(x0);
106 return f == null ? null : c; 106 return f == null ? null : c;
107 } 107 }
108 , f, DEVC$RT.type((__t28<T> _) { 108 , __x22, __t14, DEVC$RT.type((__t20<T> _) {
109 } 109 }
110 ), __t22, "Wrap", """line 208, column 46 of dart:async/future_impl.dart: """, f is __t22)); 110 ), "Wrap", """line 208, column 11 of dart:async/future_impl.dart: """, __x22 is __t20<T>))(result._zone.registerUnaryCallback(f));
111 if (onError != null) { 111 if (onError != null) {
112 onError = _registerErrorHandler(onError, result._zone); 112 onError = _registerErrorHandler(onError, result._zone);
113 } 113 }
114 } 114 }
115 _addListener(new _FutureListener.then(result, DEVC$RT.wrap((dynamic f(T __u30)) { 115 _addListener(new _FutureListener.then(result, f, onError));
116 dynamic c(T x0) => f(DEVC$RT.cast(x0, dynamic, T, "CastParam", """line 213, colu mn 51 of dart:async/future_impl.dart: """, x0 is T, false));
117 return f == null ? null : c;
118 }
119 , f, DEVC$RT.type((__t28<T> _) {
120 }
121 ), __t22, "Wrap", """line 213, column 51 of dart:async/future_impl.dart: """, f is __t22), onError));
122 return result; 116 return result;
123 } 117 }
124 Future catchError(Function onError, { 118 Future catchError(Function onError, {
125 bool test(error)} 119 bool test(error)}
126 ) { 120 ) {
127 _Future result = new _Future(); 121 _Future result = new _Future();
128 if (!identical(result._zone, _ROOT_ZONE)) { 122 if (!identical(result._zone, _ROOT_ZONE)) {
129 onError = _registerErrorHandler(onError, result._zone); 123 onError = _registerErrorHandler(onError, result._zone);
130 if (test != null) test = ((__x33) => DEVC$RT.wrap((dynamic f(dynamic __u32)) { 124 if (test != null) test = ((__x25) => DEVC$RT.wrap((dynamic f(dynamic __u24)) {
131 dynamic c(dynamic x0) => ((__x31) => DEVC$RT.cast(__x31, dynamic, bool, "CastRes ult", """line 221, column 32 of dart:async/future_impl.dart: """, __x31 is bool, true))(f(x0)); 125 dynamic c(dynamic x0) => ((__x23) => DEVC$RT.cast(__x23, dynamic, bool, "CastRes ult", """line 221, column 32 of dart:async/future_impl.dart: """, __x23 is bool, true))(f(x0));
132 return f == null ? null : c; 126 return f == null ? null : c;
133 } 127 }
134 , __x33, __t22, __t24, "Wrap", """line 221, column 32 of dart:async/future_impl. dart: """, __x33 is __t24))(result._zone.registerUnaryCallback(test)); 128 , __x25, __t14, __t16, "Wrap", """line 221, column 32 of dart:async/future_impl. dart: """, __x25 is __t16))(result._zone.registerUnaryCallback(test));
135 } 129 }
136 _addListener(new _FutureListener.catchError(result, onError, test)); 130 _addListener(new _FutureListener.catchError(result, onError, test));
137 return result; 131 return result;
138 } 132 }
139 Future<T> whenComplete(action()) { 133 Future<T> whenComplete(action()) {
140 _Future result = new _Future<T>(); 134 _Future result = new _Future<T>();
141 if (!identical(result._zone, _ROOT_ZONE)) { 135 if (!identical(result._zone, _ROOT_ZONE)) {
142 action = result._zone.registerCallback(action); 136 action = result._zone.registerCallback(action);
143 } 137 }
144 _addListener(new _FutureListener.whenComplete(result, action)); 138 _addListener(new _FutureListener.whenComplete(result, action));
145 return DEVC$RT.cast(result, DEVC$RT.type((_Future<dynamic> _) { 139 return DEVC$RT.cast(result, DEVC$RT.type((_Future<dynamic> _) {
146 } 140 }
147 ), DEVC$RT.type((Future<T> _) { 141 ), DEVC$RT.type((Future<T> _) {
148 } 142 }
149 ), "CastDynamic", """line 233, column 12 of dart:async/future_impl.dart: """, re sult is Future<T>, false); 143 ), "CastDynamic", """line 233, column 12 of dart:async/future_impl.dart: """, re sult is Future<T>, false);
150 } 144 }
151 Stream<T> asStream() => ((__x34) => DEVC$RT.cast(__x34, DEVC$RT.type((Stream<dy namic> _) { 145 Stream<T> asStream() => ((__x26) => DEVC$RT.cast(__x26, DEVC$RT.type((Stream<dy namic> _) {
152 } 146 }
153 ), DEVC$RT.type((Stream<T> _) { 147 ), DEVC$RT.type((Stream<T> _) {
154 } 148 }
155 ), "CastExact", """line 236, column 27 of dart:async/future_impl.dart: """, __x3 4 is Stream<T>, false))(new Stream.fromFuture(this)); 149 ), "CastExact", """line 236, column 27 of dart:async/future_impl.dart: """, __x2 6 is Stream<T>, false))(new Stream.fromFuture(this));
156 void _markPendingCompletion() { 150 void _markPendingCompletion() {
157 if (!_mayComplete) throw new StateError("Future already completed"); 151 if (!_mayComplete) throw new StateError("Future already completed");
158 _state = _PENDING_COMPLETE; 152 _state = _PENDING_COMPLETE;
159 } 153 }
160 T get _value { 154 T get _value {
161 assert (_isComplete && _hasValue); return DEVC$RT.cast(_resultOrListeners, dynam ic, T, "CastGeneral", """line 245, column 12 of dart:async/future_impl.dart: """ , _resultOrListeners is T, false); 155 assert (_isComplete && _hasValue); return DEVC$RT.cast(_resultOrListeners, dynam ic, T, "CastGeneral", """line 245, column 12 of dart:async/future_impl.dart: """ , _resultOrListeners is T, false);
162 } 156 }
163 AsyncError get _error { 157 AsyncError get _error {
164 assert (_isComplete && _hasError); return DEVC$RT.cast(_resultOrListeners, dynam ic, AsyncError, "CastGeneral", """line 250, column 12 of dart:async/future_impl. dart: """, _resultOrListeners is AsyncError, true); 158 assert (_isComplete && _hasError); return DEVC$RT.cast(_resultOrListeners, dynam ic, AsyncError, "CastGeneral", """line 250, column 12 of dart:async/future_impl. dart: """, _resultOrListeners is AsyncError, true);
165 } 159 }
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 listenerValueOrError = new AsyncError(e, s); 324 listenerValueOrError = new AsyncError(e, s);
331 return false; 325 return false;
332 } 326 }
333 } 327 }
334 void handleError() { 328 void handleError() {
335 AsyncError asyncError = source._error; 329 AsyncError asyncError = source._error;
336 bool matchesTest = true; 330 bool matchesTest = true;
337 if (listener.hasErrorTest) { 331 if (listener.hasErrorTest) {
338 _FutureErrorTest test = listener._errorTest; 332 _FutureErrorTest test = listener._errorTest;
339 try { 333 try {
340 matchesTest = ((__x35) => DEVC$RT.cast(__x35, dynamic, bool, "CastGeneral", """line 499, column 29 of dart:async/future_impl.dart: """, __x35 is bool, true) )(zone.runUnary(test, asyncError.error)); 334 matchesTest = ((__x27) => DEVC$RT.cast(__x27, dynamic, bool, "CastGeneral", """line 499, column 29 of dart:async/future_impl.dart: """, __x27 is bool, true) )(zone.runUnary(test, asyncError.error));
341 } 335 }
342 catch (e, s) { 336 catch (e, s) {
343 listenerValueOrError = identical(asyncError.error, e) ? asyncError : new Asy ncError(e, s); 337 listenerValueOrError = identical(asyncError.error, e) ? asyncError : new Asy ncError(e, s);
344 listenerHasValue = false; 338 listenerHasValue = false;
345 return;} 339 return;}
346 } 340 }
347 Function errorCallback = listener._onError; 341 Function errorCallback = listener._onError;
348 if (matchesTest && errorCallback != null) { 342 if (matchesTest && errorCallback != null) {
349 try { 343 try {
350 if (errorCallback is ZoneBinaryCallback) { 344 if (errorCallback is ZoneBinaryCallback) {
351 listenerValueOrError = zone.runBinary(errorCallback, asyncError.error, asy ncError.stackTrace); 345 listenerValueOrError = zone.runBinary(errorCallback, asyncError.error, asy ncError.stackTrace);
352 } 346 }
353 else { 347 else {
354 listenerValueOrError = zone.runUnary(DEVC$RT.cast(errorCallback, Function, __t22, "CastGeneral", """line 515, column 54 of dart:async/future_impl.dart: "" ", errorCallback is __t22, false), asyncError.error); 348 listenerValueOrError = zone.runUnary(DEVC$RT.cast(errorCallback, Function, __t14, "CastGeneral", """line 515, column 54 of dart:async/future_impl.dart: "" ", errorCallback is __t14, false), asyncError.error);
355 } 349 }
356 } 350 }
357 catch (e, s) { 351 catch (e, s) {
358 listenerValueOrError = identical(asyncError.error, e) ? asyncError : new Asy ncError(e, s); 352 listenerValueOrError = identical(asyncError.error, e) ? asyncError : new Asy ncError(e, s);
359 listenerHasValue = false; 353 listenerHasValue = false;
360 return;} 354 return;}
361 listenerHasValue = true; 355 listenerHasValue = true;
362 } 356 }
363 else { 357 else {
364 listenerValueOrError = asyncError; 358 listenerValueOrError = asyncError;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 , onError: (e, s) { 471 , onError: (e, s) {
478 if (timer.isActive) { 472 if (timer.isActive) {
479 timer.cancel(); 473 timer.cancel();
480 result._completeError(e, DEVC$RT.cast(s, dynamic, StackTrace, "CastGeneral", "" "line 646, column 34 of dart:async/future_impl.dart: """, s is StackTrace, true) ); 474 result._completeError(e, DEVC$RT.cast(s, dynamic, StackTrace, "CastGeneral", "" "line 646, column 34 of dart:async/future_impl.dart: """, s is StackTrace, true) );
481 } 475 }
482 } 476 }
483 ); 477 );
484 return result; 478 return result;
485 } 479 }
486 } 480 }
487 typedef dynamic __t22(dynamic __u23); 481 typedef dynamic __t14(dynamic __u15);
488 typedef bool __t24(dynamic __u25); 482 typedef bool __t16(dynamic __u17);
489 typedef dynamic __t26(); 483 typedef dynamic __t18();
490 typedef dynamic __t28<T>(T __u29); 484 typedef dynamic __t20<T>(T __u21);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698