2020-07-22 12:03:46 -04:00
|
|
|
/*! *****************************************************************************
|
|
|
|
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
|
|
this file except in compliance with the License. You may obtain a copy of the
|
|
|
|
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
|
|
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
|
|
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
|
|
|
|
|
|
See the Apache Version 2.0 License for specific language governing permissions
|
|
|
|
and limitations under the License.
|
|
|
|
***************************************************************************** */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <reference no-default-lib="true"/>
|
|
|
|
|
|
|
|
|
|
|
|
interface ProxyHandler<T extends object> {
|
2022-09-19 17:00:01 -04:00
|
|
|
/**
|
|
|
|
* A trap method for a function call.
|
|
|
|
* @param target The original callable object which is being proxied.
|
|
|
|
*/
|
2021-02-24 23:16:19 -05:00
|
|
|
apply?(target: T, thisArg: any, argArray: any[]): any;
|
2022-09-19 17:00:01 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A trap for the `new` operator.
|
|
|
|
* @param target The original object which is being proxied.
|
|
|
|
* @param newTarget The constructor that was originally called.
|
|
|
|
*/
|
2021-02-24 23:16:19 -05:00
|
|
|
construct?(target: T, argArray: any[], newTarget: Function): object;
|
2022-09-19 17:00:01 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A trap for `Object.defineProperty()`.
|
|
|
|
* @param target The original object which is being proxied.
|
|
|
|
* @returns A `Boolean` indicating whether or not the property has been defined.
|
|
|
|
*/
|
|
|
|
defineProperty?(target: T, property: string | symbol, attributes: PropertyDescriptor): boolean;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A trap for the `delete` operator.
|
|
|
|
* @param target The original object which is being proxied.
|
|
|
|
* @param p The name or `Symbol` of the property to delete.
|
|
|
|
* @returns A `Boolean` indicating whether or not the property was deleted.
|
|
|
|
*/
|
2021-02-24 23:16:19 -05:00
|
|
|
deleteProperty?(target: T, p: string | symbol): boolean;
|
2022-09-19 17:00:01 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A trap for getting a property value.
|
|
|
|
* @param target The original object which is being proxied.
|
|
|
|
* @param p The name or `Symbol` of the property to get.
|
|
|
|
* @param receiver The proxy or an object that inherits from the proxy.
|
|
|
|
*/
|
2021-02-24 23:16:19 -05:00
|
|
|
get?(target: T, p: string | symbol, receiver: any): any;
|
2022-09-19 17:00:01 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A trap for `Object.getOwnPropertyDescriptor()`.
|
|
|
|
* @param target The original object which is being proxied.
|
|
|
|
* @param p The name of the property whose description should be retrieved.
|
|
|
|
*/
|
2021-02-24 23:16:19 -05:00
|
|
|
getOwnPropertyDescriptor?(target: T, p: string | symbol): PropertyDescriptor | undefined;
|
2022-09-19 17:00:01 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A trap for the `[[GetPrototypeOf]]` internal method.
|
|
|
|
* @param target The original object which is being proxied.
|
|
|
|
*/
|
2021-02-24 23:16:19 -05:00
|
|
|
getPrototypeOf?(target: T): object | null;
|
2022-09-19 17:00:01 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A trap for the `in` operator.
|
|
|
|
* @param target The original object which is being proxied.
|
|
|
|
* @param p The name or `Symbol` of the property to check for existence.
|
|
|
|
*/
|
2021-02-24 23:16:19 -05:00
|
|
|
has?(target: T, p: string | symbol): boolean;
|
2022-09-19 17:00:01 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A trap for `Object.isExtensible()`.
|
|
|
|
* @param target The original object which is being proxied.
|
|
|
|
*/
|
2021-02-24 23:16:19 -05:00
|
|
|
isExtensible?(target: T): boolean;
|
2022-09-19 17:00:01 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A trap for `Reflect.ownKeys()`.
|
|
|
|
* @param target The original object which is being proxied.
|
|
|
|
*/
|
2021-02-24 23:16:19 -05:00
|
|
|
ownKeys?(target: T): ArrayLike<string | symbol>;
|
2022-09-19 17:00:01 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A trap for `Object.preventExtensions()`.
|
|
|
|
* @param target The original object which is being proxied.
|
|
|
|
*/
|
2021-02-24 23:16:19 -05:00
|
|
|
preventExtensions?(target: T): boolean;
|
2022-09-19 17:00:01 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A trap for setting a property value.
|
|
|
|
* @param target The original object which is being proxied.
|
|
|
|
* @param p The name or `Symbol` of the property to set.
|
|
|
|
* @param receiver The object to which the assignment was originally directed.
|
2022-12-07 12:59:59 -05:00
|
|
|
* @returns A `Boolean` indicating whether or not the property was set.
|
2022-09-19 17:00:01 -04:00
|
|
|
*/
|
|
|
|
set?(target: T, p: string | symbol, newValue: any, receiver: any): boolean;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A trap for `Object.setPrototypeOf()`.
|
|
|
|
* @param target The original object which is being proxied.
|
|
|
|
* @param newPrototype The object's new prototype or `null`.
|
|
|
|
*/
|
2021-02-24 23:16:19 -05:00
|
|
|
setPrototypeOf?(target: T, v: object | null): boolean;
|
2020-07-22 12:03:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
interface ProxyConstructor {
|
2022-09-19 17:00:01 -04:00
|
|
|
/**
|
|
|
|
* Creates a revocable Proxy object.
|
|
|
|
* @param target A target object to wrap with Proxy.
|
|
|
|
* @param handler An object whose properties define the behavior of Proxy when an operation is attempted on it.
|
|
|
|
*/
|
2020-07-22 12:03:46 -04:00
|
|
|
revocable<T extends object>(target: T, handler: ProxyHandler<T>): { proxy: T; revoke: () => void; };
|
2022-09-19 17:00:01 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a Proxy object. The Proxy object allows you to create an object that can be used in place of the
|
|
|
|
* original object, but which may redefine fundamental Object operations like getting, setting, and defining
|
|
|
|
* properties. Proxy objects are commonly used to log property accesses, validate, format, or sanitize inputs.
|
|
|
|
* @param target A target object to wrap with Proxy.
|
|
|
|
* @param handler An object whose properties define the behavior of Proxy when an operation is attempted on it.
|
|
|
|
*/
|
2020-07-22 12:03:46 -04:00
|
|
|
new <T extends object>(target: T, handler: ProxyHandler<T>): T;
|
|
|
|
}
|
|
|
|
declare var Proxy: ProxyConstructor;
|