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

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

Powered by Google App Engine
This is Rietveld 408576698