angular/angular.js — pull request #10085 by petebacondarwin (2014-11-17 01:32:12+00:00)
Title: fix(minErr/ngRepeat/$rootScope): serialization of error objects

This is my preferred solution to #9838.
`toJson` should throw errors on cyclic object references. JSON is not really designed to handle this out of the box and we should not be hiding the error from the developer.
Adding a hidden parameter is just making this method convoluted and slowing it down.

Instead we should consider that for error messages, we do not high fidelity serialization of objects but instead a readable string that is useful for debugging. Returning `undefined` for broken JSON stringification is not helpful.

This fix provides a new function `stringify` which is available within the `angular.js` file and also within the `angular-loader.js` file. This function is then used inside `minErr` and `$rootScope` to provide nice string forms of objects.

Places that were using `toJson` to create error messages (i.e. `ngRepeat` and `$rootScope`) no either pass the object directly to `minErr` or they use the `stringify` method directly.

This solution ensures that we don't confuse the point of `toJson` - it is not a generic stringification tool, it is designed for converting to and from valid JSON. The new method `stringify` also provides us with a single future improvement point if we wished to make the stringification of objects to strings more comprehensive.