aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Angular.js3
-rw-r--r--test/AngularSpec.js4
2 files changed, 6 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);
}
diff --git a/test/AngularSpec.js b/test/AngularSpec.js
index bf952249..da70aef7 100644
--- a/test/AngularSpec.js
+++ b/test/AngularSpec.js
@@ -909,6 +909,10 @@ describe('angular', function() {
it('should not serialize scope instances', inject(function($rootScope) {
expect(toJson({key: $rootScope})).toEqual('{"key":"$SCOPE"}');
}));
+
+ it('should serialize undefined as undefined', function() {
+ expect(toJson(undefined)).toEqual(undefined);
+ });
});
});