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

Side by Side Diff: sdk/lib/async/zone.dart

Issue 555153002: Add error-intercept for Completer.completeError and StreamController.addError. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Intercept all errors thrown by unregistered callbacks. Created 6 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « sdk/lib/async/stream_pipe.dart ('k') | tests/lib/async/zone_error_callback_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.async; 5 part of dart.async;
6 6
7 typedef dynamic ZoneCallback(); 7 typedef dynamic ZoneCallback();
8 typedef dynamic ZoneUnaryCallback(arg); 8 typedef dynamic ZoneUnaryCallback(arg);
9 typedef dynamic ZoneBinaryCallback(arg1, arg2); 9 typedef dynamic ZoneBinaryCallback(arg1, arg2);
10 10
11 typedef dynamic HandleUncaughtErrorHandler( 11 typedef dynamic HandleUncaughtErrorHandler(
12 Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace); 12 Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace);
13 typedef dynamic RunHandler(Zone self, ZoneDelegate parent, Zone zone, f()); 13 typedef dynamic RunHandler(Zone self, ZoneDelegate parent, Zone zone, f());
14 typedef dynamic RunUnaryHandler( 14 typedef dynamic RunUnaryHandler(
15 Zone self, ZoneDelegate parent, Zone zone, f(arg), arg); 15 Zone self, ZoneDelegate parent, Zone zone, f(arg), arg);
16 typedef dynamic RunBinaryHandler( 16 typedef dynamic RunBinaryHandler(
17 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2), arg1, arg2); 17 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2), arg1, arg2);
18 typedef ZoneCallback RegisterCallbackHandler( 18 typedef ZoneCallback RegisterCallbackHandler(
19 Zone self, ZoneDelegate parent, Zone zone, f()); 19 Zone self, ZoneDelegate parent, Zone zone, f());
20 typedef ZoneUnaryCallback RegisterUnaryCallbackHandler( 20 typedef ZoneUnaryCallback RegisterUnaryCallbackHandler(
21 Zone self, ZoneDelegate parent, Zone zone, f(arg)); 21 Zone self, ZoneDelegate parent, Zone zone, f(arg));
22 typedef ZoneBinaryCallback RegisterBinaryCallbackHandler( 22 typedef ZoneBinaryCallback RegisterBinaryCallbackHandler(
23 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)); 23 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2));
24 typedef AsyncError ErrorCallbackHandler(Zone self, ZoneDelegate parent,
25 Zone zone, Object error, StackTrace stackTrace);
24 typedef void ScheduleMicrotaskHandler( 26 typedef void ScheduleMicrotaskHandler(
25 Zone self, ZoneDelegate parent, Zone zone, f()); 27 Zone self, ZoneDelegate parent, Zone zone, f());
26 typedef Timer CreateTimerHandler( 28 typedef Timer CreateTimerHandler(
27 Zone self, ZoneDelegate parent, Zone zone, Duration duration, void f()); 29 Zone self, ZoneDelegate parent, Zone zone, Duration duration, void f());
28 typedef Timer CreatePeriodicTimerHandler( 30 typedef Timer CreatePeriodicTimerHandler(
29 Zone self, ZoneDelegate parent, Zone zone, 31 Zone self, ZoneDelegate parent, Zone zone,
30 Duration period, void f(Timer timer)); 32 Duration period, void f(Timer timer));
31 typedef void PrintHandler( 33 typedef void PrintHandler(
32 Zone self, ZoneDelegate parent, Zone zone, String line); 34 Zone self, ZoneDelegate parent, Zone zone, String line);
33 typedef Zone ForkHandler(Zone self, ZoneDelegate parent, Zone zone, 35 typedef Zone ForkHandler(Zone self, ZoneDelegate parent, Zone zone,
34 ZoneSpecification specification, 36 ZoneSpecification specification,
35 Map zoneValues); 37 Map zoneValues);
36 38
39 /// Pair of error and stack trace. Returned by [Zone.errorCallback].
40 class AsyncError implements Error {
41 final error;
42 final StackTrace stackTrace;
43
44 AsyncError(this.error, this.stackTrace);
45 String toString() => error.toString();
46 }
47
48
37 class _ZoneFunction { 49 class _ZoneFunction {
38 final _Zone zone; 50 final _Zone zone;
39 final Function function; 51 final Function function;
40 const _ZoneFunction(this.zone, this.function); 52 const _ZoneFunction(this.zone, this.function);
41 } 53 }
42 54
43 /** 55 /**
44 * This class provides the specification for a forked zone. 56 * This class provides the specification for a forked zone.
45 * 57 *
46 * When forking a new zone (see [Zone.fork]) one can override the default 58 * When forking a new zone (see [Zone.fork]) one can override the default
(...skipping 23 matching lines...) Expand all
70 dynamic runUnary( 82 dynamic runUnary(
71 Zone self, ZoneDelegate parent, Zone zone, f(arg), arg), 83 Zone self, ZoneDelegate parent, Zone zone, f(arg), arg),
72 dynamic runBinary(Zone self, ZoneDelegate parent, Zone zone, 84 dynamic runBinary(Zone self, ZoneDelegate parent, Zone zone,
73 f(arg1, arg2), arg1, arg2), 85 f(arg1, arg2), arg1, arg2),
74 ZoneCallback registerCallback( 86 ZoneCallback registerCallback(
75 Zone self, ZoneDelegate parent, Zone zone, f()), 87 Zone self, ZoneDelegate parent, Zone zone, f()),
76 ZoneUnaryCallback registerUnaryCallback( 88 ZoneUnaryCallback registerUnaryCallback(
77 Zone self, ZoneDelegate parent, Zone zone, f(arg)), 89 Zone self, ZoneDelegate parent, Zone zone, f(arg)),
78 ZoneBinaryCallback registerBinaryCallback( 90 ZoneBinaryCallback registerBinaryCallback(
79 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)), 91 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)),
92 AsyncError errorCallback(Zone self, ZoneDelegate parent, Zone zone,
93 Object error, StackTrace stackTrace),
80 void scheduleMicrotask( 94 void scheduleMicrotask(
81 Zone self, ZoneDelegate parent, Zone zone, f()), 95 Zone self, ZoneDelegate parent, Zone zone, f()),
82 Timer createTimer(Zone self, ZoneDelegate parent, Zone zone, 96 Timer createTimer(Zone self, ZoneDelegate parent, Zone zone,
83 Duration duration, void f()), 97 Duration duration, void f()),
84 Timer createPeriodicTimer(Zone self, ZoneDelegate parent, Zone zone, 98 Timer createPeriodicTimer(Zone self, ZoneDelegate parent, Zone zone,
85 Duration period, void f(Timer timer)), 99 Duration period, void f(Timer timer)),
86 void print(Zone self, ZoneDelegate parent, Zone zone, String line), 100 void print(Zone self, ZoneDelegate parent, Zone zone, String line),
87 Zone fork(Zone self, ZoneDelegate parent, Zone zone, 101 Zone fork(Zone self, ZoneDelegate parent, Zone zone,
88 ZoneSpecification specification, Map zoneValues) 102 ZoneSpecification specification, Map zoneValues)
89 }) = _ZoneSpecification; 103 }) = _ZoneSpecification;
90 104
91 /** 105 /**
92 * Creates a specification from [other] with the provided handlers overriding 106 * Creates a specification from [other] with the provided handlers overriding
93 * the ones in [other]. 107 * the ones in [other].
94 */ 108 */
95 factory ZoneSpecification.from(ZoneSpecification other, { 109 factory ZoneSpecification.from(ZoneSpecification other, {
96 dynamic handleUncaughtError(Zone self, ZoneDelegate parent, Zone zone, 110 dynamic handleUncaughtError(Zone self, ZoneDelegate parent, Zone zone,
97 error, StackTrace stackTrace): null, 111 error, StackTrace stackTrace): null,
98 dynamic run(Zone self, ZoneDelegate parent, Zone zone, f()): null, 112 dynamic run(Zone self, ZoneDelegate parent, Zone zone, f()): null,
99 dynamic runUnary( 113 dynamic runUnary(
100 Zone self, ZoneDelegate parent, Zone zone, f(arg), arg): null, 114 Zone self, ZoneDelegate parent, Zone zone, f(arg), arg): null,
101 dynamic runBinary(Zone self, ZoneDelegate parent, Zone zone, 115 dynamic runBinary(Zone self, ZoneDelegate parent, Zone zone,
102 f(arg1, arg2), arg1, arg2): null, 116 f(arg1, arg2), arg1, arg2): null,
103 ZoneCallback registerCallback( 117 ZoneCallback registerCallback(
104 Zone self, ZoneDelegate parent, Zone zone, f()): null, 118 Zone self, ZoneDelegate parent, Zone zone, f()): null,
105 ZoneUnaryCallback registerUnaryCallback( 119 ZoneUnaryCallback registerUnaryCallback(
106 Zone self, ZoneDelegate parent, Zone zone, f(arg)): null, 120 Zone self, ZoneDelegate parent, Zone zone, f(arg)): null,
107 ZoneBinaryCallback registerBinaryCallback( 121 ZoneBinaryCallback registerBinaryCallback(
108 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)): null, 122 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)): null,
123 AsyncError errorCallback(Zone self, ZoneDelegate parent, Zone zone,
124 Object error, StackTrace stackTrace),
109 void scheduleMicrotask( 125 void scheduleMicrotask(
110 Zone self, ZoneDelegate parent, Zone zone, f()): null, 126 Zone self, ZoneDelegate parent, Zone zone, f()): null,
111 Timer createTimer(Zone self, ZoneDelegate parent, Zone zone, 127 Timer createTimer(Zone self, ZoneDelegate parent, Zone zone,
112 Duration duration, void f()): null, 128 Duration duration, void f()): null,
113 Timer createPeriodicTimer(Zone self, ZoneDelegate parent, Zone zone, 129 Timer createPeriodicTimer(Zone self, ZoneDelegate parent, Zone zone,
114 Duration period, void f(Timer timer)): null, 130 Duration period, void f(Timer timer)): null,
115 void print(Zone self, ZoneDelegate parent, Zone zone, String line): null, 131 void print(Zone self, ZoneDelegate parent, Zone zone, String line): null,
116 Zone fork(Zone self, ZoneDelegate parent, Zone zone, 132 Zone fork(Zone self, ZoneDelegate parent, Zone zone,
117 ZoneSpecification specification, 133 ZoneSpecification specification,
118 Map zoneValues): null 134 Map zoneValues): null
119 }) { 135 }) {
120 return new ZoneSpecification( 136 return new ZoneSpecification(
121 handleUncaughtError: handleUncaughtError != null 137 handleUncaughtError: handleUncaughtError != null
122 ? handleUncaughtError 138 ? handleUncaughtError
123 : other.handleUncaughtError, 139 : other.handleUncaughtError,
124 run: run != null ? run : other.run, 140 run: run != null ? run : other.run,
125 runUnary: runUnary != null ? runUnary : other.runUnary, 141 runUnary: runUnary != null ? runUnary : other.runUnary,
126 runBinary: runBinary != null ? runBinary : other.runBinary, 142 runBinary: runBinary != null ? runBinary : other.runBinary,
127 registerCallback: registerCallback != null 143 registerCallback: registerCallback != null
128 ? registerCallback 144 ? registerCallback
129 : other.registerCallback, 145 : other.registerCallback,
130 registerUnaryCallback: registerUnaryCallback != null 146 registerUnaryCallback: registerUnaryCallback != null
131 ? registerUnaryCallback 147 ? registerUnaryCallback
132 : other.registerUnaryCallback, 148 : other.registerUnaryCallback,
133 registerBinaryCallback: registerBinaryCallback != null 149 registerBinaryCallback: registerBinaryCallback != null
134 ? registerBinaryCallback 150 ? registerBinaryCallback
135 : other.registerBinaryCallback, 151 : other.registerBinaryCallback,
152 errorCallback: errorCallback != null
153 ? errorCallback
154 : other.errorCallback,
136 scheduleMicrotask: scheduleMicrotask != null 155 scheduleMicrotask: scheduleMicrotask != null
137 ? scheduleMicrotask 156 ? scheduleMicrotask
138 : other.scheduleMicrotask, 157 : other.scheduleMicrotask,
139 createTimer : createTimer != null ? createTimer : other.createTimer, 158 createTimer : createTimer != null ? createTimer : other.createTimer,
140 createPeriodicTimer: createPeriodicTimer != null 159 createPeriodicTimer: createPeriodicTimer != null
141 ? createPeriodicTimer 160 ? createPeriodicTimer
142 : other.createPeriodicTimer, 161 : other.createPeriodicTimer,
143 print : print != null ? print : other.print, 162 print : print != null ? print : other.print,
144 fork: fork != null ? fork : other.fork); 163 fork: fork != null ? fork : other.fork);
145 } 164 }
146 165
147 HandleUncaughtErrorHandler get handleUncaughtError; 166 HandleUncaughtErrorHandler get handleUncaughtError;
148 RunHandler get run; 167 RunHandler get run;
149 RunUnaryHandler get runUnary; 168 RunUnaryHandler get runUnary;
150 RunBinaryHandler get runBinary; 169 RunBinaryHandler get runBinary;
151 RegisterCallbackHandler get registerCallback; 170 RegisterCallbackHandler get registerCallback;
152 RegisterUnaryCallbackHandler get registerUnaryCallback; 171 RegisterUnaryCallbackHandler get registerUnaryCallback;
153 RegisterBinaryCallbackHandler get registerBinaryCallback; 172 RegisterBinaryCallbackHandler get registerBinaryCallback;
173 ErrorCallbackHandler get errorCallback;
154 ScheduleMicrotaskHandler get scheduleMicrotask; 174 ScheduleMicrotaskHandler get scheduleMicrotask;
155 CreateTimerHandler get createTimer; 175 CreateTimerHandler get createTimer;
156 CreatePeriodicTimerHandler get createPeriodicTimer; 176 CreatePeriodicTimerHandler get createPeriodicTimer;
157 PrintHandler get print; 177 PrintHandler get print;
158 ForkHandler get fork; 178 ForkHandler get fork;
159 } 179 }
160 180
161 /** 181 /**
162 * Internal [ZoneSpecification] class. 182 * Internal [ZoneSpecification] class.
163 * 183 *
164 * The implementation wants to rely on the fact that the getters cannot change 184 * The implementation wants to rely on the fact that the getters cannot change
165 * dynamically. We thus require users to go through the redirecting 185 * dynamically. We thus require users to go through the redirecting
166 * [ZoneSpecification] constructor which instantiates this class. 186 * [ZoneSpecification] constructor which instantiates this class.
167 */ 187 */
168 class _ZoneSpecification implements ZoneSpecification { 188 class _ZoneSpecification implements ZoneSpecification {
169 const _ZoneSpecification({ 189 const _ZoneSpecification({
170 this.handleUncaughtError: null, 190 this.handleUncaughtError: null,
171 this.run: null, 191 this.run: null,
172 this.runUnary: null, 192 this.runUnary: null,
173 this.runBinary: null, 193 this.runBinary: null,
174 this.registerCallback: null, 194 this.registerCallback: null,
175 this.registerUnaryCallback: null, 195 this.registerUnaryCallback: null,
176 this.registerBinaryCallback: null, 196 this.registerBinaryCallback: null,
197 this.errorCallback: null,
177 this.scheduleMicrotask: null, 198 this.scheduleMicrotask: null,
178 this.createTimer: null, 199 this.createTimer: null,
179 this.createPeriodicTimer: null, 200 this.createPeriodicTimer: null,
180 this.print: null, 201 this.print: null,
181 this.fork: null 202 this.fork: null
182 }); 203 });
183 204
184 // TODO(13406): Enable types when dart2js supports it. 205 // TODO(13406): Enable types when dart2js supports it.
185 final /*HandleUncaughtErrorHandler*/ handleUncaughtError; 206 final /*HandleUncaughtErrorHandler*/ handleUncaughtError;
186 final /*RunHandler*/ run; 207 final /*RunHandler*/ run;
187 final /*RunUnaryHandler*/ runUnary; 208 final /*RunUnaryHandler*/ runUnary;
188 final /*RunBinaryHandler*/ runBinary; 209 final /*RunBinaryHandler*/ runBinary;
189 final /*RegisterCallbackHandler*/ registerCallback; 210 final /*RegisterCallbackHandler*/ registerCallback;
190 final /*RegisterUnaryCallbackHandler*/ registerUnaryCallback; 211 final /*RegisterUnaryCallbackHandler*/ registerUnaryCallback;
191 final /*RegisterBinaryCallbackHandler*/ registerBinaryCallback; 212 final /*RegisterBinaryCallbackHandler*/ registerBinaryCallback;
213 final /*ErrorCallbackHandler*/ errorCallback;
192 final /*ScheduleMicrotaskHandler*/ scheduleMicrotask; 214 final /*ScheduleMicrotaskHandler*/ scheduleMicrotask;
193 final /*CreateTimerHandler*/ createTimer; 215 final /*CreateTimerHandler*/ createTimer;
194 final /*CreatePeriodicTimerHandler*/ createPeriodicTimer; 216 final /*CreatePeriodicTimerHandler*/ createPeriodicTimer;
195 final /*PrintHandler*/ print; 217 final /*PrintHandler*/ print;
196 final /*ForkHandler*/ fork; 218 final /*ForkHandler*/ fork;
197 } 219 }
198 220
199 /** 221 /**
200 * This class wraps zones for delegation. 222 * This class wraps zones for delegation.
201 * 223 *
202 * When forwarding to parent zones one can't just invoke the parent zone's 224 * When forwarding to parent zones one can't just invoke the parent zone's
203 * exposed functions (like [Zone.run]), but one needs to provide more 225 * exposed functions (like [Zone.run]), but one needs to provide more
204 * information (like the zone the `run` was initiated). Zone callbacks thus 226 * information (like the zone the `run` was initiated). Zone callbacks thus
205 * receive more information including this [ZoneDelegate] class. When delegating 227 * receive more information including this [ZoneDelegate] class. When delegating
206 * to the parent zone one should go through the given instance instead of 228 * to the parent zone one should go through the given instance instead of
207 * directly invoking the parent zone. 229 * directly invoking the parent zone.
208 */ 230 */
209 abstract class ZoneDelegate { 231 abstract class ZoneDelegate {
210 dynamic handleUncaughtError(Zone zone, error, StackTrace stackTrace); 232 dynamic handleUncaughtError(Zone zone, error, StackTrace stackTrace);
211 dynamic run(Zone zone, f()); 233 dynamic run(Zone zone, f());
212 dynamic runUnary(Zone zone, f(arg), arg); 234 dynamic runUnary(Zone zone, f(arg), arg);
213 dynamic runBinary(Zone zone, f(arg1, arg2), arg1, arg2); 235 dynamic runBinary(Zone zone, f(arg1, arg2), arg1, arg2);
214 ZoneCallback registerCallback(Zone zone, f()); 236 ZoneCallback registerCallback(Zone zone, f());
215 ZoneUnaryCallback registerUnaryCallback(Zone zone, f(arg)); 237 ZoneUnaryCallback registerUnaryCallback(Zone zone, f(arg));
216 ZoneBinaryCallback registerBinaryCallback(Zone zone, f(arg1, arg2)); 238 ZoneBinaryCallback registerBinaryCallback(Zone zone, f(arg1, arg2));
239 AsyncError errorCallback(Zone zone, Object error, StackTrace stackTrace);
217 void scheduleMicrotask(Zone zone, f()); 240 void scheduleMicrotask(Zone zone, f());
218 Timer createTimer(Zone zone, Duration duration, void f()); 241 Timer createTimer(Zone zone, Duration duration, void f());
219 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)); 242 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer));
220 void print(Zone zone, String line); 243 void print(Zone zone, String line);
221 Zone fork(Zone zone, ZoneSpecification specification, Map zoneValues); 244 Zone fork(Zone zone, ZoneSpecification specification, Map zoneValues);
222 } 245 }
223 246
224 /** 247 /**
225 * A Zone represents the asynchronous version of a dynamic extent. Asynchronous 248 * A Zone represents the asynchronous version of a dynamic extent. Asynchronous
226 * callbacks are executed in the zone they have been queued in. For example, 249 * callbacks are executed in the zone they have been queued in. For example,
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 * ZoneCallback registered = registerBinaryCallback(f); 396 * ZoneCallback registered = registerBinaryCallback(f);
374 * if (runGuarded) { 397 * if (runGuarded) {
375 * return (arg1, arg2) => this.runBinaryGuarded(registered, arg); 398 * return (arg1, arg2) => this.runBinaryGuarded(registered, arg);
376 * } 399 * }
377 * return (arg1, arg2) => thin.runBinary(registered, arg1, arg2); 400 * return (arg1, arg2) => thin.runBinary(registered, arg1, arg2);
378 */ 401 */
379 ZoneBinaryCallback bindBinaryCallback( 402 ZoneBinaryCallback bindBinaryCallback(
380 f(arg1, arg2), { bool runGuarded: true }); 403 f(arg1, arg2), { bool runGuarded: true });
381 404
382 /** 405 /**
406 * Intercepts errors when added programmtically to a `Future` or `Stream`.
407 *
408 * When caling [Completer.completeError], [Stream.addError],
409 * or [Future] constructors that take an error or a callback that may throw,
410 * the current zone is allowed to intercept and replace the error.
411 *
412 * When other libraries use intermediate controllers or completers, such
413 * calls may contain errors that have already been processed.
414 *
415 * Return `null` if no replacement is desired.
416 * The original error is used unchanged in that case.
417 * Otherwise return an instance of [AsyncError] holding
418 * the new pair of error and stack trace.
419 */
420 AsyncError errorCallback(Object error, StackTrace stackTrace);
421
422 /**
383 * Runs [f] asynchronously in this zone. 423 * Runs [f] asynchronously in this zone.
384 */ 424 */
385 void scheduleMicrotask(void f()); 425 void scheduleMicrotask(void f());
386 426
387 /** 427 /**
388 * Creates a Timer where the callback is executed in this zone. 428 * Creates a Timer where the callback is executed in this zone.
389 */ 429 */
390 Timer createTimer(Duration duration, void callback()); 430 Timer createTimer(Duration duration, void callback());
391 431
392 /** 432 /**
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 implZone, _parentDelegate(implZone), zone, f); 528 implZone, _parentDelegate(implZone), zone, f);
489 } 529 }
490 530
491 ZoneBinaryCallback registerBinaryCallback(Zone zone, f(arg1, arg2)) { 531 ZoneBinaryCallback registerBinaryCallback(Zone zone, f(arg1, arg2)) {
492 _ZoneFunction implementation = _delegationTarget._registerBinaryCallback; 532 _ZoneFunction implementation = _delegationTarget._registerBinaryCallback;
493 _Zone implZone = implementation.zone; 533 _Zone implZone = implementation.zone;
494 return (implementation.function)( 534 return (implementation.function)(
495 implZone, _parentDelegate(implZone), zone, f); 535 implZone, _parentDelegate(implZone), zone, f);
496 } 536 }
497 537
538 AsyncError errorCallback(Zone zone, Object error, StackTrace stackTrace) {
539 _ZoneFunction implementation = _delegationTarget._errorCallback;
540 _Zone implZone = implementation.zone;
541 if (identical(implZone, _ROOT_ZONE)) return null;
542 return (implementation.function)(implZone, _parentDelegate(implZone), zone,
543 error, stackTrace);
544 }
545
498 void scheduleMicrotask(Zone zone, f()) { 546 void scheduleMicrotask(Zone zone, f()) {
499 _ZoneFunction implementation = _delegationTarget._scheduleMicrotask; 547 _ZoneFunction implementation = _delegationTarget._scheduleMicrotask;
500 _Zone implZone = implementation.zone; 548 _Zone implZone = implementation.zone;
501 (implementation.function)( 549 (implementation.function)(
502 implZone, _parentDelegate(implZone), zone, f); 550 implZone, _parentDelegate(implZone), zone, f);
503 } 551 }
504 552
505 Timer createTimer(Zone zone, Duration duration, void f()) { 553 Timer createTimer(Zone zone, Duration duration, void f()) {
506 _ZoneFunction implementation = _delegationTarget._createTimer; 554 _ZoneFunction implementation = _delegationTarget._createTimer;
507 _Zone implZone = implementation.zone; 555 _Zone implZone = implementation.zone;
(...skipping 30 matching lines...) Expand all
538 */ 586 */
539 abstract class _Zone implements Zone { 587 abstract class _Zone implements Zone {
540 const _Zone(); 588 const _Zone();
541 589
542 _ZoneFunction get _runUnary; 590 _ZoneFunction get _runUnary;
543 _ZoneFunction get _run; 591 _ZoneFunction get _run;
544 _ZoneFunction get _runBinary; 592 _ZoneFunction get _runBinary;
545 _ZoneFunction get _registerCallback; 593 _ZoneFunction get _registerCallback;
546 _ZoneFunction get _registerUnaryCallback; 594 _ZoneFunction get _registerUnaryCallback;
547 _ZoneFunction get _registerBinaryCallback; 595 _ZoneFunction get _registerBinaryCallback;
596 _ZoneFunction get _errorCallback;
548 _ZoneFunction get _scheduleMicrotask; 597 _ZoneFunction get _scheduleMicrotask;
549 _ZoneFunction get _createTimer; 598 _ZoneFunction get _createTimer;
550 _ZoneFunction get _createPeriodicTimer; 599 _ZoneFunction get _createPeriodicTimer;
551 _ZoneFunction get _print; 600 _ZoneFunction get _print;
552 _ZoneFunction get _fork; 601 _ZoneFunction get _fork;
553 _ZoneFunction get _handleUncaughtError; 602 _ZoneFunction get _handleUncaughtError;
554 _Zone get parent; 603 _Zone get parent;
555 _ZoneDelegate get _delegate; 604 _ZoneDelegate get _delegate;
556 Map get _map; 605 Map get _map;
557 606
558 bool inSameErrorZone(Zone otherZone) { 607 bool inSameErrorZone(Zone otherZone) {
559 return identical(errorZone, otherZone.errorZone); 608 return identical(errorZone, otherZone.errorZone);
560 } 609 }
561 } 610 }
562 611
563 class _CustomZone extends _Zone { 612 class _CustomZone extends _Zone {
564 // The actual zone and implementation of each of these 613 // The actual zone and implementation of each of these
565 // inheritable zone functions. 614 // inheritable zone functions.
566 _ZoneFunction _runUnary; 615 _ZoneFunction _runUnary;
567 _ZoneFunction _run; 616 _ZoneFunction _run;
568 _ZoneFunction _runBinary; 617 _ZoneFunction _runBinary;
569 _ZoneFunction _registerCallback; 618 _ZoneFunction _registerCallback;
570 _ZoneFunction _registerUnaryCallback; 619 _ZoneFunction _registerUnaryCallback;
571 _ZoneFunction _registerBinaryCallback; 620 _ZoneFunction _registerBinaryCallback;
621 _ZoneFunction _errorCallback;
572 _ZoneFunction _scheduleMicrotask; 622 _ZoneFunction _scheduleMicrotask;
573 _ZoneFunction _createTimer; 623 _ZoneFunction _createTimer;
574 _ZoneFunction _createPeriodicTimer; 624 _ZoneFunction _createPeriodicTimer;
575 _ZoneFunction _print; 625 _ZoneFunction _print;
576 _ZoneFunction _fork; 626 _ZoneFunction _fork;
577 _ZoneFunction _handleUncaughtError; 627 _ZoneFunction _handleUncaughtError;
578 628
579 // A cached delegate to this zone. 629 // A cached delegate to this zone.
580 ZoneDelegate _delegateCache; 630 ZoneDelegate _delegateCache;
581 631
(...skipping 26 matching lines...) Expand all
608 : parent._runBinary; 658 : parent._runBinary;
609 _registerCallback = (specification.registerCallback != null) 659 _registerCallback = (specification.registerCallback != null)
610 ? new _ZoneFunction(this, specification.registerCallback) 660 ? new _ZoneFunction(this, specification.registerCallback)
611 : parent._registerCallback; 661 : parent._registerCallback;
612 _registerUnaryCallback = (specification.registerUnaryCallback != null) 662 _registerUnaryCallback = (specification.registerUnaryCallback != null)
613 ? new _ZoneFunction(this, specification.registerUnaryCallback) 663 ? new _ZoneFunction(this, specification.registerUnaryCallback)
614 : parent._registerUnaryCallback; 664 : parent._registerUnaryCallback;
615 _registerBinaryCallback = (specification.registerBinaryCallback != null) 665 _registerBinaryCallback = (specification.registerBinaryCallback != null)
616 ? new _ZoneFunction(this, specification.registerBinaryCallback) 666 ? new _ZoneFunction(this, specification.registerBinaryCallback)
617 : parent._registerBinaryCallback; 667 : parent._registerBinaryCallback;
668 _errorCallback = (specification.errorCallback != null)
669 ? new _ZoneFunction(this, specification.errorCallback)
670 : parent._errorCallback;
618 _scheduleMicrotask = (specification.scheduleMicrotask != null) 671 _scheduleMicrotask = (specification.scheduleMicrotask != null)
619 ? new _ZoneFunction(this, specification.scheduleMicrotask) 672 ? new _ZoneFunction(this, specification.scheduleMicrotask)
620 : parent._scheduleMicrotask; 673 : parent._scheduleMicrotask;
621 _createTimer = (specification.createTimer != null) 674 _createTimer = (specification.createTimer != null)
622 ? new _ZoneFunction(this, specification.createTimer) 675 ? new _ZoneFunction(this, specification.createTimer)
623 : parent._createTimer; 676 : parent._createTimer;
624 _createPeriodicTimer = (specification.createPeriodicTimer != null) 677 _createPeriodicTimer = (specification.createPeriodicTimer != null)
625 ? new _ZoneFunction(this, specification.createPeriodicTimer) 678 ? new _ZoneFunction(this, specification.createPeriodicTimer)
626 : parent._createPeriodicTimer; 679 : parent._createPeriodicTimer;
627 _print = (specification.print != null) 680 _print = (specification.print != null)
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 } 827 }
775 828
776 ZoneBinaryCallback registerBinaryCallback(f(arg1, arg2)) { 829 ZoneBinaryCallback registerBinaryCallback(f(arg1, arg2)) {
777 _ZoneFunction implementation = this._registerBinaryCallback; 830 _ZoneFunction implementation = this._registerBinaryCallback;
778 assert(implementation != null); 831 assert(implementation != null);
779 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); 832 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone);
780 return (implementation.function)( 833 return (implementation.function)(
781 implementation.zone, parentDelegate, this, f); 834 implementation.zone, parentDelegate, this, f);
782 } 835 }
783 836
837 AsyncError errorCallback(Object error, StackTrace stackTrace) {
838 final _ZoneFunction implementation = this._errorCallback;
839 assert(implementation != null);
840 final Zone implementationZone = implementation.zone;
841 if (identical(implementationZone, _ROOT_ZONE)) return null;
842 final ZoneDelegate parentDelegate = _parentDelegate(implementationZone);
843 return (implementation.function)(
844 implementationZone, parentDelegate, this, error, stackTrace);
845 }
846
784 void scheduleMicrotask(void f()) { 847 void scheduleMicrotask(void f()) {
785 _ZoneFunction implementation = this._scheduleMicrotask; 848 _ZoneFunction implementation = this._scheduleMicrotask;
786 assert(implementation != null); 849 assert(implementation != null);
787 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); 850 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone);
788 return (implementation.function)( 851 return (implementation.function)(
789 implementation.zone, parentDelegate, this, f); 852 implementation.zone, parentDelegate, this, f);
790 } 853 }
791 854
792 Timer createTimer(Duration duration, void f()) { 855 Timer createTimer(Duration duration, void f()) {
793 _ZoneFunction implementation = this._createTimer; 856 _ZoneFunction implementation = this._createTimer;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 ZoneUnaryCallback _rootRegisterUnaryCallback( 926 ZoneUnaryCallback _rootRegisterUnaryCallback(
864 Zone self, ZoneDelegate parent, Zone zone, f(arg)) { 927 Zone self, ZoneDelegate parent, Zone zone, f(arg)) {
865 return f; 928 return f;
866 } 929 }
867 930
868 ZoneBinaryCallback _rootRegisterBinaryCallback( 931 ZoneBinaryCallback _rootRegisterBinaryCallback(
869 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)) { 932 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)) {
870 return f; 933 return f;
871 } 934 }
872 935
936 AsyncError _rootErrorCallback(Zone self, ZoneDelegate parent, Zone zone,
937 Object error, StackTrace stackTrace) => null;
938
873 void _rootScheduleMicrotask(Zone self, ZoneDelegate parent, Zone zone, f()) { 939 void _rootScheduleMicrotask(Zone self, ZoneDelegate parent, Zone zone, f()) {
874 if (!identical(_ROOT_ZONE, zone)) { 940 if (!identical(_ROOT_ZONE, zone)) {
875 f = zone.bindCallback(f); 941 f = zone.bindCallback(f);
876 } 942 }
877 _scheduleAsyncCallback(f); 943 _scheduleAsyncCallback(f);
878 } 944 }
879 945
880 Timer _rootCreateTimer(Zone self, ZoneDelegate parent, Zone zone, 946 Timer _rootCreateTimer(Zone self, ZoneDelegate parent, Zone zone,
881 Duration duration, void callback()) { 947 Duration duration, void callback()) {
882 if (!identical(_ROOT_ZONE, zone)) { 948 if (!identical(_ROOT_ZONE, zone)) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 HandleUncaughtErrorHandler get handleUncaughtError => 999 HandleUncaughtErrorHandler get handleUncaughtError =>
934 _rootHandleUncaughtError; 1000 _rootHandleUncaughtError;
935 RunHandler get run => _rootRun; 1001 RunHandler get run => _rootRun;
936 RunUnaryHandler get runUnary => _rootRunUnary; 1002 RunUnaryHandler get runUnary => _rootRunUnary;
937 RunBinaryHandler get runBinary => _rootRunBinary; 1003 RunBinaryHandler get runBinary => _rootRunBinary;
938 RegisterCallbackHandler get registerCallback => _rootRegisterCallback; 1004 RegisterCallbackHandler get registerCallback => _rootRegisterCallback;
939 RegisterUnaryCallbackHandler get registerUnaryCallback => 1005 RegisterUnaryCallbackHandler get registerUnaryCallback =>
940 _rootRegisterUnaryCallback; 1006 _rootRegisterUnaryCallback;
941 RegisterBinaryCallbackHandler get registerBinaryCallback => 1007 RegisterBinaryCallbackHandler get registerBinaryCallback =>
942 _rootRegisterBinaryCallback; 1008 _rootRegisterBinaryCallback;
1009 ErrorCallbackHandler get errorCallback => _rootErrorCallback;
943 ScheduleMicrotaskHandler get scheduleMicrotask => _rootScheduleMicrotask; 1010 ScheduleMicrotaskHandler get scheduleMicrotask => _rootScheduleMicrotask;
944 CreateTimerHandler get createTimer => _rootCreateTimer; 1011 CreateTimerHandler get createTimer => _rootCreateTimer;
945 CreatePeriodicTimerHandler get createPeriodicTimer => 1012 CreatePeriodicTimerHandler get createPeriodicTimer =>
946 _rootCreatePeriodicTimer; 1013 _rootCreatePeriodicTimer;
947 PrintHandler get print => _rootPrint; 1014 PrintHandler get print => _rootPrint;
948 ForkHandler get fork => _rootFork; 1015 ForkHandler get fork => _rootFork;
949 } 1016 }
950 1017
951 class _RootZone extends _Zone { 1018 class _RootZone extends _Zone {
952 const _RootZone(); 1019 const _RootZone();
953 1020
954 _ZoneFunction get _run => 1021 _ZoneFunction get _run =>
955 const _ZoneFunction(_ROOT_ZONE, _rootRun); 1022 const _ZoneFunction(_ROOT_ZONE, _rootRun);
956 _ZoneFunction get _runUnary => 1023 _ZoneFunction get _runUnary =>
957 const _ZoneFunction(_ROOT_ZONE, _rootRunUnary); 1024 const _ZoneFunction(_ROOT_ZONE, _rootRunUnary);
958 _ZoneFunction get _runBinary => 1025 _ZoneFunction get _runBinary =>
959 const _ZoneFunction(_ROOT_ZONE, _rootRunBinary); 1026 const _ZoneFunction(_ROOT_ZONE, _rootRunBinary);
960 _ZoneFunction get _registerCallback => 1027 _ZoneFunction get _registerCallback =>
961 const _ZoneFunction(_ROOT_ZONE, _rootRegisterCallback); 1028 const _ZoneFunction(_ROOT_ZONE, _rootRegisterCallback);
962 _ZoneFunction get _registerUnaryCallback => 1029 _ZoneFunction get _registerUnaryCallback =>
963 const _ZoneFunction(_ROOT_ZONE, _rootRegisterUnaryCallback); 1030 const _ZoneFunction(_ROOT_ZONE, _rootRegisterUnaryCallback);
964 _ZoneFunction get _registerBinaryCallback => 1031 _ZoneFunction get _registerBinaryCallback =>
965 const _ZoneFunction(_ROOT_ZONE, _rootRegisterBinaryCallback); 1032 const _ZoneFunction(_ROOT_ZONE, _rootRegisterBinaryCallback);
1033 _ZoneFunction get _errorCallback =>
1034 const _ZoneFunction(_ROOT_ZONE, _rootErrorCallback);
966 _ZoneFunction get _scheduleMicrotask => 1035 _ZoneFunction get _scheduleMicrotask =>
967 const _ZoneFunction(_ROOT_ZONE, _rootScheduleMicrotask); 1036 const _ZoneFunction(_ROOT_ZONE, _rootScheduleMicrotask);
968 _ZoneFunction get _createTimer => 1037 _ZoneFunction get _createTimer =>
969 const _ZoneFunction(_ROOT_ZONE, _rootCreateTimer); 1038 const _ZoneFunction(_ROOT_ZONE, _rootCreateTimer);
970 _ZoneFunction get _createPeriodicTimer => 1039 _ZoneFunction get _createPeriodicTimer =>
971 const _ZoneFunction(_ROOT_ZONE, _rootCreatePeriodicTimer); 1040 const _ZoneFunction(_ROOT_ZONE, _rootCreatePeriodicTimer);
972 _ZoneFunction get _print => 1041 _ZoneFunction get _print =>
973 const _ZoneFunction(_ROOT_ZONE, _rootPrint); 1042 const _ZoneFunction(_ROOT_ZONE, _rootPrint);
974 _ZoneFunction get _fork => 1043 _ZoneFunction get _fork =>
975 const _ZoneFunction(_ROOT_ZONE, _rootFork); 1044 const _ZoneFunction(_ROOT_ZONE, _rootFork);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 if (identical(Zone._current, _ROOT_ZONE)) return f(arg1, arg2); 1156 if (identical(Zone._current, _ROOT_ZONE)) return f(arg1, arg2);
1088 return _rootRunBinary(null, null, this, f, arg1, arg2); 1157 return _rootRunBinary(null, null, this, f, arg1, arg2);
1089 } 1158 }
1090 1159
1091 ZoneCallback registerCallback(f()) => f; 1160 ZoneCallback registerCallback(f()) => f;
1092 1161
1093 ZoneUnaryCallback registerUnaryCallback(f(arg)) => f; 1162 ZoneUnaryCallback registerUnaryCallback(f(arg)) => f;
1094 1163
1095 ZoneBinaryCallback registerBinaryCallback(f(arg1, arg2)) => f; 1164 ZoneBinaryCallback registerBinaryCallback(f(arg1, arg2)) => f;
1096 1165
1166 AsyncError errorCallback(Object error, StackTrace stackTrace) => null;
1167
1097 void scheduleMicrotask(void f()) { 1168 void scheduleMicrotask(void f()) {
1098 _rootScheduleMicrotask(null, null, this, f); 1169 _rootScheduleMicrotask(null, null, this, f);
1099 } 1170 }
1100 1171
1101 Timer createTimer(Duration duration, void f()) { 1172 Timer createTimer(Duration duration, void f()) {
1102 return Timer._createTimer(duration, f); 1173 return Timer._createTimer(duration, f);
1103 } 1174 }
1104 1175
1105 Timer createPeriodicTimer(Duration duration, void f(Timer timer)) { 1176 Timer createPeriodicTimer(Duration duration, void f(Timer timer)) {
1106 return Timer._createPeriodicTimer(duration, f); 1177 return Timer._createPeriodicTimer(duration, f);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 handleUncaughtError: errorHandler); 1240 handleUncaughtError: errorHandler);
1170 } 1241 }
1171 Zone zone = Zone.current.fork(specification: zoneSpecification, 1242 Zone zone = Zone.current.fork(specification: zoneSpecification,
1172 zoneValues: zoneValues); 1243 zoneValues: zoneValues);
1173 if (onError != null) { 1244 if (onError != null) {
1174 return zone.runGuarded(body); 1245 return zone.runGuarded(body);
1175 } else { 1246 } else {
1176 return zone.run(body); 1247 return zone.run(body);
1177 } 1248 }
1178 } 1249 }
OLDNEW
« no previous file with comments | « sdk/lib/async/stream_pipe.dart ('k') | tests/lib/async/zone_error_callback_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698