mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-25 06:13:44 +00:00
Serialize only own properties to avoid infinite loops when serializing scopes (this)
This commit is contained in:
parent
84b3a1774e
commit
7159b30752
2 changed files with 8 additions and 1 deletions
|
|
@ -74,7 +74,7 @@ function toJsonArray(buf, obj, pretty, stack){
|
||||||
var childPretty = pretty ? pretty + " " : false;
|
var childPretty = pretty ? pretty + " " : false;
|
||||||
var keys = [];
|
var keys = [];
|
||||||
for(var k in obj) {
|
for(var k in obj) {
|
||||||
if (k.indexOf('$$') === 0 || obj[k] === undefined)
|
if (!obj.hasOwnProperty(k) || k.indexOf('$$') === 0 || obj[k] === undefined)
|
||||||
continue;
|
continue;
|
||||||
keys.push(k);
|
keys.push(k);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,13 @@ JsonTest.prototype.testItShouldPreventRecursion = function () {
|
||||||
assertEquals('{"a":"b","recursion":RECURSION}', angular.toJson(obj));
|
assertEquals('{"a":"b","recursion":RECURSION}', angular.toJson(obj));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
JsonTest.prototype.testItShouldSerializeOnlyOwnProperties = function() {
|
||||||
|
var parent = { p: 'p'};
|
||||||
|
var child = { c: 'c'};
|
||||||
|
child.__proto__ = parent;
|
||||||
|
assertEquals('{"c":"c"}', angular.toJson(child));
|
||||||
|
}
|
||||||
|
|
||||||
JsonTest.prototype.testItShouldSerializeSameObjectsMultipleTimes = function () {
|
JsonTest.prototype.testItShouldSerializeSameObjectsMultipleTimes = function () {
|
||||||
var obj = {a:'b'};
|
var obj = {a:'b'};
|
||||||
assertEquals('{"A":{"a":"b"},"B":{"a":"b"}}', angular.toJson({A:obj, B:obj}));
|
assertEquals('{"A":{"a":"b"},"B":{"a":"b"}}', angular.toJson({A:obj, B:obj}));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue