Skip to content

Commit

Permalink
fix(scope): log firing expressions in the watchLog
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelgj committed Dec 14, 2013
1 parent 6c6151c commit c60e11c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/core/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,11 @@ class Scope implements Map {

watcherCount = 0;
scopeCount = 0;
var firedExpressions;
if (_ttl - _ttlLeft > 2) {
firedExpressions = <String>[];
watchLog.add(firedExpressions);
}
assert((timerId = _perf.startTimer('ng.dirty_check', _ttl-_ttlLeft)) != false);
digestLoop:
do { // "traverse the scopes" loop
Expand All @@ -456,6 +461,9 @@ class Scope implements Map {
var value = watch.get(current);
var last = watch.last;
if (!_identical(value, last)) {
if (_ttl - _ttlLeft > 2) {
firedExpressions.add(watch.exp == null ? '[closure]' : watch.exp);
}
lastDirtyWatch = watch;
lastLoopLastDirtyWatch = null;
watch.last = value;
Expand Down Expand Up @@ -497,7 +505,7 @@ class Scope implements Map {
assert(_perf.stopTimer(timerId) != false);
if(lastDirtyWatch != null && (_ttlLeft--) == 0) {
throw '$_ttl \$digest() iterations reached. Aborting!\n' +
'Watchers fired in the last 5 iterations: ${_toJson(watchLog)}';
'Watchers fired in the last 3 iterations: ${_toJson(watchLog)}';
}
} while (lastDirtyWatch != null || innerAsyncQueue.length > 0);
_perf.counters['ng.scope.watchers'] = watcherCount;
Expand Down
14 changes: 14 additions & 0 deletions test/core/scope_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,20 @@ main() {
}));


it(r'should prevent infinite digest and should log firing expressions', inject((Scope $rootScope) {
$rootScope['a'] = 0;
$rootScope['b'] = 0;
$rootScope.$watch('a = a + 1');
$rootScope.$watch('b = b + 1');

expect(() {
$rootScope.$digest();
}).toThrow('Watchers fired in the last 3 iterations: ['
'["a = a + 1","b = b + 1"],["a = a + 1","b = b + 1"],'
'["a = a + 1","b = b + 1"]]');
}));


it(r'should always call the watchr with newVal and oldVal equal on the first run',
inject((Scope $rootScope) {
var log = [];
Expand Down

0 comments on commit c60e11c

Please sign in to comment.