|
1 | 1 | import { SentryWrappedFunction } from '@sentry/types'; |
2 | | -import { isNaN, isPlainObject, isPrimitive, isUndefined } from './is'; |
| 2 | +import { isArray, isNaN, isPlainObject, isPrimitive, isUndefined } from './is'; |
3 | 3 | import { Memo } from './memo'; |
4 | 4 | import { truncate } from './string'; |
5 | 5 |
|
@@ -153,7 +153,7 @@ export function serializeObject<T>(value: T, depth: number): T | string | {} { |
153 | 153 | }); |
154 | 154 |
|
155 | 155 | return serialized; |
156 | | - } else if (Array.isArray(value)) { |
| 156 | + } else if (isArray(value)) { |
157 | 157 | const val = (value as any) as T[]; |
158 | 158 | return val.map(v => serializeObject(v, depth - 1)); |
159 | 159 | } |
@@ -325,19 +325,23 @@ function normalizeValue(value: any, key?: any): any { |
325 | 325 | * @param obj Object to be decycled |
326 | 326 | * @param memo Optional Memo class handling decycling |
327 | 327 | */ |
328 | | -function decycle(obj: any, memo: Memo = new Memo()): any { |
| 328 | +export function decycle(obj: any, memo: Memo = new Memo()): any { |
| 329 | + // tslint:disable-next-line:no-unsafe-any |
| 330 | + const copy = isArray(obj) ? [...obj] : isPlainObject(obj) ? { ...obj } : obj; |
| 331 | + |
329 | 332 | if (!isPrimitive(obj)) { |
330 | 333 | if (memo.memoize(obj)) { |
331 | 334 | return '[Circular ~]'; |
332 | 335 | } |
333 | 336 | // tslint:disable-next-line |
334 | 337 | for (const key in obj) { |
335 | 338 | // tslint:disable-next-line |
336 | | - obj[key] = decycle(obj[key], memo); |
| 339 | + copy[key] = decycle(obj[key], memo); |
337 | 340 | } |
338 | 341 | memo.unmemoize(obj); |
339 | 342 | } |
340 | | - return obj; |
| 343 | + |
| 344 | + return copy; |
341 | 345 | } |
342 | 346 |
|
343 | 347 | /** |
|
0 commit comments