diff options
| author | Greg Thornton | 2013-06-23 14:04:59 -0500 | 
|---|---|---|
| committer | Pawel Kozlowski | 2013-07-12 20:32:40 +0200 | 
| commit | 5a294c8646452d6e49339d145faeae4f31dcd0fc (patch) | |
| tree | 1f4599ce8591fb93e358e8036dccbe12267bb8d8 /src | |
| parent | ccda0f35090b1a6b3d5cd2288987ba77fcd1d4d7 (diff) | |
| download | angular.js-5a294c8646452d6e49339d145faeae4f31dcd0fc.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.js | 3 | 
1 files changed, 2 insertions, 1 deletions
| diff --git a/src/Angular.js b/src/Angular.js index 589929a4..746f1134 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -775,9 +775,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);  } | 
