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 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 return new _ZoneDelegate(this).createPeriodicTimer(this, duration, f); | 694 return new _ZoneDelegate(this).createPeriodicTimer(this, duration, f); |
695 } | 695 } |
696 | 696 |
697 void print(String line) { | 697 void print(String line) { |
698 new _ZoneDelegate(this).print(this, line); | 698 new _ZoneDelegate(this).print(this, line); |
699 } | 699 } |
700 } | 700 } |
701 | 701 |
702 void _rootHandleUncaughtError( | 702 void _rootHandleUncaughtError( |
703 Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace) { | 703 Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace) { |
704 _scheduleAsyncCallback(() { | 704 self.run(() { |
705 print("Uncaught Error: ${error}"); | 705 _scheduleAsyncCallback(() { |
706 var trace = stackTrace; | 706 print("Uncaught Error: ${error}"); |
707 if (trace == null) trace = getAttachedStackTrace(error); | 707 var trace = stackTrace; |
708 // Clear the attached stack trace (if any). | 708 if (trace == null) trace = getAttachedStackTrace(error); |
709 _attachStackTrace(error, null); | 709 // Clear the attached stack trace (if any). |
710 if (trace != null) { | 710 _attachStackTrace(error, null); |
711 print("Stack Trace: \n$trace\n"); | 711 if (trace != null) { |
712 } | 712 print("Stack Trace: \n$trace\n"); |
713 throw error; | 713 } |
| 714 throw error; |
| 715 }); |
714 }); | 716 }); |
715 } | 717 } |
716 | 718 |
717 dynamic _rootRun(Zone self, ZoneDelegate parent, Zone zone, f()) { | 719 dynamic _rootRun(Zone self, ZoneDelegate parent, Zone zone, f()) { |
718 if (Zone._current == zone) return f(); | 720 if (Zone._current == zone) return f(); |
719 | 721 |
720 Zone old = Zone._current; | 722 Zone old = Zone._current; |
721 try { | 723 try { |
722 Zone._current = zone; | 724 Zone._current = zone; |
723 return f(); | 725 return f(); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 const _RootZone(); | 844 const _RootZone(); |
843 | 845 |
844 Zone get parent => null; | 846 Zone get parent => null; |
845 ZoneSpecification get _specification => const _RootZoneSpecification(); | 847 ZoneSpecification get _specification => const _RootZoneSpecification(); |
846 Zone get _errorZone => this; | 848 Zone get _errorZone => this; |
847 | 849 |
848 bool inSameErrorZone(Zone otherZone) => otherZone._errorZone == this; | 850 bool inSameErrorZone(Zone otherZone) => otherZone._errorZone == this; |
849 | 851 |
850 operator [](Symbol key) => null; | 852 operator [](Symbol key) => null; |
851 | 853 |
| 854 dynamic runUnaryGuarded(f, arg) { |
| 855 try { |
| 856 return runUnary(f, arg); |
| 857 } catch (e, s) { |
| 858 return handleUncaughtError(e, s); |
| 859 } |
| 860 } |
| 861 |
852 // Methods that can be customized by the zone specification. | 862 // Methods that can be customized by the zone specification. |
853 | 863 |
854 dynamic handleUncaughtError(error, StackTrace stackTrace) => | 864 dynamic handleUncaughtError(error, StackTrace stackTrace) => |
855 _rootHandleUncaughtError(this, null, this, error, stackTrace); | 865 _rootHandleUncaughtError(this, null, this, error, stackTrace); |
856 | 866 |
857 Zone fork({ZoneSpecification specification, Map zoneValues}) => | 867 Zone fork({ZoneSpecification specification, Map zoneValues}) => |
858 _rootFork(this, null, this, specification, zoneValues); | 868 _rootFork(this, null, this, specification, zoneValues); |
859 | 869 |
860 dynamic run(f()) => _rootRun(this, null, this, f); | 870 dynamic run(f()) => _rootRun(this, null, this, f); |
861 | 871 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1011 ZoneSpecification specification = | 1021 ZoneSpecification specification = |
1012 new ZoneSpecification(handleUncaughtError: errorHandler, | 1022 new ZoneSpecification(handleUncaughtError: errorHandler, |
1013 scheduleMicrotask: asyncHandler); | 1023 scheduleMicrotask: asyncHandler); |
1014 Zone zone = Zone.current.fork(specification: specification); | 1024 Zone zone = Zone.current.fork(specification: specification); |
1015 if (onError != null) { | 1025 if (onError != null) { |
1016 return zone.runGuarded(body); | 1026 return zone.runGuarded(body); |
1017 } else { | 1027 } else { |
1018 return zone.run(body); | 1028 return zone.run(body); |
1019 } | 1029 } |
1020 } | 1030 } |
OLD | NEW |