Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
fix(scope): log firing expressions in the watchLog
Browse files Browse the repository at this point in the history
Closes #258

Conflicts:
	lib/core/scope.dart
  • Loading branch information
pavelgj authored and mhevery committed Dec 14, 2013
1 parent 9ebba43 commit b016662
Show file tree
Hide file tree
Showing 2 changed files with 25 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 @@ -433,6 +433,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 @@ -448,6 +453,9 @@ class Scope implements Map {
var value = watch.get(current);
var last = watch.last;
if (!_identical(value, last)) {
if (_ttlLeft < 3) {
firedExpressions.add(watch.exp == null ? '[unknown]' : watch.exp);
}
lastDirtyWatch = watch;
lastLoopLastDirtyWatch = null;
watch.last = value;
Expand Down Expand Up @@ -488,7 +496,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 ${_ttl - 2} iterations: ${_toJson(watchLog)}';
}
} while (lastDirtyWatch != null || innerAsyncQueue.length > 0);
_perf.counters['ng.scope.watchers'] = watcherCount;
Expand Down
16 changes: 16 additions & 0 deletions test/core/scope_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,22 @@ 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 b016662

Please sign in to comment.