@@ -3,6 +3,13 @@ part of angular.core_internal;
3
3
typedef EvalFunction0 ();
4
4
typedef EvalFunction1 (context);
5
5
6
+ final UserTag APPLY_USER_TAG = new UserTag ('Apply' );
7
+ final UserTag FLUSH_TAG = new UserTag ('NgFlush' );
8
+ final UserTag RUN_ASYNC_TAG = new UserTag ('NgRunAsync' );
9
+ final UserTag DOM_READ_TAG = new UserTag ('NgDomRead' );
10
+ final UserTag DOM_WRITE_TAG = new UserTag ('NgDomWrite' );
11
+ final UserTag ASSERT_TAG = new UserTag ('NgAssert' );
12
+
6
13
/**
7
14
* Injected into the listener function within [Scope.on] to provide
8
15
* event-specific details to the scope listener.
@@ -282,13 +289,15 @@ class Scope {
282
289
}
283
290
284
291
dynamic apply ([expression, Map locals]) {
292
+ var previous = APPLY_USER_TAG .makeCurrent ();
285
293
_assertInternalStateConsistency ();
286
294
rootScope._transitionState (null , RootScope .STATE_APPLY );
287
295
try {
288
296
return eval (expression, locals);
289
297
} catch (e, s) {
290
298
rootScope._exceptionHandler (e, s);
291
299
} finally {
300
+ previous.makeCurrent ();
292
301
rootScope.._transitionState (RootScope .STATE_APPLY , null )
293
302
..digest ()
294
303
..flush ();
@@ -567,6 +576,8 @@ class RootScope extends Scope {
567
576
568
577
String _state;
569
578
579
+ final List <UserTag > _digestTags = [];
580
+
570
581
/**
571
582
*
572
583
* While processing data bindings, Angular passes through multiple states. When testing or
@@ -616,23 +627,29 @@ class RootScope extends Scope {
616
627
*/
617
628
String get state => _state;
618
629
619
- RootScope (Object context, Parser parser, ASTParser astParser, FieldGetterFactory fieldGetterFactory,
620
- FormatterMap formatters, this ._exceptionHandler, this ._ttl , this ._zone ,
621
- ScopeStats _scopeStats)
630
+ RootScope (Object context, Parser parser, ASTParser astParser,
631
+ FieldGetterFactory fieldGetterFactory, FormatterMap formatters , this ._exceptionHandler ,
632
+ ScopeDigestTTL ttl, this ._zone, ScopeStats _scopeStats)
622
633
: _scopeStats = _scopeStats,
634
+ _ttl = ttl,
623
635
_parser = parser,
624
636
_astParser = astParser,
625
637
super (context, null , null ,
626
638
new RootWatchGroup (fieldGetterFactory,
627
- new DirtyCheckingChangeDetector (fieldGetterFactory), context),
639
+ new DirtyCheckingChangeDetector (fieldGetterFactory), context, profile: true ,
640
+ ttl: ttl.ttl),
628
641
new RootWatchGroup (fieldGetterFactory,
629
- new DirtyCheckingChangeDetector (fieldGetterFactory), context),
642
+ new DirtyCheckingChangeDetector (fieldGetterFactory), context, profile: true ,
643
+ ttl: ttl.ttl),
630
644
'' ,
631
645
_scopeStats)
632
646
{
633
647
_zone.onTurnDone = apply;
634
648
_zone.onError = (e, s, ls) => _exceptionHandler (e, s);
635
649
_zone.onScheduleMicrotask = runAsync;
650
+ for (num i = 0 ; i <= _ttl.ttl; i++ ) {
651
+ _digestTags.add (new UserTag ('NgDigest${i }' ));
652
+ }
636
653
}
637
654
638
655
RootScope get rootScope => this ;
@@ -656,18 +673,21 @@ class RootScope extends Scope {
656
673
* [ScopeDigestTTL] .
657
674
*/
658
675
void digest () {
676
+ int digestTTL = _ttl.ttl;
659
677
_transitionState (null , STATE_DIGEST );
660
678
try {
661
679
var rootWatchGroup = _readWriteGroup as RootWatchGroup ;
662
680
663
- int digestTTL = _ttl.ttl;
681
+
664
682
const int LOG_COUNT = 3 ;
665
683
List log;
666
684
List digestLog;
667
685
var count;
668
686
ChangeLog changeLog;
669
687
_scopeStats.digestStart ();
670
688
do {
689
+ var sequenceNo = _ttl.ttl - digestTTL;
690
+ var previousTag = _digestTags[sequenceNo].makeCurrent ();
671
691
672
692
int asyncCount = _runAsyncFns ();
673
693
@@ -677,7 +697,8 @@ class RootScope extends Scope {
677
697
changeLog: changeLog,
678
698
fieldStopwatch: _scopeStats.fieldStopwatch,
679
699
evalStopwatch: _scopeStats.evalStopwatch,
680
- processStopwatch: _scopeStats.processStopwatch);
700
+ processStopwatch: _scopeStats.processStopwatch,
701
+ sequenceNumber: sequenceNo);
681
702
682
703
if (digestTTL <= LOG_COUNT ) {
683
704
if (changeLog == null ) {
@@ -690,10 +711,13 @@ class RootScope extends Scope {
690
711
}
691
712
}
692
713
if (digestTTL == 0 ) {
714
+ if (previousTag != null ) previousTag.makeCurrent ();
693
715
throw 'Model did not stabilize in ${_ttl .ttl } digests. '
694
- 'Last $LOG_COUNT iterations:\n ${log .join ('\n ' )}' ;
716
+ 'Last $LOG_COUNT iterations:\n ${log .join ('\n ' )}' ;
695
717
}
718
+
696
719
_scopeStats.digestLoop (count);
720
+ previousTag.makeCurrent ();
697
721
} while (count > 0 || _runAsyncHead != null );
698
722
} finally {
699
723
_scopeStats.digestEnd ();
@@ -702,6 +726,7 @@ class RootScope extends Scope {
702
726
}
703
727
704
728
void flush () {
729
+ var previousTag = FLUSH_TAG .makeCurrent ();
705
730
_stats.flushStart ();
706
731
_transitionState (null , STATE_FLUSH );
707
732
RootWatchGroup readOnlyGroup = this ._readOnlyGroup as RootWatchGroup ;
@@ -724,7 +749,8 @@ class RootScope extends Scope {
724
749
readOnlyGroup.detectChanges (exceptionHandler: _exceptionHandler,
725
750
fieldStopwatch: _scopeStats.fieldStopwatch,
726
751
evalStopwatch: _scopeStats.evalStopwatch,
727
- processStopwatch: _scopeStats.processStopwatch);
752
+ processStopwatch: _scopeStats.processStopwatch,
753
+ sequenceNumber: _ttl.ttl);
728
754
}
729
755
if (_domReadHead != null ) _stats.domReadStart ();
730
756
while (_domReadHead != null ) {
@@ -741,30 +767,35 @@ class RootScope extends Scope {
741
767
} while (_domWriteHead != null || _domReadHead != null || _runAsyncHead != null );
742
768
_stats.flushEnd ();
743
769
assert ((() {
770
+ var previousTag = ASSERT_TAG .makeCurrent ();
744
771
_stats.flushAssertStart ();
745
772
var digestLog = [];
746
773
var flushLog = [];
747
774
(_readWriteGroup as RootWatchGroup ).detectChanges (
748
775
changeLog: (s, c, p) => digestLog.add ('$s : $c <= $p ' ),
749
776
fieldStopwatch: _scopeStats.fieldStopwatch,
750
777
evalStopwatch: _scopeStats.evalStopwatch,
751
- processStopwatch: _scopeStats.processStopwatch);
778
+ processStopwatch: _scopeStats.processStopwatch,
779
+ sequenceNumber: _ttl.ttl + 1 );
752
780
(_readOnlyGroup as RootWatchGroup ).detectChanges (
753
781
changeLog: (s, c, p) => flushLog.add ('$s : $c <= $p ' ),
754
782
fieldStopwatch: _scopeStats.fieldStopwatch,
755
783
evalStopwatch: _scopeStats.evalStopwatch,
756
- processStopwatch: _scopeStats.processStopwatch);
784
+ processStopwatch: _scopeStats.processStopwatch,
785
+ sequenceNumber: _ttl.ttl + 1 );
757
786
if (digestLog.isNotEmpty || flushLog.isNotEmpty) {
758
787
throw 'Observer reaction functions should not change model. \n '
759
788
'These watch changes were detected: ${digestLog .join ('; ' )}\n '
760
789
'These observe changes were detected: ${flushLog .join ('; ' )}' ;
761
790
}
762
791
_stats.flushAssertEnd ();
792
+ previousTag.makeCurrent ();
763
793
return true ;
764
794
})());
765
795
} finally {
766
796
_stats.cycleEnd ();
767
797
_transitionState (STATE_FLUSH , null );
798
+ previousTag.makeCurrent ();
768
799
}
769
800
}
770
801
@@ -773,12 +804,14 @@ class RootScope extends Scope {
773
804
if (_state == STATE_FLUSH_ASSERT ) {
774
805
throw "Scheduling microtasks not allowed in $state state." ;
775
806
}
807
+ var previousTag = RUN_ASYNC_TAG .makeCurrent ();
776
808
var chain = new _FunctionChain (fn);
777
809
if (_runAsyncHead == null ) {
778
810
_runAsyncHead = _runAsyncTail = chain;
779
811
} else {
780
812
_runAsyncTail = _runAsyncTail._next = chain;
781
813
}
814
+ previousTag.makeCurrent ();
782
815
}
783
816
784
817
_runAsyncFns () {
@@ -797,21 +830,25 @@ class RootScope extends Scope {
797
830
}
798
831
799
832
void domWrite (fn ()) {
833
+ var previousTag = DOM_WRITE_TAG .makeCurrent ();
800
834
var chain = new _FunctionChain (fn);
801
835
if (_domWriteHead == null ) {
802
836
_domWriteHead = _domWriteTail = chain;
803
837
} else {
804
838
_domWriteTail = _domWriteTail._next = chain;
805
839
}
840
+ previousTag.makeCurrent ();
806
841
}
807
842
808
843
void domRead (fn ()) {
844
+ var previousTag = DOM_READ_TAG .makeCurrent ();
809
845
var chain = new _FunctionChain (fn);
810
846
if (_domReadHead == null ) {
811
847
_domReadHead = _domReadTail = chain;
812
848
} else {
813
849
_domReadTail = _domReadTail._next = chain;
814
850
}
851
+ previousTag.makeCurrent ();
815
852
}
816
853
817
854
void destroy () {}
0 commit comments