Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit d3c486d

Browse files
Thomas Guilloryjeffbcross
Thomas Guillory
authored andcommitted
fix($rootScope): clear phase if an exception is raised by a watcher
Add calls to clearPhase() when an exception is raised by a watcher while a digest cycle, in order to not be stuck on `$digest` scope phase
1 parent 2d0f6cc commit d3c486d

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/ng/rootScope.js

+2
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ function $RootScopeProvider(){
562562
asyncTask = asyncQueue.shift();
563563
asyncTask.scope.$eval(asyncTask.expression);
564564
} catch (e) {
565+
clearPhase();
565566
$exceptionHandler(e);
566567
}
567568
}
@@ -594,6 +595,7 @@ function $RootScopeProvider(){
594595
}
595596
}
596597
} catch (e) {
598+
clearPhase();
597599
$exceptionHandler(e);
598600
}
599601
}

test/ng/rootScopeSpec.js

+9
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ describe('Scope', function() {
127127
});
128128
});
129129

130+
it('should clear phase if an exception interrupt $digest cycle', function() {
131+
inject(function($rootScope) {
132+
$rootScope.$watch('a', function() {throw new Error('abc');});
133+
$rootScope.a = 1;
134+
try { $rootScope.$digest(); } catch(e) { }
135+
expect($rootScope.$$phase).toBeNull();
136+
});
137+
});
138+
130139

131140
it('should fire watches in order of addition', inject(function($rootScope) {
132141
// this is not an external guarantee, just our own sanity

0 commit comments

Comments
 (0)