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

Commit e80053d

Browse files
fix($rootScope): handle cyclic references in scopes when creating error messages
Use the new private function `stringify` to convert scope values to strings, since this can cope with cyclic references and other oddities. Closes #10085
1 parent fa12c3c commit e80053d

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/ng/rootScope.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -773,11 +773,11 @@ function $RootScopeProvider() {
773773
if (ttl < 5) {
774774
logIdx = 4 - ttl;
775775
if (!watchLog[logIdx]) watchLog[logIdx] = [];
776-
logMsg = (isFunction(watch.exp))
777-
? 'fn: ' + (watch.exp.name || watch.exp.toString())
778-
: watch.exp;
779-
logMsg += '; newVal: ' + toJson(value) + '; oldVal: ' + toJson(last);
780-
watchLog[logIdx].push(logMsg);
776+
watchLog[logIdx].push({
777+
msg: isFunction(watch.exp) ? 'fn: ' + (watch.exp.name || watch.exp.toString()) : watch.exp,
778+
newVal: value,
779+
oldVal: last
780+
});
781781
}
782782
} else if (watch === lastDirtyWatch) {
783783
// If the most recently dirty watcher is now clean, short circuit since the remaining watchers
@@ -810,7 +810,7 @@ function $RootScopeProvider() {
810810
throw $rootScopeMinErr('infdig',
811811
'{0} $digest() iterations reached. Aborting!\n' +
812812
'Watchers fired in the last 5 iterations: {1}',
813-
TTL, toJson(watchLog));
813+
TTL, watchLog);
814814
}
815815

816816
} while (dirty || asyncQueue.length);

test/ng/rootScopeSpec.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,11 @@ describe('Scope', function() {
298298
$rootScope.$digest();
299299
}).toThrowMinErr('$rootScope', 'infdig', '100 $digest() iterations reached. Aborting!\n' +
300300
'Watchers fired in the last 5 iterations: ' +
301-
'[["a; newVal: 96; oldVal: 95","b; newVal: 97; oldVal: 96"],' +
302-
'["a; newVal: 97; oldVal: 96","b; newVal: 98; oldVal: 97"],' +
303-
'["a; newVal: 98; oldVal: 97","b; newVal: 99; oldVal: 98"],' +
304-
'["a; newVal: 99; oldVal: 98","b; newVal: 100; oldVal: 99"],' +
305-
'["a; newVal: 100; oldVal: 99","b; newVal: 101; oldVal: 100"]]');
301+
'[[{"msg":"a","newVal":96,"oldVal":95},{"msg":"b","newVal":97,"oldVal":96}],' +
302+
'[{"msg":"a","newVal":97,"oldVal":96},{"msg":"b","newVal":98,"oldVal":97}],' +
303+
'[{"msg":"a","newVal":98,"oldVal":97},{"msg":"b","newVal":99,"oldVal":98}],' +
304+
'[{"msg":"a","newVal":99,"oldVal":98},{"msg":"b","newVal":100,"oldVal":99}],' +
305+
'[{"msg":"a","newVal":100,"oldVal":99},{"msg":"b","newVal":101,"oldVal":100}]]');
306306

307307
expect($rootScope.$$phase).toBeNull();
308308
});

0 commit comments

Comments
 (0)