(value, depth)
| 165 | } |
| 166 | |
| 167 | function stringifyWithDepthLimit(value, depth) { |
| 168 | if (maxDepth === Infinity) { |
| 169 | return JSON.stringify(value); |
| 170 | } |
| 171 | |
| 172 | const ancestors = []; |
| 173 | |
| 174 | return JSON.stringify(value, function limitDepth(_key, currentValue) { |
| 175 | if (!utils.isObject(currentValue)) { |
| 176 | return currentValue; |
| 177 | } |
| 178 | |
| 179 | while (ancestors.length && ancestors[ancestors.length - 1] !== this) { |
| 180 | ancestors.pop(); |
| 181 | } |
| 182 | |
| 183 | ancestors.push(currentValue); |
| 184 | throwIfMaxDepthExceeded(depth + ancestors.length - 1); |
| 185 | |
| 186 | return currentValue; |
| 187 | }); |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * Default visitor. |
no test coverage detected