|
| 1 | +interface WeakRef<T extends object> { |
| 2 | + readonly [Symbol.toStringTag]: "WeakRef"; |
| 3 | + |
| 4 | + /** |
| 5 | + * Returns the WeakRef instance's target object, or undefined if the target object has been |
| 6 | + * reclaimed. |
| 7 | + */ |
| 8 | + deref(): T | undefined; |
| 9 | +} |
| 10 | + |
| 11 | +interface WeakRefConstructor { |
| 12 | + readonly prototype: WeakRef<any>; |
| 13 | + |
| 14 | + /** |
| 15 | + * Creates a WeakRef instance for the given target object. |
| 16 | + * @param target The target object for the WeakRef instance. |
| 17 | + */ |
| 18 | + new<T extends object>(target?: T): WeakRef<T>; |
| 19 | +} |
| 20 | + |
| 21 | +declare var WeakRef: WeakRefConstructor; |
| 22 | + |
| 23 | +interface FinalizationRegistry { |
| 24 | + readonly [Symbol.toStringTag]: "FinalizationRegistry"; |
| 25 | + |
| 26 | + /** |
| 27 | + * Registers an object with the registry. |
| 28 | + * @param target The target object to register. |
| 29 | + * @param heldValue The value to pass to the finalizer for this object. This cannot be the |
| 30 | + * target object. |
| 31 | + * @param unregisterToken The token to pass to the unregister method to unregister the target |
| 32 | + * object. If provided (and not undefined), this must be an object. If not provided, the target |
| 33 | + * cannot be unregistered. |
| 34 | + */ |
| 35 | + register(target: object, heldValue: any, unregisterToken?: object): void; |
| 36 | + |
| 37 | + /** |
| 38 | + * Unregisters an object from the registry. |
| 39 | + * @param unregisterToken The token that was used as the unregisterToken argument when calling |
| 40 | + * register to register the target object. |
| 41 | + */ |
| 42 | + unregister(unregisterToken: object): void; |
| 43 | +} |
| 44 | + |
| 45 | +interface FinalizationRegistryConstructor { |
| 46 | + readonly prototype: FinalizationRegistry; |
| 47 | + |
| 48 | + /** |
| 49 | + * Creates a finalization registry with an associated cleanup callback |
| 50 | + * @param cleanupCallback The callback to call after an object in the registry has been reclaimed. |
| 51 | + */ |
| 52 | + new(cleanupCallback: (heldValue: any) => void): FinalizationRegistry; |
| 53 | +} |
| 54 | + |
| 55 | +declare var FinalizationRegistry: FinalizationRegistryConstructor; |
0 commit comments