aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGreg Thornton2013-06-23 14:04:59 -0500
committerPawel Kozlowski2013-07-12 20:49:50 +0200
commit332a3c7984229a7e3a9a8a277f92942299616fdb (patch)
tree518ca551b70d579255d6126c2a1bfb1916992684 /src
parentfcd761b9d7c3c91673efce9b980ac5e7973adf3d (diff)
downloadangular.js-332a3c7984229a7e3a9a8a277f92942299616fdb.tar.bz2
feat(Angular.js): skip JSON.stringify for undefined
Return early in `angular.toJson` if the object to be stringified is `undefined`. IE8 stringifies `undefined` to `'undefined'` whereas other browsers return `undefined`. This normalizes behavior and passes currently broken unit tests in IE8.
Diffstat (limited to 'src')
-rw-r--r--src/Angular.js3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/Angular.js b/src/Angular.js
index ec3be068..01b37969 100644
--- a/src/Angular.js
+++ b/src/Angular.js
@@ -751,9 +751,10 @@ function toJsonReplacer(key, value) {
*
* @param {Object|Array|Date|string|number} obj Input to be serialized into JSON.
* @param {boolean=} pretty If set to true, the JSON output will contain newlines and whitespace.
- * @returns {string} Jsonified string representing `obj`.
+ * @returns {string|undefined} Jsonified string representing `obj`.
*/
function toJson(obj, pretty) {
+ if (typeof obj === 'undefined') return undefined;
return JSON.stringify(obj, toJsonReplacer, pretty ? ' ' : null);
}