lib.es2021.weakref.d.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  7. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  8. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  9. MERCHANTABLITY OR NON-INFRINGEMENT.
  10. See the Apache Version 2.0 License for specific language governing permissions
  11. and limitations under the License.
  12. ***************************************************************************** */
  13. /// <reference no-default-lib="true"/>
  14. interface WeakRef<T extends object> {
  15. readonly [Symbol.toStringTag]: "WeakRef";
  16. /**
  17. * Returns the WeakRef instance's target object, or undefined if the target object has been
  18. * reclaimed.
  19. */
  20. deref(): T | undefined;
  21. }
  22. interface WeakRefConstructor {
  23. readonly prototype: WeakRef<any>;
  24. /**
  25. * Creates a WeakRef instance for the given target object.
  26. * @param target The target object for the WeakRef instance.
  27. */
  28. new<T extends object>(target: T): WeakRef<T>;
  29. }
  30. declare var WeakRef: WeakRefConstructor;
  31. interface FinalizationRegistry<T> {
  32. readonly [Symbol.toStringTag]: "FinalizationRegistry";
  33. /**
  34. * Registers an object with the registry.
  35. * @param target The target object to register.
  36. * @param heldValue The value to pass to the finalizer for this object. This cannot be the
  37. * target object.
  38. * @param unregisterToken The token to pass to the unregister method to unregister the target
  39. * object. If provided (and not undefined), this must be an object. If not provided, the target
  40. * cannot be unregistered.
  41. */
  42. register(target: object, heldValue: T, unregisterToken?: object): void;
  43. /**
  44. * Unregisters an object from the registry.
  45. * @param unregisterToken The token that was used as the unregisterToken argument when calling
  46. * register to register the target object.
  47. */
  48. unregister(unregisterToken: object): void;
  49. }
  50. interface FinalizationRegistryConstructor {
  51. readonly prototype: FinalizationRegistry<any>;
  52. /**
  53. * Creates a finalization registry with an associated cleanup callback
  54. * @param cleanupCallback The callback to call after an object in the registry has been reclaimed.
  55. */
  56. new<T>(cleanupCallback: (heldValue: T) => void): FinalizationRegistry<T>;
  57. }
  58. declare var FinalizationRegistry: FinalizationRegistryConstructor;