scope($digest): add new&old val to the infinite $digest log

This commit is contained in:
Igor Minar 2011-11-29 16:54:25 -05:00
parent 188bdf7768
commit b00da987a9
2 changed files with 14 additions and 8 deletions

View file

@ -323,7 +323,8 @@ function $RootScopeProvider(){
length,
dirty, ttl = 100,
next, current, target = this,
watchLog = [];
watchLog = [],
logIdx, logMsg;
if (target.$$phase) {
throw Error(target.$$phase + ' already in progress');
@ -355,12 +356,13 @@ function $RootScopeProvider(){
watch.last = copy(value);
watch.fn(current, value, ((last === initWatchVal) ? value : last));
if (ttl < 5) {
if (!watchLog[4-ttl]) watchLog[4-ttl] = [];
if (isFunction(watch.exp)) {
watchLog[4-ttl].push('fn: ' + (watch.exp.name || watch.exp.toString()));
} else {
watchLog[4-ttl].push(watch.exp);
}
logIdx = 4-ttl;
if (!watchLog[logIdx]) watchLog[logIdx] = [];
logMsg = (isFunction(watch.exp))
? 'fn: ' + (watch.exp.name || watch.exp.toString())
: watch.exp;
logMsg += '; newVal: ' + toJson(value) + '; oldVal: ' + toJson(last);
watchLog[logIdx].push(logMsg);
}
}
} catch (e) {

View file

@ -216,7 +216,11 @@ describe('Scope', function() {
$rootScope.$digest();
}).toThrow('100 $digest() iterations reached. Aborting!\n'+
'Watchers fired in the last 5 iterations: ' +
'[["a","b"],["a","b"],["a","b"],["a","b"],["a","b"]]');
'[["a; newVal: 96; oldVal: 95","b; newVal: 97; oldVal: 96"],' +
'["a; newVal: 97; oldVal: 96","b; newVal: 98; oldVal: 97"],' +
'["a; newVal: 98; oldVal: 97","b; newVal: 99; oldVal: 98"],' +
'["a; newVal: 99; oldVal: 98","b; newVal: 100; oldVal: 99"],' +
'["a; newVal: 100; oldVal: 99","b; newVal: 101; oldVal: 100"]]');
}));