| 13 | |
| 14 | /** @internal */ |
| 15 | export const getAllObjectKeys = (obj: object): Array<PropertyKey> | Set<PropertyKey> => { |
| 16 | const own = ownKeys(obj) |
| 17 | const proto = Object.getPrototypeOf(obj) |
| 18 | if (proto === Object.prototype || proto === null) return own |
| 19 | const keys = new Set<PropertyKey>(own) |
| 20 | |
| 21 | if (obj instanceof Error) { |
| 22 | keys.delete("stack") |
| 23 | for (const key of errorSiteKeys) { |
| 24 | if (!Object.prototype.propertyIsEnumerable.call(obj, key)) keys.delete(key) |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | let current = proto |
| 29 | while (current !== null && current !== Object.prototype) { |
| 30 | for (const key of ownKeys(current)) keys.add(key) |
| 31 | current = Object.getPrototypeOf(current) |
| 32 | } |
| 33 | if (typeof obj.constructor === "function" && proto === obj.constructor.prototype) { |
| 34 | keys.delete("constructor") |
| 35 | } |
| 36 | |
| 37 | return keys |
| 38 | } |
| 39 | |
| 40 | /** @internal */ |
| 41 | export const byReferenceInstances = new WeakSet<object>() |