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

Side by Side Diff: lib/runtime/dart/async.js

Issue 1207313002: initial sync*, part of #221 (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 6 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 dart_library.library('dart/async', null, /* Imports */[ 1 dart_library.library('dart/async', null, /* Imports */[
2 "dart_runtime/dart", 2 "dart_runtime/dart",
3 'dart/core', 3 'dart/core',
4 'dart/_internal', 4 'dart/_internal',
5 'dart/collection' 5 'dart/collection'
6 ], /* Lazy imports */[ 6 ], /* Lazy imports */[
7 'dart/_isolate_helper', 7 'dart/_isolate_helper',
8 'dart/_js_helper' 8 'dart/_js_helper'
9 ], function(exports, dart, core, _internal, collection, _isolate_helper, _js_hel per) { 9 ], function(exports, dart, core, _internal, collection, _isolate_helper, _js_hel per) {
10 'use strict'; 10 'use strict';
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 } 90 }
91 static periodic(period, computation) { 91 static periodic(period, computation) {
92 if (computation === void 0) 92 if (computation === void 0)
93 computation = null; 93 computation = null;
94 if (computation == null) 94 if (computation == null)
95 computation = dart.fn(i => null, dart.bottom, [dart.dynamic]); 95 computation = dart.fn(i => null, dart.bottom, [dart.dynamic]);
96 let timer = null; 96 let timer = null;
97 let computationCount = 0; 97 let computationCount = 0;
98 let controller = null; 98 let controller = null;
99 let watch = new core.Stopwatch(); 99 let watch = new core.Stopwatch();
100 let sendEvent = () => { 100 function sendEvent() {
101 watch.reset(); 101 watch.reset();
102 let data = computation((() => { 102 let data = computation((() => {
103 let x = computationCount; 103 let x = computationCount;
104 computationCount = dart.notNull(x) + 1; 104 computationCount = dart.notNull(x) + 1;
105 return x; 105 return x;
106 })()); 106 })());
107 controller.add(data); 107 controller.add(data);
108 }; 108 }
109 dart.fn(sendEvent, dart.void, []); 109 dart.fn(sendEvent, dart.void, []);
110 let startPeriodicTimer = () => { 110 function startPeriodicTimer() {
111 dart.assert(timer == null); 111 dart.assert(timer == null);
112 timer = Timer.periodic(period, dart.fn(timer => { 112 timer = Timer.periodic(period, dart.fn(timer => {
113 sendEvent(); 113 sendEvent();
114 }, dart.dynamic, [Timer])); 114 }, dart.dynamic, [Timer]));
115 }; 115 }
116 dart.fn(startPeriodicTimer, dart.void, []); 116 dart.fn(startPeriodicTimer, dart.void, []);
117 controller = StreamController$(T).new({sync: true, onListen: dart.fn(() => { 117 controller = StreamController$(T).new({sync: true, onListen: dart.fn(() => {
118 watch.start(); 118 watch.start();
119 startPeriodicTimer(); 119 startPeriodicTimer();
120 }), onPause: dart.fn(() => { 120 }), onPause: dart.fn(() => {
121 timer.cancel(); 121 timer.cancel();
122 timer = null; 122 timer = null;
123 watch.stop(); 123 watch.stop();
124 }), onResume: dart.fn(() => { 124 }), onResume: dart.fn(() => {
125 dart.assert(timer == null); 125 dart.assert(timer == null);
(...skipping 29 matching lines...) Expand all
155 return new (_WhereStream$(T))(this, test); 155 return new (_WhereStream$(T))(this, test);
156 } 156 }
157 map(convert) { 157 map(convert) {
158 dart.as(convert, dart.functionType(dart.dynamic, [T])); 158 dart.as(convert, dart.functionType(dart.dynamic, [T]));
159 return new (_MapStream$(T, dart.dynamic))(this, convert); 159 return new (_MapStream$(T, dart.dynamic))(this, convert);
160 } 160 }
161 asyncMap(convert) { 161 asyncMap(convert) {
162 dart.as(convert, dart.functionType(dart.dynamic, [T])); 162 dart.as(convert, dart.functionType(dart.dynamic, [T]));
163 let controller = null; 163 let controller = null;
164 let subscription = null; 164 let subscription = null;
165 let onListen = () => { 165 let onListen = (function() {
166 let add = dart.bind(controller, 'add'); 166 let add = dart.bind(controller, 'add');
167 dart.assert(dart.is(controller, _StreamController) || dart.is(controll er, _BroadcastStreamController)); 167 dart.assert(dart.is(controller, _StreamController) || dart.is(controll er, _BroadcastStreamController));
168 let eventSink = controller; 168 let eventSink = controller;
169 let addError = eventSink[_addError]; 169 let addError = eventSink[_addError];
170 subscription = this.listen(dart.fn(event => { 170 subscription = this.listen(dart.fn(event => {
171 dart.as(event, T); 171 dart.as(event, T);
172 let newValue = null; 172 let newValue = null;
173 try { 173 try {
174 newValue = convert(event); 174 newValue = convert(event);
175 } catch (e) { 175 } catch (e) {
176 let s = dart.stackTrace(e); 176 let s = dart.stackTrace(e);
177 controller.addError(e, s); 177 controller.addError(e, s);
178 return; 178 return;
179 } 179 }
180 180
181 if (dart.is(newValue, Future)) { 181 if (dart.is(newValue, Future)) {
182 subscription.pause(); 182 subscription.pause();
183 dart.dsend(dart.dsend(newValue, 'then', add, {onError: addError}), 'whenComplete', dart.bind(subscription, 'resume')); 183 dart.dsend(dart.dsend(newValue, 'then', add, {onError: addError}), 'whenComplete', dart.bind(subscription, 'resume'));
184 } else { 184 } else {
185 controller.add(newValue); 185 controller.add(newValue);
186 } 186 }
187 }, dart.dynamic, [T]), {onError: dart.as(addError, core.Function), onD one: dart.bind(controller, 'close')}); 187 }, dart.dynamic, [T]), {onError: dart.as(addError, core.Function), onD one: dart.bind(controller, 'close')});
188 }; 188 }).bind(this);
189 dart.fn(onListen, dart.void, []); 189 dart.fn(onListen, dart.void, []);
190 if (dart.notNull(this.isBroadcast)) { 190 if (dart.notNull(this.isBroadcast)) {
191 controller = StreamController.broadcast({onListen: onListen, onCancel: dart.fn(() => { 191 controller = StreamController.broadcast({onListen: onListen, onCancel: dart.fn(() => {
192 subscription.cancel(); 192 subscription.cancel();
193 }), sync: true}); 193 }), sync: true});
194 } else { 194 } else {
195 controller = StreamController.new({onListen: onListen, onPause: dart.f n(() => { 195 controller = StreamController.new({onListen: onListen, onPause: dart.f n(() => {
196 subscription.pause(); 196 subscription.pause();
197 }), onResume: dart.fn(() => { 197 }), onResume: dart.fn(() => {
198 subscription.resume(); 198 subscription.resume();
199 }), onCancel: dart.fn(() => { 199 }), onCancel: dart.fn(() => {
200 subscription.cancel(); 200 subscription.cancel();
201 }), sync: true}); 201 }), sync: true});
202 } 202 }
203 return controller.stream; 203 return controller.stream;
204 } 204 }
205 asyncExpand(convert) { 205 asyncExpand(convert) {
206 dart.as(convert, dart.functionType(Stream$(), [T])); 206 dart.as(convert, dart.functionType(Stream$(), [T]));
207 let controller = null; 207 let controller = null;
208 let subscription = null; 208 let subscription = null;
209 let onListen = () => { 209 let onListen = (function() {
210 dart.assert(dart.is(controller, _StreamController) || dart.is(controll er, _BroadcastStreamController)); 210 dart.assert(dart.is(controller, _StreamController) || dart.is(controll er, _BroadcastStreamController));
211 let eventSink = controller; 211 let eventSink = controller;
212 subscription = this.listen(dart.fn(event => { 212 subscription = this.listen(dart.fn(event => {
213 dart.as(event, T); 213 dart.as(event, T);
214 let newStream = null; 214 let newStream = null;
215 try { 215 try {
216 newStream = convert(event); 216 newStream = convert(event);
217 } catch (e) { 217 } catch (e) {
218 let s = dart.stackTrace(e); 218 let s = dart.stackTrace(e);
219 controller.addError(e, s); 219 controller.addError(e, s);
220 return; 220 return;
221 } 221 }
222 222
223 if (newStream != null) { 223 if (newStream != null) {
224 subscription.pause(); 224 subscription.pause();
225 controller.addStream(newStream).whenComplete(dart.bind(subscriptio n, 'resume')); 225 controller.addStream(newStream).whenComplete(dart.bind(subscriptio n, 'resume'));
226 } 226 }
227 }, dart.dynamic, [T]), {onError: dart.as(eventSink[_addError], core.Fu nction), onDone: dart.bind(controller, 'close')}); 227 }, dart.dynamic, [T]), {onError: dart.as(eventSink[_addError], core.Fu nction), onDone: dart.bind(controller, 'close')});
228 }; 228 }).bind(this);
229 dart.fn(onListen, dart.void, []); 229 dart.fn(onListen, dart.void, []);
230 if (dart.notNull(this.isBroadcast)) { 230 if (dart.notNull(this.isBroadcast)) {
231 controller = StreamController.broadcast({onListen: onListen, onCancel: dart.fn(() => { 231 controller = StreamController.broadcast({onListen: onListen, onCancel: dart.fn(() => {
232 subscription.cancel(); 232 subscription.cancel();
233 }), sync: true}); 233 }), sync: true});
234 } else { 234 } else {
235 controller = StreamController.new({onListen: onListen, onPause: dart.f n(() => { 235 controller = StreamController.new({onListen: onListen, onPause: dart.f n(() => {
236 subscription.pause(); 236 subscription.pause();
237 }), onResume: dart.fn(() => { 237 }), onResume: dart.fn(() => {
238 subscription.resume(); 238 subscription.resume();
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 return future; 658 return future;
659 } 659 }
660 timeout(timeLimit, opts) { 660 timeout(timeLimit, opts) {
661 let onTimeout = opts && 'onTimeout' in opts ? opts.onTimeout : null; 661 let onTimeout = opts && 'onTimeout' in opts ? opts.onTimeout : null;
662 dart.as(onTimeout, dart.functionType(dart.void, [EventSink])); 662 dart.as(onTimeout, dart.functionType(dart.void, [EventSink]));
663 let controller = null; 663 let controller = null;
664 let subscription = null; 664 let subscription = null;
665 let timer = null; 665 let timer = null;
666 let zone = null; 666 let zone = null;
667 let timeout = null; 667 let timeout = null;
668 let onData = event => { 668 function onData(event) {
669 dart.as(event, T); 669 dart.as(event, T);
670 timer.cancel(); 670 timer.cancel();
671 controller.add(event); 671 controller.add(event);
672 timer = zone.createTimer(timeLimit, dart.as(timeout, __CastType17)); 672 timer = zone.createTimer(timeLimit, dart.as(timeout, __CastType17));
673 }; 673 }
674 dart.fn(onData, dart.void, [T]); 674 dart.fn(onData, dart.void, [T]);
675 let onError = (error, stackTrace) => { 675 function onError(error, stackTrace) {
676 timer.cancel(); 676 timer.cancel();
677 dart.assert(dart.is(controller, _StreamController) || dart.is(controll er, _BroadcastStreamController)); 677 dart.assert(dart.is(controller, _StreamController) || dart.is(controll er, _BroadcastStreamController));
678 let eventSink = controller; 678 let eventSink = controller;
679 dart.dcall(eventSink[_addError], error, stackTrace); 679 dart.dcall(eventSink[_addError], error, stackTrace);
680 timer = zone.createTimer(timeLimit, dart.as(timeout, dart.functionType (dart.void, []))); 680 timer = zone.createTimer(timeLimit, dart.as(timeout, dart.functionType (dart.void, [])));
681 }; 681 }
682 dart.fn(onError, dart.void, [dart.dynamic, core.StackTrace]); 682 dart.fn(onError, dart.void, [dart.dynamic, core.StackTrace]);
683 let onDone = () => { 683 function onDone() {
684 timer.cancel(); 684 timer.cancel();
685 controller.close(); 685 controller.close();
686 }; 686 }
687 dart.fn(onDone, dart.void, []); 687 dart.fn(onDone, dart.void, []);
688 let onListen = () => { 688 let onListen = (function() {
689 zone = Zone.current; 689 zone = Zone.current;
690 if (onTimeout == null) { 690 if (onTimeout == null) {
691 timeout = dart.fn(() => { 691 timeout = dart.fn(() => {
692 controller.addError(new TimeoutException("No stream event", timeLi mit), null); 692 controller.addError(new TimeoutException("No stream event", timeLi mit), null);
693 }); 693 });
694 } else { 694 } else {
695 onTimeout = dart.as(zone.registerUnaryCallback(onTimeout), __CastTyp e18); 695 onTimeout = dart.as(zone.registerUnaryCallback(onTimeout), __CastTyp e18);
696 let wrapper = new _ControllerEventSinkWrapper(null); 696 let wrapper = new _ControllerEventSinkWrapper(null);
697 timeout = dart.fn(() => { 697 timeout = dart.fn(() => {
698 wrapper[_sink] = controller; 698 wrapper[_sink] = controller;
699 zone.runUnaryGuarded(onTimeout, wrapper); 699 zone.runUnaryGuarded(onTimeout, wrapper);
700 wrapper[_sink] = null; 700 wrapper[_sink] = null;
701 }); 701 });
702 } 702 }
703 subscription = this.listen(onData, {onError: onError, onDone: onDone}) ; 703 subscription = this.listen(onData, {onError: onError, onDone: onDone}) ;
704 timer = zone.createTimer(timeLimit, dart.as(timeout, dart.functionType (dart.void, []))); 704 timer = zone.createTimer(timeLimit, dart.as(timeout, dart.functionType (dart.void, [])));
705 }; 705 }).bind(this);
706 dart.fn(onListen, dart.void, []); 706 dart.fn(onListen, dart.void, []);
707 let onCancel = () => { 707 function onCancel() {
708 timer.cancel(); 708 timer.cancel();
709 let result = subscription.cancel(); 709 let result = subscription.cancel();
710 subscription = null; 710 subscription = null;
711 return result; 711 return result;
712 }; 712 }
713 dart.fn(onCancel, Future, []); 713 dart.fn(onCancel, Future, []);
714 controller = dart.notNull(this.isBroadcast) ? new _SyncBroadcastStreamCo ntroller(onListen, onCancel) : new _SyncStreamController(onListen, dart.fn(() => { 714 controller = dart.notNull(this.isBroadcast) ? new _SyncBroadcastStreamCo ntroller(onListen, onCancel) : new _SyncStreamController(onListen, dart.fn(() => {
715 timer.cancel(); 715 timer.cancel();
716 subscription.pause(); 716 subscription.pause();
717 }), dart.fn(() => { 717 }), dart.fn(() => {
718 subscription.resume(); 718 subscription.resume();
719 timer = zone.createTimer(timeLimit, dart.as(timeout, dart.functionType (dart.void, []))); 719 timer = zone.createTimer(timeLimit, dart.as(timeout, dart.functionType (dart.void, [])));
720 }), onCancel); 720 }), onCancel);
721 return controller.stream; 721 return controller.stream;
722 } 722 }
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 this[_state] = dart.notNull(this[_state]) | dart.notNull(_BufferingStrea mSubscription$()._STATE_IN_CALLBACK); 1098 this[_state] = dart.notNull(this[_state]) | dart.notNull(_BufferingStrea mSubscription$()._STATE_IN_CALLBACK);
1099 this[_zone].runUnaryGuarded(this[_onData], data); 1099 this[_zone].runUnaryGuarded(this[_onData], data);
1100 this[_state] = dart.notNull(this[_state]) & ~dart.notNull(_BufferingStre amSubscription$()._STATE_IN_CALLBACK); 1100 this[_state] = dart.notNull(this[_state]) & ~dart.notNull(_BufferingStre amSubscription$()._STATE_IN_CALLBACK);
1101 this[_checkState](wasInputPaused); 1101 this[_checkState](wasInputPaused);
1102 } 1102 }
1103 [_sendError](error, stackTrace) { 1103 [_sendError](error, stackTrace) {
1104 dart.assert(!dart.notNull(this[_isCanceled])); 1104 dart.assert(!dart.notNull(this[_isCanceled]));
1105 dart.assert(!dart.notNull(this[_isPaused])); 1105 dart.assert(!dart.notNull(this[_isPaused]));
1106 dart.assert(!dart.notNull(this[_inCallback])); 1106 dart.assert(!dart.notNull(this[_inCallback]));
1107 let wasInputPaused = this[_isInputPaused]; 1107 let wasInputPaused = this[_isInputPaused];
1108 let sendError = () => { 1108 let sendError = (function() {
1109 if (dart.notNull(this[_isCanceled]) && !dart.notNull(this[_waitsForCan cel])) 1109 if (dart.notNull(this[_isCanceled]) && !dart.notNull(this[_waitsForCan cel]))
1110 return; 1110 return;
1111 this[_state] = dart.notNull(this[_state]) | dart.notNull(_BufferingStr eamSubscription$()._STATE_IN_CALLBACK); 1111 this[_state] = dart.notNull(this[_state]) | dart.notNull(_BufferingStr eamSubscription$()._STATE_IN_CALLBACK);
1112 if (dart.is(this[_onError], ZoneBinaryCallback)) { 1112 if (dart.is(this[_onError], ZoneBinaryCallback)) {
1113 this[_zone].runBinaryGuarded(dart.as(this[_onError], __CastType22), error, stackTrace); 1113 this[_zone].runBinaryGuarded(dart.as(this[_onError], __CastType22), error, stackTrace);
1114 } else { 1114 } else {
1115 this[_zone].runUnaryGuarded(dart.as(this[_onError], __CastType25), e rror); 1115 this[_zone].runUnaryGuarded(dart.as(this[_onError], __CastType25), e rror);
1116 } 1116 }
1117 this[_state] = dart.notNull(this[_state]) & ~dart.notNull(_BufferingSt reamSubscription$()._STATE_IN_CALLBACK); 1117 this[_state] = dart.notNull(this[_state]) & ~dart.notNull(_BufferingSt reamSubscription$()._STATE_IN_CALLBACK);
1118 }; 1118 }).bind(this);
1119 dart.fn(sendError, dart.void, []); 1119 dart.fn(sendError, dart.void, []);
1120 if (dart.notNull(this[_cancelOnError])) { 1120 if (dart.notNull(this[_cancelOnError])) {
1121 this[_state] = dart.notNull(this[_state]) | dart.notNull(_BufferingStr eamSubscription$()._STATE_WAIT_FOR_CANCEL); 1121 this[_state] = dart.notNull(this[_state]) | dart.notNull(_BufferingStr eamSubscription$()._STATE_WAIT_FOR_CANCEL);
1122 this[_cancel](); 1122 this[_cancel]();
1123 if (dart.is(this[_cancelFuture], Future)) { 1123 if (dart.is(this[_cancelFuture], Future)) {
1124 this[_cancelFuture].whenComplete(sendError); 1124 this[_cancelFuture].whenComplete(sendError);
1125 } else { 1125 } else {
1126 sendError(); 1126 sendError();
1127 } 1127 }
1128 } else { 1128 } else {
1129 sendError(); 1129 sendError();
1130 this[_checkState](wasInputPaused); 1130 this[_checkState](wasInputPaused);
1131 } 1131 }
1132 } 1132 }
1133 [_sendDone]() { 1133 [_sendDone]() {
1134 dart.assert(!dart.notNull(this[_isCanceled])); 1134 dart.assert(!dart.notNull(this[_isCanceled]));
1135 dart.assert(!dart.notNull(this[_isPaused])); 1135 dart.assert(!dart.notNull(this[_isPaused]));
1136 dart.assert(!dart.notNull(this[_inCallback])); 1136 dart.assert(!dart.notNull(this[_inCallback]));
1137 let sendDone = () => { 1137 let sendDone = (function() {
1138 if (!dart.notNull(this[_waitsForCancel])) 1138 if (!dart.notNull(this[_waitsForCancel]))
1139 return; 1139 return;
1140 this[_state] = dart.notNull(this[_state]) | dart.notNull(_BufferingStr eamSubscription$()._STATE_CANCELED) | dart.notNull(_BufferingStreamSubscription$ ()._STATE_CLOSED) | dart.notNull(_BufferingStreamSubscription$()._STATE_IN_CALLB ACK); 1140 this[_state] = dart.notNull(this[_state]) | dart.notNull(_BufferingStr eamSubscription$()._STATE_CANCELED) | dart.notNull(_BufferingStreamSubscription$ ()._STATE_CLOSED) | dart.notNull(_BufferingStreamSubscription$()._STATE_IN_CALLB ACK);
1141 this[_zone].runGuarded(this[_onDone]); 1141 this[_zone].runGuarded(this[_onDone]);
1142 this[_state] = dart.notNull(this[_state]) & ~dart.notNull(_BufferingSt reamSubscription$()._STATE_IN_CALLBACK); 1142 this[_state] = dart.notNull(this[_state]) & ~dart.notNull(_BufferingSt reamSubscription$()._STATE_IN_CALLBACK);
1143 }; 1143 }).bind(this);
1144 dart.fn(sendDone, dart.void, []); 1144 dart.fn(sendDone, dart.void, []);
1145 this[_cancel](); 1145 this[_cancel]();
1146 this[_state] = dart.notNull(this[_state]) | dart.notNull(_BufferingStrea mSubscription$()._STATE_WAIT_FOR_CANCEL); 1146 this[_state] = dart.notNull(this[_state]) | dart.notNull(_BufferingStrea mSubscription$()._STATE_WAIT_FOR_CANCEL);
1147 if (dart.is(this[_cancelFuture], Future)) { 1147 if (dart.is(this[_cancelFuture], Future)) {
1148 this[_cancelFuture].whenComplete(sendDone); 1148 this[_cancelFuture].whenComplete(sendDone);
1149 } else { 1149 } else {
1150 sendDone(); 1150 sendDone();
1151 } 1151 }
1152 } 1152 }
1153 [_guardCallback](callback) { 1153 [_guardCallback](callback) {
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after
1881 } 1881 }
1882 static wait(futures, opts) { 1882 static wait(futures, opts) {
1883 let eagerError = opts && 'eagerError' in opts ? opts.eagerError : false; 1883 let eagerError = opts && 'eagerError' in opts ? opts.eagerError : false;
1884 let cleanUp = opts && 'cleanUp' in opts ? opts.cleanUp : null; 1884 let cleanUp = opts && 'cleanUp' in opts ? opts.cleanUp : null;
1885 dart.as(cleanUp, dart.functionType(dart.void, [dart.dynamic])); 1885 dart.as(cleanUp, dart.functionType(dart.void, [dart.dynamic]));
1886 let result = new (_Future$(core.List))(); 1886 let result = new (_Future$(core.List))();
1887 let values = null; 1887 let values = null;
1888 let remaining = 0; 1888 let remaining = 0;
1889 let error = null; 1889 let error = null;
1890 let stackTrace = null; 1890 let stackTrace = null;
1891 let handleError = (theError, theStackTrace) => { 1891 function handleError(theError, theStackTrace) {
1892 remaining = dart.notNull(remaining) - 1; 1892 remaining = dart.notNull(remaining) - 1;
1893 if (values != null) { 1893 if (values != null) {
1894 if (cleanUp != null) { 1894 if (cleanUp != null) {
1895 for (let value of values) { 1895 for (let value of values) {
1896 if (value != null) { 1896 if (value != null) {
1897 Future$().sync(dart.fn(() => { 1897 Future$().sync(dart.fn(() => {
1898 dart.dcall(cleanUp, value); 1898 dart.dcall(cleanUp, value);
1899 })); 1899 }));
1900 } 1900 }
1901 } 1901 }
1902 } 1902 }
1903 values = null; 1903 values = null;
1904 if (remaining == 0 || dart.notNull(eagerError)) { 1904 if (remaining == 0 || dart.notNull(eagerError)) {
1905 result[_completeError](theError, dart.as(theStackTrace, core.Stack Trace)); 1905 result[_completeError](theError, dart.as(theStackTrace, core.Stack Trace));
1906 } else { 1906 } else {
1907 error = theError; 1907 error = theError;
1908 stackTrace = dart.as(theStackTrace, core.StackTrace); 1908 stackTrace = dart.as(theStackTrace, core.StackTrace);
1909 } 1909 }
1910 } else if (remaining == 0 && !dart.notNull(eagerError)) { 1910 } else if (remaining == 0 && !dart.notNull(eagerError)) {
1911 result[_completeError](error, stackTrace); 1911 result[_completeError](error, stackTrace);
1912 } 1912 }
1913 }; 1913 }
1914 dart.fn(handleError, dart.void, [dart.dynamic, dart.dynamic]); 1914 dart.fn(handleError, dart.void, [dart.dynamic, dart.dynamic]);
1915 for (let future of futures) { 1915 for (let future of futures) {
1916 let pos = remaining; 1916 let pos = remaining;
1917 remaining = dart.notNull(pos) + 1; 1917 remaining = dart.notNull(pos) + 1;
1918 future.then(dart.fn(value => { 1918 future.then(dart.fn(value => {
1919 remaining = dart.notNull(remaining) - 1; 1919 remaining = dart.notNull(remaining) - 1;
1920 if (values != null) { 1920 if (values != null) {
1921 values[dartx.set](pos, value); 1921 values[dartx.set](pos, value);
1922 if (remaining == 0) { 1922 if (remaining == 0) {
1923 result[_completeWithValue](values); 1923 result[_completeWithValue](values);
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
2472 let zone = listener[_zone]; 2472 let zone = listener[_zone];
2473 if (dart.notNull(hasError) && !dart.notNull(source[_zone].inSameErro rZone(zone))) { 2473 if (dart.notNull(hasError) && !dart.notNull(source[_zone].inSameErro rZone(zone))) {
2474 let asyncError = source[_error]; 2474 let asyncError = source[_error];
2475 source[_zone].handleUncaughtError(asyncError.error, asyncError.sta ckTrace); 2475 source[_zone].handleUncaughtError(asyncError.error, asyncError.sta ckTrace);
2476 return; 2476 return;
2477 } 2477 }
2478 let oldZone = null; 2478 let oldZone = null;
2479 if (!dart.notNull(core.identical(Zone.current, zone))) { 2479 if (!dart.notNull(core.identical(Zone.current, zone))) {
2480 oldZone = Zone._enter(zone); 2480 oldZone = Zone._enter(zone);
2481 } 2481 }
2482 let handleValueCallback = () => { 2482 function handleValueCallback() {
2483 try { 2483 try {
2484 listenerValueOrError = zone.runUnary(listener[_onValue], sourceV alue); 2484 listenerValueOrError = zone.runUnary(listener[_onValue], sourceV alue);
2485 return true; 2485 return true;
2486 } catch (e) { 2486 } catch (e) {
2487 let s = dart.stackTrace(e); 2487 let s = dart.stackTrace(e);
2488 listenerValueOrError = new AsyncError(e, s); 2488 listenerValueOrError = new AsyncError(e, s);
2489 return false; 2489 return false;
2490 } 2490 }
2491 2491
2492 }; 2492 }
2493 dart.fn(handleValueCallback, core.bool, []); 2493 dart.fn(handleValueCallback, core.bool, []);
2494 let handleError = () => { 2494 function handleError() {
2495 let asyncError = source[_error]; 2495 let asyncError = source[_error];
2496 let matchesTest = true; 2496 let matchesTest = true;
2497 if (dart.notNull(listener.hasErrorTest)) { 2497 if (dart.notNull(listener.hasErrorTest)) {
2498 let test = listener[_errorTest]; 2498 let test = listener[_errorTest];
2499 try { 2499 try {
2500 matchesTest = dart.as(zone.runUnary(test, asyncError.error), c ore.bool); 2500 matchesTest = dart.as(zone.runUnary(test, asyncError.error), c ore.bool);
2501 } catch (e) { 2501 } catch (e) {
2502 let s = dart.stackTrace(e); 2502 let s = dart.stackTrace(e);
2503 listenerValueOrError = dart.notNull(core.identical(asyncError. error, e)) ? asyncError : new AsyncError(e, s); 2503 listenerValueOrError = dart.notNull(core.identical(asyncError. error, e)) ? asyncError : new AsyncError(e, s);
2504 listenerHasValue = false; 2504 listenerHasValue = false;
(...skipping 14 matching lines...) Expand all
2519 listenerValueOrError = dart.notNull(core.identical(asyncError. error, e)) ? asyncError : new AsyncError(e, s); 2519 listenerValueOrError = dart.notNull(core.identical(asyncError. error, e)) ? asyncError : new AsyncError(e, s);
2520 listenerHasValue = false; 2520 listenerHasValue = false;
2521 return; 2521 return;
2522 } 2522 }
2523 2523
2524 listenerHasValue = true; 2524 listenerHasValue = true;
2525 } else { 2525 } else {
2526 listenerValueOrError = asyncError; 2526 listenerValueOrError = asyncError;
2527 listenerHasValue = false; 2527 listenerHasValue = false;
2528 } 2528 }
2529 }; 2529 }
2530 dart.fn(handleError, dart.void, []); 2530 dart.fn(handleError, dart.void, []);
2531 let handleWhenCompleteCallback = () => { 2531 function handleWhenCompleteCallback() {
2532 let completeResult = null; 2532 let completeResult = null;
2533 try { 2533 try {
2534 completeResult = zone.run(listener[_whenCompleteAction]); 2534 completeResult = zone.run(listener[_whenCompleteAction]);
2535 } catch (e) { 2535 } catch (e) {
2536 let s = dart.stackTrace(e); 2536 let s = dart.stackTrace(e);
2537 if (dart.notNull(hasError) && dart.notNull(core.identical(source [_error].error, e))) { 2537 if (dart.notNull(hasError) && dart.notNull(core.identical(source [_error].error, e))) {
2538 listenerValueOrError = source[_error]; 2538 listenerValueOrError = source[_error];
2539 } else { 2539 } else {
2540 listenerValueOrError = new AsyncError(e, s); 2540 listenerValueOrError = new AsyncError(e, s);
2541 } 2541 }
(...skipping 10 matching lines...) Expand all
2552 }), {onError: dart.fn((error, stackTrace) => { 2552 }), {onError: dart.fn((error, stackTrace) => {
2553 if (stackTrace === void 0) 2553 if (stackTrace === void 0)
2554 stackTrace = null; 2554 stackTrace = null;
2555 if (!dart.is(completeResult, _Future$())) { 2555 if (!dart.is(completeResult, _Future$())) {
2556 completeResult = new (_Future$())(); 2556 completeResult = new (_Future$())();
2557 dart.dsend(completeResult, _setError, error, stackTrace); 2557 dart.dsend(completeResult, _setError, error, stackTrace);
2558 } 2558 }
2559 _Future$()._propagateToListeners(dart.as(completeResult, _Fu ture$()), new _FutureListener.chain(result)); 2559 _Future$()._propagateToListeners(dart.as(completeResult, _Fu ture$()), new _FutureListener.chain(result));
2560 }, dart.dynamic, [dart.dynamic], [dart.dynamic])}); 2560 }, dart.dynamic, [dart.dynamic], [dart.dynamic])});
2561 } 2561 }
2562 }; 2562 }
2563 dart.fn(handleWhenCompleteCallback, dart.void, []); 2563 dart.fn(handleWhenCompleteCallback, dart.void, []);
2564 if (!dart.notNull(hasError)) { 2564 if (!dart.notNull(hasError)) {
2565 if (dart.notNull(listener.handlesValue)) { 2565 if (dart.notNull(listener.handlesValue)) {
2566 listenerHasValue = handleValueCallback(); 2566 listenerHasValue = handleValueCallback();
2567 } 2567 }
2568 } else { 2568 } else {
2569 handleError(); 2569 handleError();
2570 } 2570 }
2571 if (dart.notNull(listener.handlesComplete)) { 2571 if (dart.notNull(listener.handlesComplete)) {
2572 handleWhenCompleteCallback(); 2572 handleWhenCompleteCallback();
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
2773 dart.dcall(_AsyncRun.scheduleImmediateClosure, callback); 2773 dart.dcall(_AsyncRun.scheduleImmediateClosure, callback);
2774 } 2774 }
2775 static _initializeScheduleImmediate() { 2775 static _initializeScheduleImmediate() {
2776 if (self.scheduleImmediate != null) { 2776 if (self.scheduleImmediate != null) {
2777 return _AsyncRun._scheduleImmediateJsOverride; 2777 return _AsyncRun._scheduleImmediateJsOverride;
2778 } 2778 }
2779 if (self.MutationObserver != null && self.document != null) { 2779 if (self.MutationObserver != null && self.document != null) {
2780 let div = self.document.createElement("div"); 2780 let div = self.document.createElement("div");
2781 let span = self.document.createElement("span"); 2781 let span = self.document.createElement("span");
2782 let storedCallback = null; 2782 let storedCallback = null;
2783 let internalCallback = _ => { 2783 function internalCallback(_) {
2784 _isolate_helper.leaveJsAsync(); 2784 _isolate_helper.leaveJsAsync();
2785 let f = storedCallback; 2785 let f = storedCallback;
2786 storedCallback = null; 2786 storedCallback = null;
2787 dart.dcall(f); 2787 dart.dcall(f);
2788 }; 2788 }
2789 dart.fn(internalCallback); 2789 dart.fn(internalCallback);
2790 ; 2790 ;
2791 let observer = new self.MutationObserver(_js_helper.convertDartClosureTo JS(internalCallback, 1)); 2791 let observer = new self.MutationObserver(_js_helper.convertDartClosureTo JS(internalCallback, 1));
2792 observer.observe(div, {childList: true}); 2792 observer.observe(div, {childList: true});
2793 return dart.fn(callback => { 2793 return dart.fn(callback => {
2794 dart.assert(storedCallback == null); 2794 dart.assert(storedCallback == null);
2795 _isolate_helper.enterJsAsync(); 2795 _isolate_helper.enterJsAsync();
2796 storedCallback = callback; 2796 storedCallback = callback;
2797 div.firstChild ? div.removeChild(span) : div.appendChild(span); 2797 div.firstChild ? div.removeChild(span) : div.appendChild(span);
2798 }, dart.dynamic, [dart.functionType(dart.void, [])]); 2798 }, dart.dynamic, [dart.functionType(dart.void, [])]);
2799 } else if (self.setImmediate != null) { 2799 } else if (self.setImmediate != null) {
2800 return _AsyncRun._scheduleImmediateWithSetImmediate; 2800 return _AsyncRun._scheduleImmediateWithSetImmediate;
2801 } 2801 }
2802 return _AsyncRun._scheduleImmediateWithTimer; 2802 return _AsyncRun._scheduleImmediateWithTimer;
2803 } 2803 }
2804 static _scheduleImmediateJsOverride(callback) { 2804 static _scheduleImmediateJsOverride(callback) {
2805 let internalCallback = () => { 2805 function internalCallback() {
2806 _isolate_helper.leaveJsAsync(); 2806 _isolate_helper.leaveJsAsync();
2807 callback(); 2807 callback();
2808 }; 2808 }
2809 dart.fn(internalCallback); 2809 dart.fn(internalCallback);
2810 ; 2810 ;
2811 _isolate_helper.enterJsAsync(); 2811 _isolate_helper.enterJsAsync();
2812 self.scheduleImmediate(_js_helper.convertDartClosureToJS(internalCallback, 0)); 2812 self.scheduleImmediate(_js_helper.convertDartClosureToJS(internalCallback, 0));
2813 } 2813 }
2814 static _scheduleImmediateWithSetImmediate(callback) { 2814 static _scheduleImmediateWithSetImmediate(callback) {
2815 let internalCallback = () => { 2815 function internalCallback() {
2816 _isolate_helper.leaveJsAsync(); 2816 _isolate_helper.leaveJsAsync();
2817 callback(); 2817 callback();
2818 }; 2818 }
2819 dart.fn(internalCallback); 2819 dart.fn(internalCallback);
2820 ; 2820 ;
2821 _isolate_helper.enterJsAsync(); 2821 _isolate_helper.enterJsAsync();
2822 self.setImmediate(_js_helper.convertDartClosureToJS(internalCallback, 0)); 2822 self.setImmediate(_js_helper.convertDartClosureToJS(internalCallback, 0));
2823 } 2823 }
2824 static _scheduleImmediateWithTimer(callback) { 2824 static _scheduleImmediateWithTimer(callback) {
2825 Timer._createTimer(core.Duration.ZERO, callback); 2825 Timer._createTimer(core.Duration.ZERO, callback);
2826 } 2826 }
2827 } 2827 }
2828 dart.setSignature(_AsyncRun, { 2828 dart.setSignature(_AsyncRun, {
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
3207 } catch (e) { 3207 } catch (e) {
3208 let s = dart.stackTrace(e); 3208 let s = dart.stackTrace(e);
3209 result = new _Future(); 3209 result = new _Future();
3210 result[_asyncCompleteError](e, s); 3210 result[_asyncCompleteError](e, s);
3211 } 3211 }
3212 3212
3213 } else { 3213 } else {
3214 result = result.whenComplete(this[_onCancel]); 3214 result = result.whenComplete(this[_onCancel]);
3215 } 3215 }
3216 } 3216 }
3217 let complete = () => { 3217 let complete = (function() {
3218 if (this[_doneFuture] != null && dart.notNull(this[_doneFuture][_mayCo mplete])) { 3218 if (this[_doneFuture] != null && dart.notNull(this[_doneFuture][_mayCo mplete])) {
3219 this[_doneFuture][_asyncComplete](null); 3219 this[_doneFuture][_asyncComplete](null);
3220 } 3220 }
3221 }; 3221 }).bind(this);
3222 dart.fn(complete, dart.void, []); 3222 dart.fn(complete, dart.void, []);
3223 if (result != null) { 3223 if (result != null) {
3224 result = result.whenComplete(complete); 3224 result = result.whenComplete(complete);
3225 } else { 3225 } else {
3226 complete(); 3226 complete();
3227 } 3227 }
3228 return result; 3228 return result;
3229 } 3229 }
3230 [_recordPause](subscription) { 3230 [_recordPause](subscription) {
3231 dart.as(subscription, StreamSubscription$(T)); 3231 dart.as(subscription, StreamSubscription$(T));
(...skipping 2680 matching lines...) Expand 10 before | Expand all | Expand 10 after
5912 exports.ScheduleMicrotaskHandler = ScheduleMicrotaskHandler; 5912 exports.ScheduleMicrotaskHandler = ScheduleMicrotaskHandler;
5913 exports.CreateTimerHandler = CreateTimerHandler; 5913 exports.CreateTimerHandler = CreateTimerHandler;
5914 exports.CreatePeriodicTimerHandler = CreatePeriodicTimerHandler; 5914 exports.CreatePeriodicTimerHandler = CreatePeriodicTimerHandler;
5915 exports.PrintHandler = PrintHandler; 5915 exports.PrintHandler = PrintHandler;
5916 exports.ForkHandler = ForkHandler; 5916 exports.ForkHandler = ForkHandler;
5917 exports.ZoneSpecification = ZoneSpecification; 5917 exports.ZoneSpecification = ZoneSpecification;
5918 exports.ZoneDelegate = ZoneDelegate; 5918 exports.ZoneDelegate = ZoneDelegate;
5919 exports.Zone = Zone; 5919 exports.Zone = Zone;
5920 exports.runZoned = runZoned; 5920 exports.runZoned = runZoned;
5921 }); 5921 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698