aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/JSON.js14
-rw-r--r--test/JsonSpec.js8
2 files changed, 20 insertions, 2 deletions
diff --git a/src/JSON.js b/src/JSON.js
index 9ec95805..50f63dec 100644
--- a/src/JSON.js
+++ b/src/JSON.js
@@ -22,8 +22,18 @@ function fromJson(json) {
angular['toJson'] = toJson;
angular['fromJson'] = fromJson;
-function toJsonArray(buf, obj, pretty, stack){
- if (typeof obj == "object") {
+function toJsonArray(buf, obj, pretty, stack) {
+ if (isObject(obj)) {
+ if (obj === window) {
+ buf.push('WINDOW');
+ return;
+ }
+
+ if (obj === document) {
+ buf.push('DOCUMENT');
+ return;
+ }
+
if (includes(stack, obj)) {
buf.push("RECURSION");
return;
diff --git a/test/JsonSpec.js b/test/JsonSpec.js
index 33aae6ff..e6264293 100644
--- a/test/JsonSpec.js
+++ b/test/JsonSpec.js
@@ -92,6 +92,14 @@ describe('json', function(){
it('should not serialize undefined values', function() {
expect(angular.toJson({A:undefined})).toEqual('{}');
});
+
+ it('should not serialize $window object', function() {
+ expect(toJson(window)).toEqual('WINDOW');
+ });
+
+ it('should not serialize $document object', function() {
+ expect(toJson(document)).toEqual('DOCUMENT');
+ });
it('should parse floats', function() {
expect(fromJson("{value:2.55, name:'misko'}")).toEqual({value:2.55, name:'misko'});