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 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 } | 484 } |
485 | 485 |
486 class _ZoneDelegate implements ZoneDelegate { | 486 class _ZoneDelegate implements ZoneDelegate { |
487 final _Zone _delegationTarget; | 487 final _Zone _delegationTarget; |
488 | 488 |
489 _ZoneDelegate(this._delegationTarget); | 489 _ZoneDelegate(this._delegationTarget); |
490 | 490 |
491 dynamic handleUncaughtError(Zone zone, error, StackTrace stackTrace) { | 491 dynamic handleUncaughtError(Zone zone, error, StackTrace stackTrace) { |
492 _ZoneFunction implementation = _delegationTarget._handleUncaughtError; | 492 _ZoneFunction implementation = _delegationTarget._handleUncaughtError; |
493 _Zone implZone = implementation.zone; | 493 _Zone implZone = implementation.zone; |
494 return (implementation.function)( | 494 HandleUncaughtErrorHandler handler = implementation.function; |
| 495 return handler( |
495 implZone, _parentDelegate(implZone), zone, error, stackTrace); | 496 implZone, _parentDelegate(implZone), zone, error, stackTrace); |
496 } | 497 } |
497 | 498 |
498 dynamic run(Zone zone, f()) { | 499 dynamic run(Zone zone, f()) { |
499 _ZoneFunction implementation = _delegationTarget._run; | 500 _ZoneFunction implementation = _delegationTarget._run; |
500 _Zone implZone = implementation.zone; | 501 _Zone implZone = implementation.zone; |
501 return (implementation.function)( | 502 RunHandler handler = implementation.function; |
502 implZone, _parentDelegate(implZone), zone, f); | 503 return handler(implZone, _parentDelegate(implZone), zone, f); |
503 } | 504 } |
504 | 505 |
505 dynamic runUnary(Zone zone, f(arg), arg) { | 506 dynamic runUnary(Zone zone, f(arg), arg) { |
506 _ZoneFunction implementation = _delegationTarget._runUnary; | 507 _ZoneFunction implementation = _delegationTarget._runUnary; |
507 _Zone implZone = implementation.zone; | 508 _Zone implZone = implementation.zone; |
508 return (implementation.function)( | 509 RunUnaryHandler handler = implementation.function; |
| 510 return handler( |
509 implZone, _parentDelegate(implZone), zone, f, arg); | 511 implZone, _parentDelegate(implZone), zone, f, arg); |
510 } | 512 } |
511 | 513 |
512 dynamic runBinary(Zone zone, f(arg1, arg2), arg1, arg2) { | 514 dynamic runBinary(Zone zone, f(arg1, arg2), arg1, arg2) { |
513 _ZoneFunction implementation = _delegationTarget._runBinary; | 515 _ZoneFunction implementation = _delegationTarget._runBinary; |
514 _Zone implZone = implementation.zone; | 516 _Zone implZone = implementation.zone; |
515 return (implementation.function)( | 517 RunBinaryHandler handler = implementation.function; |
| 518 return handler( |
516 implZone, _parentDelegate(implZone), zone, f, arg1, arg2); | 519 implZone, _parentDelegate(implZone), zone, f, arg1, arg2); |
517 } | 520 } |
518 | 521 |
519 ZoneCallback registerCallback(Zone zone, f()) { | 522 ZoneCallback registerCallback(Zone zone, f()) { |
520 _ZoneFunction implementation = _delegationTarget._registerCallback; | 523 _ZoneFunction implementation = _delegationTarget._registerCallback; |
521 _Zone implZone = implementation.zone; | 524 _Zone implZone = implementation.zone; |
522 return (implementation.function)( | 525 RegisterCallbackHandler handler = implementation.function; |
523 implZone, _parentDelegate(implZone), zone, f); | 526 return handler(implZone, _parentDelegate(implZone), zone, f); |
524 } | 527 } |
525 | 528 |
526 ZoneUnaryCallback registerUnaryCallback(Zone zone, f(arg)) { | 529 ZoneUnaryCallback registerUnaryCallback(Zone zone, f(arg)) { |
527 _ZoneFunction implementation = _delegationTarget._registerUnaryCallback; | 530 _ZoneFunction implementation = _delegationTarget._registerUnaryCallback; |
528 _Zone implZone = implementation.zone; | 531 _Zone implZone = implementation.zone; |
529 return (implementation.function)( | 532 RegisterUnaryCallbackHandler handler = implementation.function; |
530 implZone, _parentDelegate(implZone), zone, f); | 533 return handler(implZone, _parentDelegate(implZone), zone, f); |
531 } | 534 } |
532 | 535 |
533 ZoneBinaryCallback registerBinaryCallback(Zone zone, f(arg1, arg2)) { | 536 ZoneBinaryCallback registerBinaryCallback(Zone zone, f(arg1, arg2)) { |
534 _ZoneFunction implementation = _delegationTarget._registerBinaryCallback; | 537 _ZoneFunction implementation = _delegationTarget._registerBinaryCallback; |
535 _Zone implZone = implementation.zone; | 538 _Zone implZone = implementation.zone; |
536 return (implementation.function)( | 539 RegisterBinaryCallbackHandler handler = implementation.function; |
537 implZone, _parentDelegate(implZone), zone, f); | 540 return handler(implZone, _parentDelegate(implZone), zone, f); |
538 } | 541 } |
539 | 542 |
540 AsyncError errorCallback(Zone zone, Object error, StackTrace stackTrace) { | 543 AsyncError errorCallback(Zone zone, Object error, StackTrace stackTrace) { |
541 _ZoneFunction implementation = _delegationTarget._errorCallback; | 544 _ZoneFunction implementation = _delegationTarget._errorCallback; |
542 _Zone implZone = implementation.zone; | 545 _Zone implZone = implementation.zone; |
543 if (identical(implZone, _ROOT_ZONE)) return null; | 546 if (identical(implZone, _ROOT_ZONE)) return null; |
544 return (implementation.function)(implZone, _parentDelegate(implZone), zone, | 547 ErrorCallbackHandler handler = implementation.function; |
545 error, stackTrace); | 548 return handler(implZone, _parentDelegate(implZone), zone, |
| 549 error, stackTrace); |
546 } | 550 } |
547 | 551 |
548 void scheduleMicrotask(Zone zone, f()) { | 552 void scheduleMicrotask(Zone zone, f()) { |
549 _ZoneFunction implementation = _delegationTarget._scheduleMicrotask; | 553 _ZoneFunction implementation = _delegationTarget._scheduleMicrotask; |
550 _Zone implZone = implementation.zone; | 554 _Zone implZone = implementation.zone; |
551 (implementation.function)( | 555 ScheduleMicrotaskHandler handler = implementation.function; |
552 implZone, _parentDelegate(implZone), zone, f); | 556 handler(implZone, _parentDelegate(implZone), zone, f); |
553 } | 557 } |
554 | 558 |
555 Timer createTimer(Zone zone, Duration duration, void f()) { | 559 Timer createTimer(Zone zone, Duration duration, void f()) { |
556 _ZoneFunction implementation = _delegationTarget._createTimer; | 560 _ZoneFunction implementation = _delegationTarget._createTimer; |
557 _Zone implZone = implementation.zone; | 561 _Zone implZone = implementation.zone; |
558 return (implementation.function)( | 562 CreateTimerHandler handler = implementation.function; |
559 implZone, _parentDelegate(implZone), zone, duration, f); | 563 return handler(implZone, _parentDelegate(implZone), zone, duration, f); |
560 } | 564 } |
561 | 565 |
562 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)) { | 566 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)) { |
563 _ZoneFunction implementation = _delegationTarget._createPeriodicTimer; | 567 _ZoneFunction implementation = _delegationTarget._createPeriodicTimer; |
564 _Zone implZone = implementation.zone; | 568 _Zone implZone = implementation.zone; |
565 return (implementation.function)( | 569 CreatePeriodicTimerHandler handler = implementation.function; |
566 implZone, _parentDelegate(implZone), zone, period, f); | 570 return handler(implZone, _parentDelegate(implZone), zone, period, f); |
567 } | 571 } |
568 | 572 |
569 void print(Zone zone, String line) { | 573 void print(Zone zone, String line) { |
570 _ZoneFunction implementation = _delegationTarget._print; | 574 _ZoneFunction implementation = _delegationTarget._print; |
571 _Zone implZone = implementation.zone; | 575 _Zone implZone = implementation.zone; |
572 (implementation.function)( | 576 PrintHandler handler = implementation.function; |
573 implZone, _parentDelegate(implZone), zone, line); | 577 handler(implZone, _parentDelegate(implZone), zone, line); |
574 } | 578 } |
575 | 579 |
576 Zone fork(Zone zone, ZoneSpecification specification, | 580 Zone fork(Zone zone, ZoneSpecification specification, |
577 Map zoneValues) { | 581 Map zoneValues) { |
578 _ZoneFunction implementation = _delegationTarget._fork; | 582 _ZoneFunction implementation = _delegationTarget._fork; |
579 _Zone implZone = implementation.zone; | 583 _Zone implZone = implementation.zone; |
580 return (implementation.function)( | 584 ForkHandler handler = implementation.function; |
| 585 return handler( |
581 implZone, _parentDelegate(implZone), zone, specification, zoneValues); | 586 implZone, _parentDelegate(implZone), zone, specification, zoneValues); |
582 } | 587 } |
583 } | 588 } |
584 | 589 |
585 | 590 |
586 /** | 591 /** |
587 * Base class for Zone implementations. | 592 * Base class for Zone implementations. |
588 */ | 593 */ |
589 abstract class _Zone implements Zone { | 594 abstract class _Zone implements Zone { |
590 const _Zone(); | 595 const _Zone(); |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 assert(this == _ROOT_ZONE); | 774 assert(this == _ROOT_ZONE); |
770 return null; | 775 return null; |
771 } | 776 } |
772 | 777 |
773 // Methods that can be customized by the zone specification. | 778 // Methods that can be customized by the zone specification. |
774 | 779 |
775 dynamic handleUncaughtError(error, StackTrace stackTrace) { | 780 dynamic handleUncaughtError(error, StackTrace stackTrace) { |
776 _ZoneFunction implementation = this._handleUncaughtError; | 781 _ZoneFunction implementation = this._handleUncaughtError; |
777 assert(implementation != null); | 782 assert(implementation != null); |
778 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | 783 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
779 return (implementation.function)( | 784 HandleUncaughtErrorHandler handler = implementation.function; |
| 785 return handler( |
780 implementation.zone, parentDelegate, this, error, stackTrace); | 786 implementation.zone, parentDelegate, this, error, stackTrace); |
781 } | 787 } |
782 | 788 |
783 Zone fork({ZoneSpecification specification, Map zoneValues}) { | 789 Zone fork({ZoneSpecification specification, Map zoneValues}) { |
784 _ZoneFunction implementation = this._fork; | 790 _ZoneFunction implementation = this._fork; |
785 assert(implementation != null); | 791 assert(implementation != null); |
786 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | 792 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
787 return (implementation.function)( | 793 ForkHandler handler = implementation.function; |
788 implementation.zone, parentDelegate, this, | 794 return handler(implementation.zone, parentDelegate, this, |
789 specification, zoneValues); | 795 specification, zoneValues); |
790 } | 796 } |
791 | 797 |
792 dynamic run(f()) { | 798 dynamic run(f()) { |
793 _ZoneFunction implementation = this._run; | 799 _ZoneFunction implementation = this._run; |
794 assert(implementation != null); | 800 assert(implementation != null); |
795 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | 801 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
796 return (implementation.function)( | 802 RunHandler handler = implementation.function; |
797 implementation.zone, parentDelegate, this, f); | 803 return handler(implementation.zone, parentDelegate, this, f); |
798 } | 804 } |
799 | 805 |
800 dynamic runUnary(f(arg), arg) { | 806 dynamic runUnary(f(arg), arg) { |
801 _ZoneFunction implementation = this._runUnary; | 807 _ZoneFunction implementation = this._runUnary; |
802 assert(implementation != null); | 808 assert(implementation != null); |
803 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | 809 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
804 return (implementation.function)( | 810 RunUnaryHandler handler = implementation.function; |
805 implementation.zone, parentDelegate, this, f, arg); | 811 return handler(implementation.zone, parentDelegate, this, f, arg); |
806 } | 812 } |
807 | 813 |
808 dynamic runBinary(f(arg1, arg2), arg1, arg2) { | 814 dynamic runBinary(f(arg1, arg2), arg1, arg2) { |
809 _ZoneFunction implementation = this._runBinary; | 815 _ZoneFunction implementation = this._runBinary; |
810 assert(implementation != null); | 816 assert(implementation != null); |
811 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | 817 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
812 return (implementation.function)( | 818 RunBinaryHandler handler = implementation.function; |
| 819 return handler( |
813 implementation.zone, parentDelegate, this, f, arg1, arg2); | 820 implementation.zone, parentDelegate, this, f, arg1, arg2); |
814 } | 821 } |
815 | 822 |
816 ZoneCallback registerCallback(f()) { | 823 ZoneCallback registerCallback(f()) { |
817 _ZoneFunction implementation = this._registerCallback; | 824 _ZoneFunction implementation = this._registerCallback; |
818 assert(implementation != null); | 825 assert(implementation != null); |
819 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | 826 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
820 return (implementation.function)( | 827 RegisterCallbackHandler handler = implementation.function; |
821 implementation.zone, parentDelegate, this, f); | 828 return handler(implementation.zone, parentDelegate, this, f); |
822 } | 829 } |
823 | 830 |
824 ZoneUnaryCallback registerUnaryCallback(f(arg)) { | 831 ZoneUnaryCallback registerUnaryCallback(f(arg)) { |
825 _ZoneFunction implementation = this._registerUnaryCallback; | 832 _ZoneFunction implementation = this._registerUnaryCallback; |
826 assert(implementation != null); | 833 assert(implementation != null); |
827 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | 834 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
828 return (implementation.function)( | 835 RegisterUnaryCallbackHandler handler = implementation.function; |
829 implementation.zone, parentDelegate, this, f); | 836 return handler(implementation.zone, parentDelegate, this, f); |
830 } | 837 } |
831 | 838 |
832 ZoneBinaryCallback registerBinaryCallback(f(arg1, arg2)) { | 839 ZoneBinaryCallback registerBinaryCallback(f(arg1, arg2)) { |
833 _ZoneFunction implementation = this._registerBinaryCallback; | 840 _ZoneFunction implementation = this._registerBinaryCallback; |
834 assert(implementation != null); | 841 assert(implementation != null); |
835 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | 842 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
836 return (implementation.function)( | 843 RegisterBinaryCallbackHandler handler = implementation.function; |
837 implementation.zone, parentDelegate, this, f); | 844 return handler(implementation.zone, parentDelegate, this, f); |
838 } | 845 } |
839 | 846 |
840 AsyncError errorCallback(Object error, StackTrace stackTrace) { | 847 AsyncError errorCallback(Object error, StackTrace stackTrace) { |
841 final _ZoneFunction implementation = this._errorCallback; | 848 final _ZoneFunction implementation = this._errorCallback; |
842 assert(implementation != null); | 849 assert(implementation != null); |
843 final Zone implementationZone = implementation.zone; | 850 final Zone implementationZone = implementation.zone; |
844 if (identical(implementationZone, _ROOT_ZONE)) return null; | 851 if (identical(implementationZone, _ROOT_ZONE)) return null; |
845 final ZoneDelegate parentDelegate = _parentDelegate(implementationZone); | 852 final ZoneDelegate parentDelegate = _parentDelegate(implementationZone); |
846 return (implementation.function)( | 853 ErrorCallbackHandler handler = implementation.function; |
| 854 return handler( |
847 implementationZone, parentDelegate, this, error, stackTrace); | 855 implementationZone, parentDelegate, this, error, stackTrace); |
848 } | 856 } |
849 | 857 |
850 void scheduleMicrotask(void f()) { | 858 void scheduleMicrotask(void f()) { |
851 _ZoneFunction implementation = this._scheduleMicrotask; | 859 _ZoneFunction implementation = this._scheduleMicrotask; |
852 assert(implementation != null); | 860 assert(implementation != null); |
853 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | 861 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
854 return (implementation.function)( | 862 ScheduleMicrotaskHandler handler = implementation.function; |
855 implementation.zone, parentDelegate, this, f); | 863 return handler(implementation.zone, parentDelegate, this, f); |
856 } | 864 } |
857 | 865 |
858 Timer createTimer(Duration duration, void f()) { | 866 Timer createTimer(Duration duration, void f()) { |
859 _ZoneFunction implementation = this._createTimer; | 867 _ZoneFunction implementation = this._createTimer; |
860 assert(implementation != null); | 868 assert(implementation != null); |
861 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | 869 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
862 return (implementation.function)( | 870 CreateTimerHandler handler = implementation.function; |
863 implementation.zone, parentDelegate, this, duration, f); | 871 return handler(implementation.zone, parentDelegate, this, duration, f); |
864 } | 872 } |
865 | 873 |
866 Timer createPeriodicTimer(Duration duration, void f(Timer timer)) { | 874 Timer createPeriodicTimer(Duration duration, void f(Timer timer)) { |
867 _ZoneFunction implementation = this._createPeriodicTimer; | 875 _ZoneFunction implementation = this._createPeriodicTimer; |
868 assert(implementation != null); | 876 assert(implementation != null); |
869 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | 877 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
870 return (implementation.function)( | 878 CreatePeriodicTimerHandler handler = implementation.function; |
| 879 return handler( |
871 implementation.zone, parentDelegate, this, duration, f); | 880 implementation.zone, parentDelegate, this, duration, f); |
872 } | 881 } |
873 | 882 |
874 void print(String line) { | 883 void print(String line) { |
875 _ZoneFunction implementation = this._print; | 884 _ZoneFunction implementation = this._print; |
876 assert(implementation != null); | 885 assert(implementation != null); |
877 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | 886 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
878 return (implementation.function)( | 887 PrintHandler handler = implementation.function; |
879 implementation.zone, parentDelegate, this, line); | 888 return handler(implementation.zone, parentDelegate, this, line); |
880 } | 889 } |
881 } | 890 } |
882 | 891 |
883 void _rootHandleUncaughtError( | 892 void _rootHandleUncaughtError( |
884 Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace) { | 893 Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace) { |
885 _schedulePriorityAsyncCallback(() { | 894 _schedulePriorityAsyncCallback(() { |
886 throw new _UncaughtAsyncError(error, stackTrace); | 895 throw new _UncaughtAsyncError(error, stackTrace); |
887 }); | 896 }); |
888 } | 897 } |
889 | 898 |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1246 handleUncaughtError: errorHandler); | 1255 handleUncaughtError: errorHandler); |
1247 } | 1256 } |
1248 Zone zone = Zone.current.fork(specification: zoneSpecification, | 1257 Zone zone = Zone.current.fork(specification: zoneSpecification, |
1249 zoneValues: zoneValues); | 1258 zoneValues: zoneValues); |
1250 if (onError != null) { | 1259 if (onError != null) { |
1251 return zone.runGuarded(body); | 1260 return zone.runGuarded(body); |
1252 } else { | 1261 } else { |
1253 return zone.run(body); | 1262 return zone.run(body); |
1254 } | 1263 } |
1255 } | 1264 } |
OLD | NEW |