lib.es2021.weakref.d.ts (3171B)
1 /*! ***************************************************************************** 2 Copyright (c) Microsoft Corporation. All rights reserved. 3 Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 this file except in compliance with the License. You may obtain a copy of the 5 License at http://www.apache.org/licenses/LICENSE-2.0 6 7 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 MERCHANTABLITY OR NON-INFRINGEMENT. 11 12 See the Apache Version 2.0 License for specific language governing permissions 13 and limitations under the License. 14 ***************************************************************************** */ 15 16 17 /// <reference no-default-lib="true"/> 18 19 /// <reference lib="es2015.symbol.wellknown" /> 20 21 interface WeakRef<T extends WeakKey> { 22 readonly [Symbol.toStringTag]: "WeakRef"; 23 24 /** 25 * Returns the WeakRef instance's target value, or undefined if the target value has been 26 * reclaimed. 27 * In es2023 the value can be either a symbol or an object, in previous versions only object is permissible. 28 */ 29 deref(): T | undefined; 30 } 31 32 interface WeakRefConstructor { 33 readonly prototype: WeakRef<any>; 34 35 /** 36 * Creates a WeakRef instance for the given target value. 37 * In es2023 the value can be either a symbol or an object, in previous versions only object is permissible. 38 * @param target The target value for the WeakRef instance. 39 */ 40 new <T extends WeakKey>(target: T): WeakRef<T>; 41 } 42 43 declare var WeakRef: WeakRefConstructor; 44 45 interface FinalizationRegistry<T> { 46 readonly [Symbol.toStringTag]: "FinalizationRegistry"; 47 48 /** 49 * Registers a value with the registry. 50 * In es2023 the value can be either a symbol or an object, in previous versions only object is permissible. 51 * @param target The target value to register. 52 * @param heldValue The value to pass to the finalizer for this value. This cannot be the 53 * target value. 54 * @param unregisterToken The token to pass to the unregister method to unregister the target 55 * value. If not provided, the target cannot be unregistered. 56 */ 57 register(target: WeakKey, heldValue: T, unregisterToken?: WeakKey): void; 58 59 /** 60 * Unregisters a value from the registry. 61 * In es2023 the value can be either a symbol or an object, in previous versions only object is permissible. 62 * @param unregisterToken The token that was used as the unregisterToken argument when calling 63 * register to register the target value. 64 */ 65 unregister(unregisterToken: WeakKey): boolean; 66 } 67 68 interface FinalizationRegistryConstructor { 69 readonly prototype: FinalizationRegistry<any>; 70 71 /** 72 * Creates a finalization registry with an associated cleanup callback 73 * @param cleanupCallback The callback to call after a value in the registry has been reclaimed. 74 */ 75 new <T>(cleanupCallback: (heldValue: T) => void): FinalizationRegistry<T>; 76 } 77 78 declare var FinalizationRegistry: FinalizationRegistryConstructor;