Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 typedef void ScheduleMicrotaskHandler( | 24 typedef void ScheduleMicrotaskHandler( |
| 25 Zone self, ZoneDelegate parent, Zone zone, f()); | 25 Zone self, ZoneDelegate parent, Zone zone, f()); |
| 26 @deprecated | 26 @deprecated |
| 27 typedef void RunAsyncHandler( | 27 typedef void RunAsyncHandler( |
| 28 Zone self, ZoneDelegate parent, Zone zone, f()); | 28 Zone self, ZoneDelegate parent, Zone zone, f()); |
| 29 typedef Timer CreateTimerHandler( | 29 typedef Timer CreateTimerHandler( |
| 30 Zone self, ZoneDelegate parent, Zone zone, Duration duration, void f()); | 30 Zone self, ZoneDelegate parent, Zone zone, Duration duration, void f()); |
| 31 typedef Timer CreatePeriodicTimerHandler( | 31 typedef Timer CreatePeriodicTimerHandler( |
| 32 Zone self, ZoneDelegate parent, Zone zone, | 32 Zone self, ZoneDelegate parent, Zone zone, |
| 33 Duration period, void f(Timer timer)); | 33 Duration period, void f(Timer timer)); |
| 34 typedef void PrintHandler( | |
| 35 Zone self, ZoneDelegate parent, Zone zone, String line); | |
| 34 typedef Zone ForkHandler(Zone self, ZoneDelegate parent, Zone zone, | 36 typedef Zone ForkHandler(Zone self, ZoneDelegate parent, Zone zone, |
| 35 ZoneSpecification specification, | 37 ZoneSpecification specification, |
| 36 Map<Symbol, dynamic> zoneValues); | 38 Map<Symbol, dynamic> zoneValues); |
| 37 | 39 |
| 38 /** | 40 /** |
| 39 * This class provides the specification for a forked zone. | 41 * This class provides the specification for a forked zone. |
| 40 * | 42 * |
| 41 * When forking a new zone (see [Zone.fork]) one can override the default | 43 * When forking a new zone (see [Zone.fork]) one can override the default |
| 42 * behavior of the zone by providing callbacks. These callbacks must be | 44 * behavior of the zone by providing callbacks. These callbacks must be |
| 43 * given in an instance of this class. | 45 * given in an instance of this class. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 ZoneBinaryCallback registerBinaryCallback( | 77 ZoneBinaryCallback registerBinaryCallback( |
| 76 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)): null, | 78 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)): null, |
| 77 void scheduleMicrotask( | 79 void scheduleMicrotask( |
| 78 Zone self, ZoneDelegate parent, Zone zone, f()): null, | 80 Zone self, ZoneDelegate parent, Zone zone, f()): null, |
| 79 void runAsync( | 81 void runAsync( |
| 80 Zone self, ZoneDelegate parent, Zone zone, f()): null, | 82 Zone self, ZoneDelegate parent, Zone zone, f()): null, |
| 81 Timer createTimer(Zone self, ZoneDelegate parent, Zone zone, | 83 Timer createTimer(Zone self, ZoneDelegate parent, Zone zone, |
| 82 Duration duration, void f()): null, | 84 Duration duration, void f()): null, |
| 83 Timer createPeriodicTimer(Zone self, ZoneDelegate parent, Zone zone, | 85 Timer createPeriodicTimer(Zone self, ZoneDelegate parent, Zone zone, |
| 84 Duration period, void f(Timer timer)): null, | 86 Duration period, void f(Timer timer)): null, |
| 87 void print(Zone self, ZoneDelegate parent, Zone zone, String line): null, | |
| 85 Zone fork(Zone self, ZoneDelegate parent, Zone zone, | 88 Zone fork(Zone self, ZoneDelegate parent, Zone zone, |
| 86 ZoneSpecification specification, Map zoneValues): null | 89 ZoneSpecification specification, Map zoneValues): null |
| 87 }) = _ZoneSpecification; | 90 }) = _ZoneSpecification; |
| 88 | 91 |
| 89 /** | 92 /** |
| 90 * Creates a specification from [other] with the provided handlers overriding | 93 * Creates a specification from [other] with the provided handlers overriding |
| 91 * the ones in [other]. | 94 * the ones in [other]. |
| 92 */ | 95 */ |
| 93 factory ZoneSpecification.from(ZoneSpecification other, { | 96 factory ZoneSpecification.from(ZoneSpecification other, { |
| 94 dynamic handleUncaughtError(Zone self, ZoneDelegate parent, Zone zone, | 97 dynamic handleUncaughtError(Zone self, ZoneDelegate parent, Zone zone, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 105 ZoneBinaryCallback registerBinaryCallback( | 108 ZoneBinaryCallback registerBinaryCallback( |
| 106 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)): null, | 109 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)): null, |
| 107 void scheduleMicrotask( | 110 void scheduleMicrotask( |
| 108 Zone self, ZoneDelegate parent, Zone zone, f()): null, | 111 Zone self, ZoneDelegate parent, Zone zone, f()): null, |
| 109 void runAsync( | 112 void runAsync( |
| 110 Zone self, ZoneDelegate parent, Zone zone, f()): null, | 113 Zone self, ZoneDelegate parent, Zone zone, f()): null, |
| 111 Timer createTimer(Zone self, ZoneDelegate parent, Zone zone, | 114 Timer createTimer(Zone self, ZoneDelegate parent, Zone zone, |
| 112 Duration duration, void f()): null, | 115 Duration duration, void f()): null, |
| 113 Timer createPeriodicTimer(Zone self, ZoneDelegate parent, Zone zone, | 116 Timer createPeriodicTimer(Zone self, ZoneDelegate parent, Zone zone, |
| 114 Duration period, void f(Timer timer)): null, | 117 Duration period, void f(Timer timer)): null, |
| 118 void print(Zone self, ZoneDelegate parent, Zone zone, String line): null, | |
| 115 Zone fork(Zone self, ZoneDelegate parent, Zone zone, | 119 Zone fork(Zone self, ZoneDelegate parent, Zone zone, |
| 116 ZoneSpecification specification, | 120 ZoneSpecification specification, |
| 117 Map<Symbol, dynamic> zoneValues): null | 121 Map<Symbol, dynamic> zoneValues): null |
| 118 }) { | 122 }) { |
| 119 return new ZoneSpecification( | 123 return new ZoneSpecification( |
| 120 handleUncaughtError: handleUncaughtError != null | 124 handleUncaughtError: handleUncaughtError != null |
| 121 ? handleUncaughtError | 125 ? handleUncaughtError |
| 122 : other.handleUncaughtError, | 126 : other.handleUncaughtError, |
| 123 run: run != null ? run : other.run, | 127 run: run != null ? run : other.run, |
| 124 runUnary: runUnary != null ? runUnary : other.runUnary, | 128 runUnary: runUnary != null ? runUnary : other.runUnary, |
| 125 runBinary: runBinary != null ? runBinary : other.runBinary, | 129 runBinary: runBinary != null ? runBinary : other.runBinary, |
| 126 registerCallback: registerCallback != null | 130 registerCallback: registerCallback != null |
| 127 ? registerCallback | 131 ? registerCallback |
| 128 : other.registerCallback, | 132 : other.registerCallback, |
| 129 registerUnaryCallback: registerUnaryCallback != null | 133 registerUnaryCallback: registerUnaryCallback != null |
| 130 ? registerUnaryCallback | 134 ? registerUnaryCallback |
| 131 : other.registerUnaryCallback, | 135 : other.registerUnaryCallback, |
| 132 registerBinaryCallback: registerBinaryCallback != null | 136 registerBinaryCallback: registerBinaryCallback != null |
| 133 ? registerBinaryCallback | 137 ? registerBinaryCallback |
| 134 : other.registerBinaryCallback, | 138 : other.registerBinaryCallback, |
| 135 scheduleMicrotask: scheduleMicrotask != null | 139 scheduleMicrotask: scheduleMicrotask != null |
| 136 ? scheduleMicrotask | 140 ? scheduleMicrotask |
| 137 : (runAsync != null | 141 : (runAsync != null |
| 138 ? runAsync | 142 ? runAsync |
| 139 : other.scheduleMicrotask), | 143 : other.scheduleMicrotask), |
| 140 createTimer : createTimer != null ? createTimer : other.createTimer, | 144 createTimer : createTimer != null ? createTimer : other.createTimer, |
| 141 createPeriodicTimer: createPeriodicTimer != null | 145 createPeriodicTimer: createPeriodicTimer != null |
| 142 ? createPeriodicTimer | 146 ? createPeriodicTimer |
| 143 : other.createPeriodicTimer, | 147 : other.createPeriodicTimer, |
| 148 print : print != null ? print : other.print, | |
| 144 fork: fork != null ? fork : other.fork); | 149 fork: fork != null ? fork : other.fork); |
| 145 } | 150 } |
| 146 | 151 |
| 147 HandleUncaughtErrorHandler get handleUncaughtError; | 152 HandleUncaughtErrorHandler get handleUncaughtError; |
| 148 RunHandler get run; | 153 RunHandler get run; |
| 149 RunUnaryHandler get runUnary; | 154 RunUnaryHandler get runUnary; |
| 150 RunBinaryHandler get runBinary; | 155 RunBinaryHandler get runBinary; |
| 151 RegisterCallbackHandler get registerCallback; | 156 RegisterCallbackHandler get registerCallback; |
| 152 RegisterUnaryCallbackHandler get registerUnaryCallback; | 157 RegisterUnaryCallbackHandler get registerUnaryCallback; |
| 153 RegisterBinaryCallbackHandler get registerBinaryCallback; | 158 RegisterBinaryCallbackHandler get registerBinaryCallback; |
| 154 ScheduleMicrotaskHandler get scheduleMicrotask; | 159 ScheduleMicrotaskHandler get scheduleMicrotask; |
| 155 @deprecated | 160 @deprecated |
| 156 RunAsyncHandler get runAsync; | 161 RunAsyncHandler get runAsync; |
| 157 CreateTimerHandler get createTimer; | 162 CreateTimerHandler get createTimer; |
| 158 CreatePeriodicTimerHandler get createPeriodicTimer; | 163 CreatePeriodicTimerHandler get createPeriodicTimer; |
| 164 PrintHandler get print; | |
| 159 ForkHandler get fork; | 165 ForkHandler get fork; |
| 160 } | 166 } |
| 161 | 167 |
| 162 /** | 168 /** |
| 163 * Internal [ZoneSpecification] class. | 169 * Internal [ZoneSpecification] class. |
| 164 * | 170 * |
| 165 * The implementation wants to rely on the fact that the getters cannot change | 171 * The implementation wants to rely on the fact that the getters cannot change |
| 166 * dynamically. We thus require users to go through the redirecting | 172 * dynamically. We thus require users to go through the redirecting |
| 167 * [ZoneSpecification] constructor which instantiates this class. | 173 * [ZoneSpecification] constructor which instantiates this class. |
| 168 */ | 174 */ |
| 169 class _ZoneSpecification implements ZoneSpecification { | 175 class _ZoneSpecification implements ZoneSpecification { |
| 170 const _ZoneSpecification({ | 176 const _ZoneSpecification({ |
| 171 this.handleUncaughtError: null, | 177 this.handleUncaughtError: null, |
| 172 this.run: null, | 178 this.run: null, |
| 173 this.runUnary: null, | 179 this.runUnary: null, |
| 174 this.runBinary: null, | 180 this.runBinary: null, |
| 175 this.registerCallback: null, | 181 this.registerCallback: null, |
| 176 this.registerUnaryCallback: null, | 182 this.registerUnaryCallback: null, |
| 177 this.registerBinaryCallback: null, | 183 this.registerBinaryCallback: null, |
| 178 this.scheduleMicrotask: null, | 184 this.scheduleMicrotask: null, |
| 179 this.runAsync: null, | 185 this.runAsync: null, |
| 180 this.createTimer: null, | 186 this.createTimer: null, |
| 181 this.createPeriodicTimer: null, | 187 this.createPeriodicTimer: null, |
| 188 this.print: null, | |
| 182 this.fork: null | 189 this.fork: null |
| 183 }); | 190 }); |
| 184 | 191 |
| 185 // TODO(13406): Enable types when dart2js supports it. | 192 // TODO(13406): Enable types when dart2js supports it. |
| 186 final /*HandleUncaughtErrorHandler*/ handleUncaughtError; | 193 final /*HandleUncaughtErrorHandler*/ handleUncaughtError; |
| 187 final /*RunHandler*/ run; | 194 final /*RunHandler*/ run; |
| 188 final /*RunUnaryHandler*/ runUnary; | 195 final /*RunUnaryHandler*/ runUnary; |
| 189 final /*RunBinaryHandler*/ runBinary; | 196 final /*RunBinaryHandler*/ runBinary; |
| 190 final /*RegisterCallbackHandler*/ registerCallback; | 197 final /*RegisterCallbackHandler*/ registerCallback; |
| 191 final /*RegisterUnaryCallbackHandler*/ registerUnaryCallback; | 198 final /*RegisterUnaryCallbackHandler*/ registerUnaryCallback; |
| 192 final /*RegisterBinaryCallbackHandler*/ registerBinaryCallback; | 199 final /*RegisterBinaryCallbackHandler*/ registerBinaryCallback; |
| 193 final /*ScheduleMicrotaskHandler*/ scheduleMicrotask; | 200 final /*ScheduleMicrotaskHandler*/ scheduleMicrotask; |
| 194 @deprecated | 201 @deprecated |
| 195 final /*RunAsyncHandler*/ runAsync; | 202 final /*RunAsyncHandler*/ runAsync; |
| 196 final /*CreateTimerHandler*/ createTimer; | 203 final /*CreateTimerHandler*/ createTimer; |
| 197 final /*CreatePeriodicTimerHandler*/ createPeriodicTimer; | 204 final /*CreatePeriodicTimerHandler*/ createPeriodicTimer; |
| 205 final /*PrintHandler*/ print; | |
| 198 final /*ForkHandler*/ fork; | 206 final /*ForkHandler*/ fork; |
| 199 } | 207 } |
| 200 | 208 |
| 201 /** | 209 /** |
| 202 * This class wraps zones for delegation. | 210 * This class wraps zones for delegation. |
| 203 * | 211 * |
| 204 * When forwarding to parent zones one can't just invoke the parent zone's | 212 * When forwarding to parent zones one can't just invoke the parent zone's |
| 205 * exposed functions (like [Zone.run]), but one needs to provide more | 213 * exposed functions (like [Zone.run]), but one needs to provide more |
| 206 * information (like the zone the `run` was initiated). Zone callbacks thus | 214 * information (like the zone the `run` was initiated). Zone callbacks thus |
| 207 * receive more information including this [ZoneDelegate] class. When delegating | 215 * receive more information including this [ZoneDelegate] class. When delegating |
| 208 * to the parent zone one should go through the given instance instead of | 216 * to the parent zone one should go through the given instance instead of |
| 209 * directly invoking the parent zone. | 217 * directly invoking the parent zone. |
| 210 */ | 218 */ |
| 211 abstract class ZoneDelegate { | 219 abstract class ZoneDelegate { |
| 212 /// The [Zone] this class wraps. | 220 /// The [Zone] this class wraps. |
| 213 Zone get _zone; | 221 Zone get _zone; |
| 214 | 222 |
| 215 dynamic handleUncaughtError(Zone zone, error, StackTrace stackTrace); | 223 dynamic handleUncaughtError(Zone zone, error, StackTrace stackTrace); |
| 216 dynamic run(Zone zone, f()); | 224 dynamic run(Zone zone, f()); |
| 217 dynamic runUnary(Zone zone, f(arg), arg); | 225 dynamic runUnary(Zone zone, f(arg), arg); |
| 218 dynamic runBinary(Zone zone, f(arg1, arg2), arg1, arg2); | 226 dynamic runBinary(Zone zone, f(arg1, arg2), arg1, arg2); |
| 219 ZoneCallback registerCallback(Zone zone, f()); | 227 ZoneCallback registerCallback(Zone zone, f()); |
| 220 ZoneUnaryCallback registerUnaryCallback(Zone zone, f(arg)); | 228 ZoneUnaryCallback registerUnaryCallback(Zone zone, f(arg)); |
| 221 ZoneBinaryCallback registerBinaryCallback(Zone zone, f(arg1, arg2)); | 229 ZoneBinaryCallback registerBinaryCallback(Zone zone, f(arg1, arg2)); |
| 222 @deprecated | 230 @deprecated |
| 223 void runAsync(Zone zone, f()); | 231 void runAsync(Zone zone, f()); |
| 224 void scheduleMicrotask(Zone zone, f()); | 232 void scheduleMicrotask(Zone zone, f()); |
| 225 Timer createTimer(Zone zone, Duration duration, void f()); | 233 Timer createTimer(Zone zone, Duration duration, void f()); |
| 226 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)); | 234 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)); |
| 235 void print(Zone zone, String line); | |
| 227 Zone fork(Zone zone, ZoneSpecification specification, Map zoneValues); | 236 Zone fork(Zone zone, ZoneSpecification specification, Map zoneValues); |
| 228 } | 237 } |
| 229 | 238 |
| 230 /** | 239 /** |
| 231 * A Zone represents the asynchronous version of a dynamic extent. Asynchronous | 240 * A Zone represents the asynchronous version of a dynamic extent. Asynchronous |
| 232 * callbacks are executed in the zone they have been queued in. For example, | 241 * callbacks are executed in the zone they have been queued in. For example, |
| 233 * the callback of a `future.then` is executed in the same zone as the one where | 242 * the callback of a `future.then` is executed in the same zone as the one where |
| 234 * the `then` was invoked. | 243 * the `then` was invoked. |
| 235 */ | 244 */ |
| 236 abstract class Zone { | 245 abstract class Zone { |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 379 * Creates a Timer where the callback is executed in this zone. | 388 * Creates a Timer where the callback is executed in this zone. |
| 380 */ | 389 */ |
| 381 Timer createTimer(Duration duration, void callback()); | 390 Timer createTimer(Duration duration, void callback()); |
| 382 | 391 |
| 383 /** | 392 /** |
| 384 * Creates a periodic Timer where the callback is executed in this zone. | 393 * Creates a periodic Timer where the callback is executed in this zone. |
| 385 */ | 394 */ |
| 386 Timer createPeriodicTimer(Duration period, void callback(Timer timer)); | 395 Timer createPeriodicTimer(Duration period, void callback(Timer timer)); |
| 387 | 396 |
| 388 /** | 397 /** |
| 398 * Prints the given [line]. | |
| 399 */ | |
| 400 void print(String line); | |
| 401 | |
| 402 /** | |
| 389 * The error zone is the one that is responsible for dealing with uncaught | 403 * The error zone is the one that is responsible for dealing with uncaught |
| 390 * errors. Errors are not allowed to cross zones with different error-zones. | 404 * errors. Errors are not allowed to cross zones with different error-zones. |
| 391 */ | 405 */ |
| 392 Zone get _errorZone; | 406 Zone get _errorZone; |
| 393 | 407 |
| 394 /** | 408 /** |
| 395 * Retrieves the zone-value associated with [key]. | 409 * Retrieves the zone-value associated with [key]. |
| 396 * | 410 * |
| 397 * If this zone does not contain the value looks up the same key in the | 411 * If this zone does not contain the value looks up the same key in the |
| 398 * parent zone. If the [key] is not found returns `null`. | 412 * parent zone. If the [key] is not found returns `null`. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 500 | 514 |
| 501 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)) { | 515 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)) { |
| 502 _BaseZone parent = _degelationTarget; | 516 _BaseZone parent = _degelationTarget; |
| 503 while (parent._specification.createPeriodicTimer == null) { | 517 while (parent._specification.createPeriodicTimer == null) { |
| 504 parent = parent.parent; | 518 parent = parent.parent; |
| 505 } | 519 } |
| 506 return (parent._specification.createPeriodicTimer)( | 520 return (parent._specification.createPeriodicTimer)( |
| 507 parent, new _ZoneDelegate(parent.parent), zone, period, f); | 521 parent, new _ZoneDelegate(parent.parent), zone, period, f); |
| 508 } | 522 } |
| 509 | 523 |
| 524 void print(Zone zone, String line) { | |
| 525 _CustomizedZone parent = _degelationTarget; | |
|
Ivan Posva
2013/10/16 07:19:51
Why is this a _CustomizedZone when all the other c
floitsch
2013/10/16 07:38:56
That was a bad merge and mistake. Had to do a foll
| |
| 526 while (parent._specification.print == null) { | |
| 527 parent = parent.parent; | |
| 528 } | |
| 529 (parent._specification.print)( | |
| 530 parent, new _ZoneDelegate(parent.parent), zone, line); | |
|
Ivan Posva
2013/10/16 07:19:51
See question below about repeatedly allocating _Zo
| |
| 531 } | |
| 532 | |
| 510 Zone fork(Zone zone, ZoneSpecification specification, | 533 Zone fork(Zone zone, ZoneSpecification specification, |
| 511 Map<Symbol, dynamic> zoneValues) { | 534 Map<Symbol, dynamic> zoneValues) { |
| 512 _BaseZone parent = _degelationTarget; | 535 _BaseZone parent = _degelationTarget; |
| 513 while (parent._specification.fork == null) { | 536 while (parent._specification.fork == null) { |
| 514 parent = parent.parent; | 537 parent = parent.parent; |
| 515 } | 538 } |
| 516 _ZoneDelegate grandParent = new _ZoneDelegate(parent.parent); | 539 _ZoneDelegate grandParent = new _ZoneDelegate(parent.parent); |
| 517 return (parent._specification.fork)( | 540 return (parent._specification.fork)( |
| 518 parent, grandParent, zone, specification, zoneValues); | 541 parent, grandParent, zone, specification, zoneValues); |
| 519 } | 542 } |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 663 scheduleMicrotask(f); | 686 scheduleMicrotask(f); |
| 664 } | 687 } |
| 665 | 688 |
| 666 Timer createTimer(Duration duration, void f()) { | 689 Timer createTimer(Duration duration, void f()) { |
| 667 return new _ZoneDelegate(this).createTimer(this, duration, f); | 690 return new _ZoneDelegate(this).createTimer(this, duration, f); |
| 668 } | 691 } |
| 669 | 692 |
| 670 Timer createPeriodicTimer(Duration duration, void f(Timer timer)) { | 693 Timer createPeriodicTimer(Duration duration, void f(Timer timer)) { |
| 671 return new _ZoneDelegate(this).createPeriodicTimer(this, duration, f); | 694 return new _ZoneDelegate(this).createPeriodicTimer(this, duration, f); |
| 672 } | 695 } |
| 696 | |
| 697 void print(String line) { | |
| 698 new _ZoneDelegate(this).print(this, line); | |
|
Ivan Posva
2013/10/16 07:19:51
I am wondering whether it is really necessary to a
floitsch
2013/10/16 07:38:56
It's not and on my TODO list.
| |
| 699 } | |
| 673 } | 700 } |
| 674 | 701 |
| 675 void _rootHandleUncaughtError( | 702 void _rootHandleUncaughtError( |
| 676 Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace) { | 703 Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace) { |
| 677 _scheduleAsyncCallback(() { | 704 _scheduleAsyncCallback(() { |
| 678 print("Uncaught Error: ${error}"); | 705 print("Uncaught Error: ${error}"); |
| 679 var trace = stackTrace; | 706 var trace = stackTrace; |
| 680 if (trace == null) trace = getAttachedStackTrace(error); | 707 if (trace == null) trace = getAttachedStackTrace(error); |
| 681 // Clear the attached stack trace (if any). | 708 // Clear the attached stack trace (if any). |
| 682 _attachStackTrace(error, null); | 709 _attachStackTrace(error, null); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 747 Duration duration, void callback()) { | 774 Duration duration, void callback()) { |
| 748 return _createTimer(duration, callback); | 775 return _createTimer(duration, callback); |
| 749 } | 776 } |
| 750 | 777 |
| 751 Timer _rootCreatePeriodicTimer( | 778 Timer _rootCreatePeriodicTimer( |
| 752 Zone self, ZoneDelegate parent, Zone zone, | 779 Zone self, ZoneDelegate parent, Zone zone, |
| 753 Duration duration, void callback(Timer timer)) { | 780 Duration duration, void callback(Timer timer)) { |
| 754 return _createPeriodicTimer(duration, callback); | 781 return _createPeriodicTimer(duration, callback); |
| 755 } | 782 } |
| 756 | 783 |
| 784 void _rootPrint(Zone self, ZoneDelegate parent, Zone zone, String line) { | |
| 785 printToConsole(line); | |
| 786 } | |
| 787 | |
| 788 void _printToZone(String line) { | |
| 789 Zone.current.print(line); | |
| 790 } | |
| 791 | |
| 757 Zone _rootFork(Zone self, ZoneDelegate parent, Zone zone, | 792 Zone _rootFork(Zone self, ZoneDelegate parent, Zone zone, |
| 758 ZoneSpecification specification, | 793 ZoneSpecification specification, |
| 759 Map<Symbol, dynamic> zoneValues) { | 794 Map<Symbol, dynamic> zoneValues) { |
| 795 // TODO(floitsch): it would be nice if we could get rid of this hack. | |
| 796 // Change the static zoneOrDirectPrint function to go through zones | |
| 797 // from now on. | |
| 798 printToZone = _printToZone; | |
| 799 | |
| 760 if (specification == null) { | 800 if (specification == null) { |
| 761 specification = const ZoneSpecification(); | 801 specification = const ZoneSpecification(); |
| 762 } else if (specification is! _ZoneSpecification) { | 802 } else if (specification is! _ZoneSpecification) { |
| 763 throw new ArgumentError("ZoneSpecifications must be instantiated" | 803 throw new ArgumentError("ZoneSpecifications must be instantiated" |
| 764 " with the provided constructor."); | 804 " with the provided constructor."); |
| 765 } | 805 } |
| 766 Map<Symbol, dynamic> copiedMap = new HashMap(); | 806 Map<Symbol, dynamic> copiedMap = new HashMap(); |
| 767 if (zoneValues != null) { | 807 if (zoneValues != null) { |
| 768 zoneValues.forEach((Symbol key, value) { | 808 zoneValues.forEach((Symbol key, value) { |
| 769 if (key == null) { | 809 if (key == null) { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 787 RegisterUnaryCallbackHandler get registerUnaryCallback => | 827 RegisterUnaryCallbackHandler get registerUnaryCallback => |
| 788 _rootRegisterUnaryCallback; | 828 _rootRegisterUnaryCallback; |
| 789 RegisterBinaryCallbackHandler get registerBinaryCallback => | 829 RegisterBinaryCallbackHandler get registerBinaryCallback => |
| 790 _rootRegisterBinaryCallback; | 830 _rootRegisterBinaryCallback; |
| 791 ScheduleMicrotaskHandler get scheduleMicrotask => _rootScheduleMicrotask; | 831 ScheduleMicrotaskHandler get scheduleMicrotask => _rootScheduleMicrotask; |
| 792 @deprecated | 832 @deprecated |
| 793 RunAsyncHandler get runAsync => null; | 833 RunAsyncHandler get runAsync => null; |
| 794 CreateTimerHandler get createTimer => _rootCreateTimer; | 834 CreateTimerHandler get createTimer => _rootCreateTimer; |
| 795 CreatePeriodicTimerHandler get createPeriodicTimer => | 835 CreatePeriodicTimerHandler get createPeriodicTimer => |
| 796 _rootCreatePeriodicTimer; | 836 _rootCreatePeriodicTimer; |
| 837 PrintHandler get print => _rootPrint; | |
| 797 ForkHandler get fork => _rootFork; | 838 ForkHandler get fork => _rootFork; |
| 798 } | 839 } |
| 799 | 840 |
| 800 class _RootZone extends _BaseZone { | 841 class _RootZone extends _BaseZone { |
| 801 const _RootZone(); | 842 const _RootZone(); |
| 802 | 843 |
| 803 Zone get parent => null; | 844 Zone get parent => null; |
| 804 ZoneSpecification get _specification => const _RootZoneSpecification(); | 845 ZoneSpecification get _specification => const _RootZoneSpecification(); |
| 805 Zone get _errorZone => this; | 846 Zone get _errorZone => this; |
| 806 | 847 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 839 @deprecated | 880 @deprecated |
| 840 void runAsync(void f()) { | 881 void runAsync(void f()) { |
| 841 scheduleMicrotask(f); | 882 scheduleMicrotask(f); |
| 842 } | 883 } |
| 843 | 884 |
| 844 Timer createTimer(Duration duration, void f()) => | 885 Timer createTimer(Duration duration, void f()) => |
| 845 _rootCreateTimer(this, null, this, duration, f); | 886 _rootCreateTimer(this, null, this, duration, f); |
| 846 | 887 |
| 847 Timer createPeriodicTimer(Duration duration, void f(Timer timer)) => | 888 Timer createPeriodicTimer(Duration duration, void f(Timer timer)) => |
| 848 _rootCreatePeriodicTimer(this, null, this, duration, f); | 889 _rootCreatePeriodicTimer(this, null, this, duration, f); |
| 890 | |
| 891 void print(String line) => _rootPrint(this, null, this, line); | |
| 849 } | 892 } |
| 850 | 893 |
| 851 const _ROOT_ZONE = const _RootZone(); | 894 const _ROOT_ZONE = const _RootZone(); |
| 852 | 895 |
| 853 | 896 |
| 854 /** | 897 /** |
| 855 * Runs [body] in its own zone. | 898 * Runs [body] in its own zone. |
| 856 * | 899 * |
| 857 * If [onError] is non-null the zone is considered an error zone. All uncaught | 900 * If [onError] is non-null the zone is considered an error zone. All uncaught |
| 858 * errors, synchronous or asynchronous, in the zone are caught and handled | 901 * errors, synchronous or asynchronous, in the zone are caught and handled |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 968 ZoneSpecification specification = | 1011 ZoneSpecification specification = |
| 969 new ZoneSpecification(handleUncaughtError: errorHandler, | 1012 new ZoneSpecification(handleUncaughtError: errorHandler, |
| 970 scheduleMicrotask: asyncHandler); | 1013 scheduleMicrotask: asyncHandler); |
| 971 Zone zone = Zone.current.fork(specification: specification); | 1014 Zone zone = Zone.current.fork(specification: specification); |
| 972 if (onError != null) { | 1015 if (onError != null) { |
| 973 return zone.runGuarded(body); | 1016 return zone.runGuarded(body); |
| 974 } else { | 1017 } else { |
| 975 return zone.run(body); | 1018 return zone.run(body); |
| 976 } | 1019 } |
| 977 } | 1020 } |
| OLD | NEW |