diff options
| author | Misko Hevery | 2010-01-23 15:54:58 -0800 |
|---|---|---|
| committer | Misko Hevery | 2010-01-23 15:54:58 -0800 |
| commit | 4460328bc1173f5d97fb4ff54edc041968486fce (patch) | |
| tree | 40e18a175f7f1ae104aa56347fe5038526374ed8 /src/JSON.js | |
| parent | e41ee88ef85986dcd0fea23fefcc57d89cee5c0b (diff) | |
| download | angular.js-4460328bc1173f5d97fb4ff54edc041968486fce.tar.bz2 | |
lots of cleanup to get it ready for OS
Diffstat (limited to 'src/JSON.js')
| -rw-r--r-- | src/JSON.js | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/JSON.js b/src/JSON.js index 0c842865..98dfddd2 100644 --- a/src/JSON.js +++ b/src/JSON.js @@ -2,7 +2,7 @@ array = [].constructor; function toJson(obj, pretty){ var buf = []; - toJsonArray(buf, obj, pretty ? "\n " : null); + toJsonArray(buf, obj, pretty ? "\n " : null, _([])); return buf.join(''); }; @@ -25,7 +25,14 @@ function fromJson(json) { angular['toJson'] = toJson; angular['fromJson'] = fromJson; -function toJsonArray(buf, obj, pretty){ +function toJsonArray(buf, obj, pretty, stack){ + if (typeof obj == "object") { + if (stack.include(obj)) { + buf.push("RECURSION"); + return; + } + stack.push(obj); + } var type = typeof obj; if (obj === null) { buf.push("null"); @@ -52,7 +59,7 @@ function toJsonArray(buf, obj, pretty){ if (typeof item == 'function' || typeof item == 'undefined') { buf.push("null"); } else { - toJsonArray(buf, item, pretty); + toJsonArray(buf, item, pretty, stack); } sep = true; } @@ -82,7 +89,7 @@ function toJsonArray(buf, obj, pretty){ } buf.push(angular['String']['quote'](key)); buf.push(":"); - toJsonArray(buf, value, childPretty); + toJsonArray(buf, value, childPretty, stack); comma = true; } } catch (e) { @@ -91,4 +98,7 @@ function toJsonArray(buf, obj, pretty){ buf.push("}"); } } + if (typeof obj == "object") { + stack.pop(); + } }; |
