@@ -372,7 +372,7 @@ function $RootScopeProvider(){
372
372
watchLog = [ ] ,
373
373
logIdx , logMsg ;
374
374
375
- flagPhase ( target , '$digest' ) ;
375
+ beginPhase ( '$digest' ) ;
376
376
377
377
do {
378
378
dirty = false ;
@@ -429,12 +429,13 @@ function $RootScopeProvider(){
429
429
} while ( ( current = next ) ) ;
430
430
431
431
if ( dirty && ! ( ttl -- ) ) {
432
+ clearPhase ( ) ;
432
433
throw Error ( TTL + ' $digest() iterations reached. Aborting!\n' +
433
434
'Watchers fired in the last 5 iterations: ' + toJson ( watchLog ) ) ;
434
435
}
435
436
} while ( dirty || asyncQueue . length ) ;
436
437
437
- this . $root . $$phase = null ;
438
+ clearPhase ( ) ;
438
439
} ,
439
440
440
441
@@ -469,7 +470,7 @@ function $RootScopeProvider(){
469
470
* perform any necessary cleanup.
470
471
*/
471
472
$destroy : function ( ) {
472
- if ( this . $root == this ) return ; // we can't remove the root node;
473
+ if ( $rootScope == this ) return ; // we can't remove the root node;
473
474
var parent = this . $parent ;
474
475
475
476
this . $broadcast ( '$destroy' ) ;
@@ -586,13 +587,18 @@ function $RootScopeProvider(){
586
587
*/
587
588
$apply : function ( expr ) {
588
589
try {
589
- flagPhase ( this , '$apply' ) ;
590
+ beginPhase ( '$apply' ) ;
590
591
return this . $eval ( expr ) ;
591
592
} catch ( e ) {
592
593
$exceptionHandler ( e ) ;
593
594
} finally {
594
- this . $root . $$phase = null ;
595
- this . $root . $digest ( ) ;
595
+ clearPhase ( ) ;
596
+ try {
597
+ $rootScope . $digest ( ) ;
598
+ } catch ( e ) {
599
+ $exceptionHandler ( e ) ;
600
+ throw e ;
601
+ }
596
602
}
597
603
} ,
598
604
@@ -754,18 +760,22 @@ function $RootScopeProvider(){
754
760
}
755
761
} ;
756
762
763
+ var $rootScope = new Scope ( ) ;
764
+
765
+ return $rootScope ;
757
766
758
- function flagPhase ( scope , phase ) {
759
- var root = scope . $root ;
760
767
761
- if ( root . $$phase ) {
762
- throw Error ( root . $$phase + ' already in progress' ) ;
768
+ function beginPhase ( phase ) {
769
+ if ( $rootScope . $$phase ) {
770
+ throw Error ( $rootScope . $$phase + ' already in progress' ) ;
763
771
}
764
772
765
- root . $$phase = phase ;
773
+ $rootScope . $$phase = phase ;
766
774
}
767
775
768
- return new Scope ( ) ;
776
+ function clearPhase ( ) {
777
+ $rootScope . $$phase = null ;
778
+ }
769
779
770
780
function compileToFn ( exp , name ) {
771
781
var fn = $parse ( exp ) ;
0 commit comments