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 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 737 | 737 |
| 738 Zone _rootFork(Zone self, ZoneDelegate parent, Zone zone, | 738 Zone _rootFork(Zone self, ZoneDelegate parent, Zone zone, |
| 739 ZoneSpecification specification, | 739 ZoneSpecification specification, |
| 740 Map<Symbol, dynamic> zoneValues) { | 740 Map<Symbol, dynamic> zoneValues) { |
| 741 if (specification == null) { | 741 if (specification == null) { |
| 742 specification = const ZoneSpecification(); | 742 specification = const ZoneSpecification(); |
| 743 } else if (specification is! _ZoneSpecification) { | 743 } else if (specification is! _ZoneSpecification) { |
| 744 throw new ArgumentError("ZoneSpecifications must be instantiated" | 744 throw new ArgumentError("ZoneSpecifications must be instantiated" |
| 745 " with the provided constructor."); | 745 " with the provided constructor."); |
| 746 } | 746 } |
| 747 Map<Symbol, dynamic> copiedMap = new HashMap(); | 747 Map<Symbol, dynamic> copiedMap = new HashMap(); |
|
Lasse Reichstein Nielsen
2013/10/15 12:04:07
Why was the zoneValues based on Symbols only?
I se
floitsch
2013/10/15 13:06:07
We can change later.
| |
| 748 if (zoneValues != null) { | 748 if (zoneValues != null) { |
| 749 zoneValues.forEach((Symbol key, value) { | 749 zoneValues.forEach((Symbol key, value) { |
| 750 if (key == null) { | 750 if (key == null) { |
| 751 throw new ArgumentError("ZoneValue key must not be null"); | 751 throw new ArgumentError("ZoneValue key must not be null"); |
| 752 } | 752 } |
| 753 copiedMap[key] = value; | 753 copiedMap[key] = value; |
| 754 }); | 754 }); |
| 755 } | 755 } |
| 756 return new _CustomizedZone(zone, specification, copiedMap); | 756 return new _CustomizedZone(zone, specification, copiedMap); |
| 757 } | 757 } |
| 758 | 758 |
| 759 const _ROOT_SPECIFICATION = const ZoneSpecification( | 759 class _RootZoneSpecification implements ZoneSpecification { |
| 760 handleUncaughtError: _rootHandleUncaughtError, | 760 const _RootZoneSpecification(); |
| 761 run: _rootRun, | |
| 762 runUnary: _rootRunUnary, | |
| 763 runBinary: _rootRunBinary, | |
| 764 registerCallback: _rootRegisterCallback, | |
| 765 registerUnaryCallback: _rootRegisterUnaryCallback, | |
| 766 registerBinaryCallback: _rootRegisterBinaryCallback, | |
| 767 scheduleMicrotask: _rootScheduleMicrotask, | |
| 768 createTimer: _rootCreateTimer, | |
| 769 createPeriodicTimer: _rootCreatePeriodicTimer, | |
| 770 fork: _rootFork | |
| 771 ); | |
| 772 | 761 |
| 773 const _ROOT_ZONE = | 762 HandleUncaughtErrorHandler get handleUncaughtError => |
| 774 const _CustomizedZone(null, _ROOT_SPECIFICATION, const <Symbol, dynamic>{}); | 763 _rootHandleUncaughtError; |
| 764 RunHandler get run => _rootRun; | |
| 765 RunUnaryHandler get runUnary => _rootRunUnary; | |
| 766 RunBinaryHandler get runBinary => _rootRunBinary; | |
| 767 RegisterCallbackHandler get registerCallback => _rootRegisterCallback; | |
| 768 RegisterUnaryCallbackHandler get registerUnaryCallback => | |
| 769 _rootRegisterUnaryCallback; | |
| 770 RegisterBinaryCallbackHandler get registerBinaryCallback => | |
| 771 _rootRegisterBinaryCallback; | |
| 772 ScheduleMicrotaskHandler get scheduleMicrotask => _rootScheduleMicrotask; | |
| 773 @deprecated | |
| 774 RunAsyncHandler get runAsync => null; | |
| 775 CreateTimerHandler get createTimer => _rootCreateTimer; | |
| 776 CreatePeriodicTimerHandler get createPeriodicTimer => | |
| 777 _rootCreatePeriodicTimer; | |
| 778 ForkHandler get fork => _rootFork; | |
| 779 } | |
| 780 | |
| 781 class _RootZone extends _CustomizedZone { | |
| 782 const _RootZone() | |
| 783 : super(null, const _RootZoneSpecification(), const <Symbol, dynamic>{}); | |
|
Lasse Reichstein Nielsen
2013/10/15 12:04:07
Can you replace the map with null, since it is nev
floitsch
2013/10/15 13:06:07
Done.
| |
| 784 | |
| 785 Zone get _errorZone => this; | |
| 786 | |
| 787 bool inSameErrorZone(Zone otherZone) => otherZone._errorZone == this; | |
| 788 | |
| 789 operator [](Symbol key) => null; | |
| 790 | |
| 791 // Methods that can be customized by the zone specification. | |
| 792 | |
| 793 dynamic handleUncaughtError(error, StackTrace stackTrace) => | |
| 794 _rootHandleUncaughtError(this, null, this, error, stackTrace); | |
| 795 | |
| 796 Zone fork({ZoneSpecification specification, Map zoneValues}) => | |
| 797 _rootFork(this, null, this, specification, zoneValues); | |
| 798 | |
| 799 dynamic run(f()) => _rootRun(this, null, this, f); | |
| 800 | |
| 801 dynamic runUnary(f(arg), arg) => _rootRunUnary(this, null, this, f, arg); | |
| 802 | |
| 803 dynamic runBinary(f(arg1, arg2), arg1, arg2) => | |
| 804 _rootRunBinary(this, null, this, f, arg1, arg2); | |
| 805 | |
| 806 ZoneCallback registerCallback(f()) => | |
| 807 _rootRegisterCallback(this, null, this, f); | |
| 808 | |
| 809 ZoneUnaryCallback registerUnaryCallback(f(arg)) => | |
| 810 _rootRegisterUnaryCallback(this, null, this, f); | |
| 811 | |
| 812 ZoneBinaryCallback registerBinaryCallback(f(arg1, arg2)) => | |
| 813 _rootRegisterBinaryCallback(this, null, this, f); | |
| 814 | |
| 815 void scheduleMicrotask(void f()) { | |
| 816 _rootScheduleMicrotask(this, null, this, f); | |
| 817 } | |
| 818 | |
| 819 @deprecated | |
| 820 void runAsync(void f()) { | |
| 821 scheduleMicrotask(f); | |
| 822 } | |
| 823 | |
| 824 Timer createTimer(Duration duration, void f()) => | |
| 825 _rootCreateTimer(this, null, this, duration, f); | |
| 826 | |
| 827 Timer createPeriodicTimer(Duration duration, void f(Timer timer)) => | |
| 828 _rootCreatePeriodicTimer(this, null, this, duration, f); | |
| 829 } | |
| 830 | |
| 831 const _ROOT_SPECIFICATION = const _RootZoneSpecification(); | |
| 832 const _ROOT_ZONE = const _RootZone(); | |
| 775 | 833 |
| 776 | 834 |
| 777 /** | 835 /** |
| 778 * Runs [body] in its own zone. | 836 * Runs [body] in its own zone. |
| 779 * | 837 * |
| 780 * If [onError] is non-null the zone is considered an error zone. All uncaught | 838 * If [onError] is non-null the zone is considered an error zone. All uncaught |
| 781 * errors, synchronous or asynchronous, in the zone are caught and handled | 839 * errors, synchronous or asynchronous, in the zone are caught and handled |
| 782 * by the callback. | 840 * by the callback. |
| 783 * | 841 * |
| 784 * Errors may never cross error-zone boundaries. This is intuitive for leaving | 842 * Errors may never cross error-zone boundaries. This is intuitive for leaving |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 891 ZoneSpecification specification = | 949 ZoneSpecification specification = |
| 892 new ZoneSpecification(handleUncaughtError: errorHandler, | 950 new ZoneSpecification(handleUncaughtError: errorHandler, |
| 893 scheduleMicrotask: asyncHandler); | 951 scheduleMicrotask: asyncHandler); |
| 894 Zone zone = Zone.current.fork(specification: specification); | 952 Zone zone = Zone.current.fork(specification: specification); |
| 895 if (onError != null) { | 953 if (onError != null) { |
| 896 return zone.runGuarded(body); | 954 return zone.runGuarded(body); |
| 897 } else { | 955 } else { |
| 898 return zone.run(body); | 956 return zone.run(body); |
| 899 } | 957 } |
| 900 } | 958 } |
| OLD | NEW |