lib.es2015.proxy.d.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 ProxyHandler<T extends object> {
  15. /**
  16. * A trap method for a function call.
  17. * @param target The original callable object which is being proxied.
  18. */
  19. apply?(target: T, thisArg: any, argArray: any[]): any;
  20. /**
  21. * A trap for the `new` operator.
  22. * @param target The original object which is being proxied.
  23. * @param newTarget The constructor that was originally called.
  24. */
  25. construct?(target: T, argArray: any[], newTarget: Function): object;
  26. /**
  27. * A trap for `Object.defineProperty()`.
  28. * @param target The original object which is being proxied.
  29. * @returns A `Boolean` indicating whether or not the property has been defined.
  30. */
  31. defineProperty?(target: T, property: string | symbol, attributes: PropertyDescriptor): boolean;
  32. /**
  33. * A trap for the `delete` operator.
  34. * @param target The original object which is being proxied.
  35. * @param p The name or `Symbol` of the property to delete.
  36. * @returns A `Boolean` indicating whether or not the property was deleted.
  37. */
  38. deleteProperty?(target: T, p: string | symbol): boolean;
  39. /**
  40. * A trap for getting a property value.
  41. * @param target The original object which is being proxied.
  42. * @param p The name or `Symbol` of the property to get.
  43. * @param receiver The proxy or an object that inherits from the proxy.
  44. */
  45. get?(target: T, p: string | symbol, receiver: any): any;
  46. /**
  47. * A trap for `Object.getOwnPropertyDescriptor()`.
  48. * @param target The original object which is being proxied.
  49. * @param p The name of the property whose description should be retrieved.
  50. */
  51. getOwnPropertyDescriptor?(target: T, p: string | symbol): PropertyDescriptor | undefined;
  52. /**
  53. * A trap for the `[[GetPrototypeOf]]` internal method.
  54. * @param target The original object which is being proxied.
  55. */
  56. getPrototypeOf?(target: T): object | null;
  57. /**
  58. * A trap for the `in` operator.
  59. * @param target The original object which is being proxied.
  60. * @param p The name or `Symbol` of the property to check for existence.
  61. */
  62. has?(target: T, p: string | symbol): boolean;
  63. /**
  64. * A trap for `Object.isExtensible()`.
  65. * @param target The original object which is being proxied.
  66. */
  67. isExtensible?(target: T): boolean;
  68. /**
  69. * A trap for `Reflect.ownKeys()`.
  70. * @param target The original object which is being proxied.
  71. */
  72. ownKeys?(target: T): ArrayLike<string | symbol>;
  73. /**
  74. * A trap for `Object.preventExtensions()`.
  75. * @param target The original object which is being proxied.
  76. */
  77. preventExtensions?(target: T): boolean;
  78. /**
  79. * A trap for setting a property value.
  80. * @param target The original object which is being proxied.
  81. * @param p The name or `Symbol` of the property to set.
  82. * @param receiver The object to which the assignment was originally directed.
  83. * @returns A `Boolean` indicating whether or not the property was set.
  84. */
  85. set?(target: T, p: string | symbol, newValue: any, receiver: any): boolean;
  86. /**
  87. * A trap for `Object.setPrototypeOf()`.
  88. * @param target The original object which is being proxied.
  89. * @param newPrototype The object's new prototype or `null`.
  90. */
  91. setPrototypeOf?(target: T, v: object | null): boolean;
  92. }
  93. interface ProxyConstructor {
  94. /**
  95. * Creates a revocable Proxy object.
  96. * @param target A target object to wrap with Proxy.
  97. * @param handler An object whose properties define the behavior of Proxy when an operation is attempted on it.
  98. */
  99. revocable<T extends object>(target: T, handler: ProxyHandler<T>): { proxy: T; revoke: () => void; };
  100. /**
  101. * Creates a Proxy object. The Proxy object allows you to create an object that can be used in place of the
  102. * original object, but which may redefine fundamental Object operations like getting, setting, and defining
  103. * properties. Proxy objects are commonly used to log property accesses, validate, format, or sanitize inputs.
  104. * @param target A target object to wrap with Proxy.
  105. * @param handler An object whose properties define the behavior of Proxy when an operation is attempted on it.
  106. */
  107. new <T extends object>(target: T, handler: ProxyHandler<T>): T;
  108. }
  109. declare var Proxy: ProxyConstructor;