lib.es2021.weakref.d.ts 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 WeakKey> {
  15. readonly [Symbol.toStringTag]: "WeakRef";
  16. /**
  17. * Returns the WeakRef instance's target value, or undefined if the target value has been
  18. * reclaimed.
  19. * In es2023 the value can be either a symbol or an object, in previous versions only object is permissible.
  20. */
  21. deref(): T | undefined;
  22. }
  23. interface WeakRefConstructor {
  24. readonly prototype: WeakRef<any>;
  25. /**
  26. * Creates a WeakRef instance for the given target value.
  27. * In es2023 the value can be either a symbol or an object, in previous versions only object is permissible.
  28. * @param target The target value for the WeakRef instance.
  29. */
  30. new <T extends WeakKey>(target: T): WeakRef<T>;
  31. }
  32. declare var WeakRef: WeakRefConstructor;
  33. interface FinalizationRegistry<T> {
  34. readonly [Symbol.toStringTag]: "FinalizationRegistry";
  35. /**
  36. * Registers a value with the registry.
  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 to register.
  39. * @param heldValue The value to pass to the finalizer for this value. This cannot be the
  40. * target value.
  41. * @param unregisterToken The token to pass to the unregister method to unregister the target
  42. * value. If not provided, the target cannot be unregistered.
  43. */
  44. register(target: WeakKey, heldValue: T, unregisterToken?: WeakKey): void;
  45. /**
  46. * Unregisters a value from the registry.
  47. * In es2023 the value can be either a symbol or an object, in previous versions only object is permissible.
  48. * @param unregisterToken The token that was used as the unregisterToken argument when calling
  49. * register to register the target value.
  50. */
  51. unregister(unregisterToken: WeakKey): boolean;
  52. }
  53. interface FinalizationRegistryConstructor {
  54. readonly prototype: FinalizationRegistry<any>;
  55. /**
  56. * Creates a finalization registry with an associated cleanup callback
  57. * @param cleanupCallback The callback to call after a value in the registry has been reclaimed.
  58. */
  59. new <T>(cleanupCallback: (heldValue: T) => void): FinalizationRegistry<T>;
  60. }
  61. declare var FinalizationRegistry: FinalizationRegistryConstructor;