(obj, properties, printedObjects = new WeakSet())
| 80 | } |
| 81 | |
| 82 | function formatObject(obj, properties, printedObjects = new WeakSet()) { |
| 83 | printedObjects.add(obj); |
| 84 | if (Array.isArray(obj) || _isTypedArray(obj)) |
| 85 | return formatArray(obj, properties, printedObjects).toString(); |
| 86 | |
| 87 | if (obj instanceof Date) |
| 88 | return formatDate(obj); |
| 89 | |
| 90 | const formattedObject = []; |
| 91 | let keys = Object.getOwnPropertyNames(obj).concat(Object.getOwnPropertySymbols(obj)).map(k => [k, obj[k]]); |
| 92 | // properties is only passed to us in the debugger |
| 93 | if (properties?.cur) |
| 94 | keys = keys.concat(properties.cur); |
| 95 | |
| 96 | for (const [propertyKey, value] of keys) { |
| 97 | const key = formatPropertyKey(propertyKey); |
| 98 | switch (typeof value) { |
| 99 | case 'object': |
| 100 | if (printedObjects.has(value)) |
| 101 | formattedObject.push(`${key}: [Circular]`); |
| 102 | else if (value === null) |
| 103 | formattedObject.push(`${key}: null`); |
| 104 | else if (_hasStandardToString(value)) |
| 105 | formattedObject.push(`${key}: ${formatObject(value, properties?.children[propertyKey], printedObjects)}`); |
| 106 | else |
| 107 | formattedObject.push(`${key}: ${value.toString()}`); |
| 108 | break; |
| 109 | case 'function': |
| 110 | formattedObject.push(`${key}: ${formatFunction(value)}`); |
| 111 | break; |
| 112 | case 'string': |
| 113 | formattedObject.push(`${key}: "${value}"`); |
| 114 | break; |
| 115 | case 'symbol': |
| 116 | formattedObject.push(`${key}: ${formatSymbol(value)}`); |
| 117 | break; |
| 118 | default: |
| 119 | formattedObject.push(`${key}: ${value}`); |
| 120 | break; |
| 121 | } |
| 122 | } |
| 123 | return Object.keys(formattedObject).length === 0 ? '{}' |
| 124 | : `{ ${formattedObject.join(', ')} }`; |
| 125 | } |
| 126 | |
| 127 | function formatArray(arr, properties, printedObjects) { |
| 128 | const formattedArray = []; |
no test coverage detected