(value: T)
| 26 | * @returns A WeakRef wrapper if available, or the original object as fallback |
| 27 | */ |
| 28 | export function makeWeakRef<T extends object>(value: T): MaybeWeakRef<T> { |
| 29 | try { |
| 30 | // @ts-expect-error - WeakRef may not be in the type definitions for older TS targets |
| 31 | const WeakRefImpl = GLOBAL_OBJ.WeakRef; |
| 32 | if (typeof WeakRefImpl === 'function') { |
| 33 | return new WeakRefImpl(value); |
| 34 | } |
| 35 | } catch { |
| 36 | // WeakRef not available or construction failed |
| 37 | } |
| 38 | return value; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Resolves a potentially weak reference, returning the underlying object |
no outgoing calls
no test coverage detected