(obj, replacer)
| 207 | |
| 208 | // safely perform toJSON logic on objects with cycles. |
| 209 | function __toJSONSafe(obj, replacer) { |
| 210 | if (obj !== Object(obj)) return obj; // primitive value |
| 211 | if (obj._$visited) return undefined; |
| 212 | if (obj.toJSON) { |
| 213 | var newObj = obj.toJSON(); |
| 214 | if (newObj !== Object(newObj)) return newObj; // primitive value |
| 215 | if (newObj !== obj) return __toJSONSafe(newObj); |
| 216 | // toJSON returned the object unchanged. |
| 217 | obj = newObj; |
| 218 | } |
| 219 | obj._$visited = true; |
| 220 | var result; |
| 221 | if (obj instanceof Array) { |
| 222 | result = obj.map(function (o) { |
| 223 | return __toJSONSafe(o, replacer); |
| 224 | }); |
| 225 | } else if (typeof (obj) === "function") { |
| 226 | result = undefined; |
| 227 | } else { |
| 228 | result = {}; |
| 229 | for (var prop in obj) { |
| 230 | if (prop === "_$visited") continue; |
| 231 | var val = obj[prop]; |
| 232 | if (replacer) { |
| 233 | val = replacer(prop, val); |
| 234 | if (val === undefined) continue; |
| 235 | } |
| 236 | val = __toJSONSafe(val); |
| 237 | if (val === undefined) continue; |
| 238 | result[prop] = val; |
| 239 | } |
| 240 | } |
| 241 | delete obj._$visited; |
| 242 | return result; |
| 243 | } |
| 244 | |
| 245 | // resolves the values of a list of properties by checking each property in multiple sources until a value is found. |
| 246 | function __resolveProperties(sources, propertyNames) { |
no outgoing calls
no test coverage detected