| 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 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 */ | 378 */ |
| 379 void print(String line); | 379 void print(String line); |
| 380 | 380 |
| 381 /** | 381 /** |
| 382 * The error zone is the one that is responsible for dealing with uncaught | 382 * The error zone is the one that is responsible for dealing with uncaught |
| 383 * errors. Errors are not allowed to cross zones with different error-zones. | 383 * errors. Errors are not allowed to cross zones with different error-zones. |
| 384 */ | 384 */ |
| 385 Zone get _errorZone; | 385 Zone get _errorZone; |
| 386 | 386 |
| 387 /** | 387 /** |
| 388 * Call to enter the Zone. |
| 389 * |
| 390 * The previous current zone is returned. |
| 391 */ |
| 392 static Zone _enter(Zone zone) { |
| 393 assert(zone != null); |
| 394 assert(!identical(zone, _current)); |
| 395 Zone previous = _current; |
| 396 _current = zone; |
| 397 return previous; |
| 398 } |
| 399 |
| 400 /** |
| 401 * Call to leave the Zone. |
| 402 * |
| 403 * The previous Zone must be provided as `previous`. |
| 404 */ |
| 405 static void _leave(Zone previous) { |
| 406 assert(previous != null); |
| 407 Zone._current = previous; |
| 408 } |
| 409 |
| 410 /** |
| 388 * Retrieves the zone-value associated with [key]. | 411 * Retrieves the zone-value associated with [key]. |
| 389 * | 412 * |
| 390 * If this zone does not contain the value looks up the same key in the | 413 * If this zone does not contain the value looks up the same key in the |
| 391 * parent zone. If the [key] is not found returns `null`. | 414 * parent zone. If the [key] is not found returns `null`. |
| 392 */ | 415 */ |
| 393 operator[](Symbol key); | 416 operator[](Symbol key); |
| 394 } | 417 } |
| 395 | 418 |
| 396 class _ZoneDelegate implements ZoneDelegate { | 419 class _ZoneDelegate implements ZoneDelegate { |
| 397 final _BaseZone _degelationTarget; | 420 final _BaseZone _degelationTarget; |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 print("Stack Trace: \n$trace\n"); | 698 print("Stack Trace: \n$trace\n"); |
| 676 } | 699 } |
| 677 throw error; | 700 throw error; |
| 678 }); | 701 }); |
| 679 }); | 702 }); |
| 680 } | 703 } |
| 681 | 704 |
| 682 dynamic _rootRun(Zone self, ZoneDelegate parent, Zone zone, f()) { | 705 dynamic _rootRun(Zone self, ZoneDelegate parent, Zone zone, f()) { |
| 683 if (Zone._current == zone) return f(); | 706 if (Zone._current == zone) return f(); |
| 684 | 707 |
| 685 Zone old = Zone._current; | 708 Zone old = Zone._enter(zone); |
| 686 try { | 709 try { |
| 687 Zone._current = zone; | |
| 688 return f(); | 710 return f(); |
| 689 } finally { | 711 } finally { |
| 690 Zone._current = old; | 712 Zone._leave(old); |
| 691 } | 713 } |
| 692 } | 714 } |
| 693 | 715 |
| 694 dynamic _rootRunUnary(Zone self, ZoneDelegate parent, Zone zone, f(arg), arg) { | 716 dynamic _rootRunUnary(Zone self, ZoneDelegate parent, Zone zone, f(arg), arg) { |
| 695 if (Zone._current == zone) return f(arg); | 717 if (Zone._current == zone) return f(arg); |
| 696 | 718 |
| 697 Zone old = Zone._current; | 719 Zone old = Zone._enter(zone); |
| 698 try { | 720 try { |
| 699 Zone._current = zone; | |
| 700 return f(arg); | 721 return f(arg); |
| 701 } finally { | 722 } finally { |
| 702 Zone._current = old; | 723 Zone._leave(old); |
| 703 } | 724 } |
| 704 } | 725 } |
| 705 | 726 |
| 706 dynamic _rootRunBinary(Zone self, ZoneDelegate parent, Zone zone, | 727 dynamic _rootRunBinary(Zone self, ZoneDelegate parent, Zone zone, |
| 707 f(arg1, arg2), arg1, arg2) { | 728 f(arg1, arg2), arg1, arg2) { |
| 708 if (Zone._current == zone) return f(arg1, arg2); | 729 if (Zone._current == zone) return f(arg1, arg2); |
| 709 | 730 |
| 710 Zone old = Zone._current; | 731 Zone old = Zone._enter(zone); |
| 711 try { | 732 try { |
| 712 Zone._current = zone; | |
| 713 return f(arg1, arg2); | 733 return f(arg1, arg2); |
| 714 } finally { | 734 } finally { |
| 715 Zone._current = old; | 735 Zone._leave(old); |
| 716 } | 736 } |
| 717 } | 737 } |
| 718 | 738 |
| 719 ZoneCallback _rootRegisterCallback( | 739 ZoneCallback _rootRegisterCallback( |
| 720 Zone self, ZoneDelegate parent, Zone zone, f()) { | 740 Zone self, ZoneDelegate parent, Zone zone, f()) { |
| 721 return f; | 741 return f; |
| 722 } | 742 } |
| 723 | 743 |
| 724 ZoneUnaryCallback _rootRegisterUnaryCallback( | 744 ZoneUnaryCallback _rootRegisterUnaryCallback( |
| 725 Zone self, ZoneDelegate parent, Zone zone, f(arg)) { | 745 Zone self, ZoneDelegate parent, Zone zone, f(arg)) { |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 handleUncaughtError: errorHandler); | 937 handleUncaughtError: errorHandler); |
| 918 } | 938 } |
| 919 Zone zone = Zone.current.fork(specification: zoneSpecification, | 939 Zone zone = Zone.current.fork(specification: zoneSpecification, |
| 920 zoneValues: zoneValues); | 940 zoneValues: zoneValues); |
| 921 if (onError != null) { | 941 if (onError != null) { |
| 922 return zone.runGuarded(body); | 942 return zone.runGuarded(body); |
| 923 } else { | 943 } else { |
| 924 return zone.run(body); | 944 return zone.run(body); |
| 925 } | 945 } |
| 926 } | 946 } |
| OLD | NEW |