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

Commit

Permalink
fix($rootScope): clear phase if an exception is raised by a watcher
Browse files Browse the repository at this point in the history
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
  • Loading branch information
thomasguillory authored and jeffbcross committed Dec 4, 2013
1 parent 2d0f6cc commit d3c486d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ng/rootScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ function $RootScopeProvider(){
asyncTask = asyncQueue.shift();
asyncTask.scope.$eval(asyncTask.expression);
} catch (e) {
clearPhase();
$exceptionHandler(e);
}
}
Expand Down Expand Up @@ -594,6 +595,7 @@ function $RootScopeProvider(){
}
}
} catch (e) {
clearPhase();
$exceptionHandler(e);
}
}
Expand Down
9 changes: 9 additions & 0 deletions test/ng/rootScopeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ describe('Scope', function() {
});
});

it('should clear phase if an exception interrupt $digest cycle', function() {
inject(function($rootScope) {
$rootScope.$watch('a', function() {throw new Error('abc');});
$rootScope.a = 1;
try { $rootScope.$digest(); } catch(e) { }
expect($rootScope.$$phase).toBeNull();
});
});


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

0 comments on commit d3c486d

Please sign in to comment.