diff --git a/Reflect.ts b/Reflect.ts index 3cf181b..8e65aa3 100644 --- a/Reflect.ts +++ b/Reflect.ts @@ -15,6 +15,9 @@ and limitations under the License. namespace Reflect { "use strict"; + // Metadata Proposal + // https://rbuckton.github.io/reflect-metadata/ + type HashMap = Record; interface BufferLike { @@ -133,6 +136,7 @@ namespace Reflect { const _WeakMap: typeof WeakMap = typeof WeakMap === "function" ? WeakMap : CreateWeakMapPolyfill(); // [[Metadata]] internal slot + // https://rbuckton.github.io/reflect-metadata/#ordinary-object-internal-methods-and-internal-slots const Metadata = new _WeakMap>>(); /** @@ -155,8 +159,8 @@ namespace Reflect { * Applies a set of decorators to a property of a target object. * @param decorators An array of decorators. * @param target The target object. - * @param targetKey The property key to decorate. - * @param targetDescriptor A property descriptor + * @param propertyKey The property key to decorate. + * @param attributes A property descriptor. * @remarks Decorators are applied in reverse order. * @example * @@ -186,14 +190,14 @@ namespace Reflect { * Object.getOwnPropertyDescriptor(Example.prototype, "method"))); * */ - export function decorate(decorators: (PropertyDecorator | MethodDecorator)[], target: any, targetKey: string | symbol, targetDescriptor?: PropertyDescriptor | null): PropertyDescriptor | undefined; + export function decorate(decorators: (PropertyDecorator | MethodDecorator)[], target: any, propertyKey: string | symbol, attributes?: PropertyDescriptor | null): PropertyDescriptor | undefined; /** * Applies a set of decorators to a property of a target object. * @param decorators An array of decorators. * @param target The target object. - * @param targetKey The property key to decorate. - * @param targetDescriptor A property descriptor + * @param propertyKey The property key to decorate. + * @param attributes A property descriptor. * @remarks Decorators are applied in reverse order. * @example * @@ -223,14 +227,14 @@ namespace Reflect { * Object.getOwnPropertyDescriptor(Example.prototype, "method"))); * */ - export function decorate(decorators: (PropertyDecorator | MethodDecorator)[], target: any, targetKey: string | symbol, targetDescriptor: PropertyDescriptor): PropertyDescriptor; + export function decorate(decorators: (PropertyDecorator | MethodDecorator)[], target: any, propertyKey: string | symbol, attributes: PropertyDescriptor): PropertyDescriptor; /** * Applies a set of decorators to a property of a target object. * @param decorators An array of decorators. * @param target The target object. - * @param targetKey (Optional) The property key to decorate. - * @param targetDescriptor (Optional) The property descriptor for the target key + * @param propertyKey (Optional) The property key to decorate. + * @param attributes (Optional) The property descriptor for the target key. * @remarks Decorators are applied in reverse order. * @example * @@ -264,14 +268,14 @@ namespace Reflect { * Object.getOwnPropertyDescriptor(Example.prototype, "method"))); * */ - export function decorate(decorators: (ClassDecorator | MemberDecorator)[], target: any, targetKey?: string | symbol, targetDescriptor?: PropertyDescriptor | null): PropertyDescriptor | Function | undefined { - if (!IsUndefined(targetKey)) { + export function decorate(decorators: (ClassDecorator | MemberDecorator)[], target: any, propertyKey?: string | symbol, attributes?: PropertyDescriptor | null): PropertyDescriptor | Function | undefined { + if (!IsUndefined(propertyKey)) { if (!IsArray(decorators)) throw new TypeError(); if (!IsObject(target)) throw new TypeError(); - if (!IsObject(targetDescriptor) && !IsUndefined(targetDescriptor) && !IsNull(targetDescriptor)) throw new TypeError(); - if (IsNull(targetDescriptor)) targetDescriptor = undefined; - targetKey = ToPropertyKey(targetKey); - return DecorateProperty(decorators, target, targetKey, targetDescriptor); + if (!IsObject(attributes) && !IsUndefined(attributes) && !IsNull(attributes)) throw new TypeError(); + if (IsNull(attributes)) attributes = undefined; + propertyKey = ToPropertyKey(propertyKey); + return DecorateProperty(decorators, target, propertyKey, attributes); } else { if (!IsArray(decorators)) throw new TypeError(); @@ -280,6 +284,9 @@ namespace Reflect { } } + // 4.1.2 Reflect.metadata(metadataKey, metadataValue) + // https://rbuckton.github.io/reflect-metadata/#reflect.metadata + /** * A default metadata decorator factory that can be used on a class, class member, or parameter. * @param metadataKey The key for the metadata entry. @@ -322,21 +329,18 @@ namespace Reflect { */ export function metadata(metadataKey: any, metadataValue: any) { function decorator(target: Function): void; - function decorator(target: any, targetKey: string | symbol): void; - function decorator(target: any, targetKey?: string | symbol): void { - if (!IsUndefined(targetKey)) { - if (!IsObject(target)) throw new TypeError(); - targetKey = ToPropertyKey(targetKey); - OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, targetKey); - } - else { - if (!IsConstructor(target)) throw new TypeError(); - OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, /*targetKey*/ undefined); - } + function decorator(target: any, propertyKey: string | symbol): void; + function decorator(target: any, propertyKey?: string | symbol): void { + if (!IsObject(target)) throw new TypeError(); + if (!IsUndefined(propertyKey) && !IsPropertyKey(propertyKey)) throw new TypeError(); + OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey); } return decorator; } + // 4.1.3 Reflect.defineMetadata(metadataKey, metadataValue, target [, propertyKey]) + // https://rbuckton.github.io/reflect-metadata/#reflect.definemetadata + /** * Define a unique metadata entry on the target. * @param metadataKey A key used to store and retrieve metadata. @@ -363,7 +367,7 @@ namespace Reflect { * @param metadataKey A key used to store and retrieve metadata. * @param metadataValue A value that contains attached metadata. * @param target The target object on which to define metadata. - * @param targetKey The property key for the target. + * @param propertyKey The property key for the target. * @example * * class Example { @@ -393,14 +397,14 @@ namespace Reflect { * } * */ - export function defineMetadata(metadataKey: any, metadataValue: any, target: any, targetKey: string | symbol): void; + export function defineMetadata(metadataKey: any, metadataValue: any, target: any, propertyKey: string | symbol): void; /** * Define a unique metadata entry on the target. * @param metadataKey A key used to store and retrieve metadata. * @param metadataValue A value that contains attached metadata. * @param target The target object on which to define metadata. - * @param targetKey (Optional) The property key for the target. + * @param propertyKey (Optional) The property key for the target. * @example * * class Example { @@ -434,12 +438,15 @@ namespace Reflect { * } * */ - export function defineMetadata(metadataKey: any, metadataValue: any, target: any, targetKey?: string | symbol): void { + export function defineMetadata(metadataKey: any, metadataValue: any, target: any, propertyKey?: string | symbol): void { if (!IsObject(target)) throw new TypeError(); - if (!IsUndefined(targetKey)) targetKey = ToPropertyKey(targetKey); - return OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, targetKey); + if (!IsUndefined(propertyKey)) propertyKey = ToPropertyKey(propertyKey); + return OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey); } + // 4.1.4 Reflect.hasMetadata(metadataKey, target [, propertyKey]) + // https://rbuckton.github.io/reflect-metadata/#reflect.hasmetadata + /** * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined. * @param metadataKey A key used to store and retrieve metadata. @@ -460,7 +467,7 @@ namespace Reflect { * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined. * @param metadataKey A key used to store and retrieve metadata. * @param target The target object on which the metadata is defined. - * @param targetKey The property key for the target. + * @param propertyKey The property key for the target. * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`. * @example * @@ -486,13 +493,13 @@ namespace Reflect { * result = Reflect.hasMetadata("custom:annotation", Example.prototype, "method"); * */ - export function hasMetadata(metadataKey: any, target: any, targetKey: string | symbol): boolean; + export function hasMetadata(metadataKey: any, target: any, propertyKey: string | symbol): boolean; /** * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined. * @param metadataKey A key used to store and retrieve metadata. * @param target The target object on which the metadata is defined. - * @param targetKey (Optional) The property key for the target. + * @param propertyKey (Optional) The property key for the target. * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`. * @example * @@ -522,12 +529,15 @@ namespace Reflect { * result = Reflect.hasMetadata("custom:annotation", Example.prototype, "method"); * */ - export function hasMetadata(metadataKey: any, target: any, targetKey?: string | symbol): boolean { + export function hasMetadata(metadataKey: any, target: any, propertyKey?: string | symbol): boolean { if (!IsObject(target)) throw new TypeError(); - if (!IsUndefined(targetKey)) targetKey = ToPropertyKey(targetKey); - return OrdinaryHasMetadata(metadataKey, target, targetKey); + if (!IsUndefined(propertyKey)) propertyKey = ToPropertyKey(propertyKey); + return OrdinaryHasMetadata(metadataKey, target, propertyKey); } + // 4.1.5 Reflect.hasOwnMetadata(metadataKey, target [, propertyKey]) + // https://rbuckton.github.io/reflect-metadata/#reflect-hasownmetadata + /** * Gets a value indicating whether the target object has the provided metadata key defined. * @param metadataKey A key used to store and retrieve metadata. @@ -548,7 +558,7 @@ namespace Reflect { * Gets a value indicating whether the target object has the provided metadata key defined. * @param metadataKey A key used to store and retrieve metadata. * @param target The target object on which the metadata is defined. - * @param targetKey The property key for the target. + * @param propertyKey The property key for the target. * @returns `true` if the metadata key was defined on the target object; otherwise, `false`. * @example * @@ -574,13 +584,13 @@ namespace Reflect { * result = Reflect.hasOwnMetadata("custom:annotation", Example.prototype, "method"); * */ - export function hasOwnMetadata(metadataKey: any, target: any, targetKey: string | symbol): boolean; + export function hasOwnMetadata(metadataKey: any, target: any, propertyKey: string | symbol): boolean; /** * Gets a value indicating whether the target object has the provided metadata key defined. * @param metadataKey A key used to store and retrieve metadata. * @param target The target object on which the metadata is defined. - * @param targetKey (Optional) The property key for the target. + * @param propertyKey (Optional) The property key for the target. * @returns `true` if the metadata key was defined on the target object; otherwise, `false`. * @example * @@ -610,12 +620,15 @@ namespace Reflect { * result = Reflect.hasOwnMetadata("custom:annotation", Example.prototype, "method"); * */ - export function hasOwnMetadata(metadataKey: any, target: any, targetKey?: string | symbol): boolean { + export function hasOwnMetadata(metadataKey: any, target: any, propertyKey?: string | symbol): boolean { if (!IsObject(target)) throw new TypeError(); - if (!IsUndefined(targetKey)) targetKey = ToPropertyKey(targetKey); - return OrdinaryHasOwnMetadata(metadataKey, target, targetKey); + if (!IsUndefined(propertyKey)) propertyKey = ToPropertyKey(propertyKey); + return OrdinaryHasOwnMetadata(metadataKey, target, propertyKey); } + // 4.1.6 Reflect.getMetadata(metadataKey, target [, propertyKey]) + // https://rbuckton.github.io/reflect-metadata/#reflect-getmetadata + /** * Gets the metadata value for the provided metadata key on the target object or its prototype chain. * @param metadataKey A key used to store and retrieve metadata. @@ -636,7 +649,7 @@ namespace Reflect { * Gets the metadata value for the provided metadata key on the target object or its prototype chain. * @param metadataKey A key used to store and retrieve metadata. * @param target The target object on which the metadata is defined. - * @param targetKey The property key for the target. + * @param propertyKey The property key for the target. * @returns The metadata value for the metadata key if found; otherwise, `undefined`. * @example * @@ -662,13 +675,13 @@ namespace Reflect { * result = Reflect.getMetadata("custom:annotation", Example.prototype, "method"); * */ - export function getMetadata(metadataKey: any, target: any, targetKey: string | symbol): any; + export function getMetadata(metadataKey: any, target: any, propertyKey: string | symbol): any; /** * Gets the metadata value for the provided metadata key on the target object or its prototype chain. * @param metadataKey A key used to store and retrieve metadata. * @param target The target object on which the metadata is defined. - * @param targetKey (Optional) The property key for the target. + * @param propertyKey (Optional) The property key for the target. * @returns The metadata value for the metadata key if found; otherwise, `undefined`. * @example * @@ -698,12 +711,15 @@ namespace Reflect { * result = Reflect.getMetadata("custom:annotation", Example.prototype, "method"); * */ - export function getMetadata(metadataKey: any, target: any, targetKey?: string | symbol): any { + export function getMetadata(metadataKey: any, target: any, propertyKey?: string | symbol): any { if (!IsObject(target)) throw new TypeError(); - if (!IsUndefined(targetKey)) targetKey = ToPropertyKey(targetKey); - return OrdinaryGetMetadata(metadataKey, target, targetKey); + if (!IsUndefined(propertyKey)) propertyKey = ToPropertyKey(propertyKey); + return OrdinaryGetMetadata(metadataKey, target, propertyKey); } + // 4.1.7 Reflect.getOwnMetadata(metadataKey, target [, propertyKey]) + // https://rbuckton.github.io/reflect-metadata/#reflect-getownmetadata + /** * Gets the metadata value for the provided metadata key on the target object. * @param metadataKey A key used to store and retrieve metadata. @@ -724,7 +740,7 @@ namespace Reflect { * Gets the metadata value for the provided metadata key on the target object. * @param metadataKey A key used to store and retrieve metadata. * @param target The target object on which the metadata is defined. - * @param targetKey The property key for the target. + * @param propertyKey The property key for the target. * @returns The metadata value for the metadata key if found; otherwise, `undefined`. * @example * @@ -750,13 +766,13 @@ namespace Reflect { * result = Reflect.getOwnMetadata("custom:annotation", Example.prototype, "method"); * */ - export function getOwnMetadata(metadataKey: any, target: any, targetKey: string | symbol): any; + export function getOwnMetadata(metadataKey: any, target: any, propertyKey: string | symbol): any; /** * Gets the metadata value for the provided metadata key on the target object. * @param metadataKey A key used to store and retrieve metadata. * @param target The target object on which the metadata is defined. - * @param targetKey (Optional) The property key for the target. + * @param propertyKey (Optional) The property key for the target. * @returns The metadata value for the metadata key if found; otherwise, `undefined`. * @example * @@ -786,12 +802,15 @@ namespace Reflect { * result = Reflect.getOwnMetadata("custom:annotation", Example.prototype, "method"); * */ - export function getOwnMetadata(metadataKey: any, target: any, targetKey?: string | symbol): any { + export function getOwnMetadata(metadataKey: any, target: any, propertyKey?: string | symbol): any { if (!IsObject(target)) throw new TypeError(); - if (!IsUndefined(targetKey)) targetKey = ToPropertyKey(targetKey); - return OrdinaryGetOwnMetadata(metadataKey, target, targetKey); + if (!IsUndefined(propertyKey)) propertyKey = ToPropertyKey(propertyKey); + return OrdinaryGetOwnMetadata(metadataKey, target, propertyKey); } + // 4.1.8 Reflect.getMetadataKeys(target [, propertyKey]) + // https://rbuckton.github.io/reflect-metadata/#reflect-getmetadatakeys + /** * Gets the metadata keys defined on the target object or its prototype chain. * @param target The target object on which the metadata is defined. @@ -810,7 +829,7 @@ namespace Reflect { /** * Gets the metadata keys defined on the target object or its prototype chain. * @param target The target object on which the metadata is defined. - * @param targetKey The property key for the target. + * @param propertyKey The property key for the target. * @returns An array of unique metadata keys. * @example * @@ -836,12 +855,12 @@ namespace Reflect { * result = Reflect.getMetadataKeys(Example.prototype, "method"); * */ - export function getMetadataKeys(target: any, targetKey: string | symbol): any[]; + export function getMetadataKeys(target: any, propertyKey: string | symbol): any[]; /** * Gets the metadata keys defined on the target object or its prototype chain. * @param target The target object on which the metadata is defined. - * @param targetKey (Optional) The property key for the target. + * @param propertyKey (Optional) The property key for the target. * @returns An array of unique metadata keys. * @example * @@ -871,12 +890,15 @@ namespace Reflect { * result = Reflect.getMetadataKeys(Example.prototype, "method"); * */ - export function getMetadataKeys(target: any, targetKey?: string | symbol): any[] { + export function getMetadataKeys(target: any, propertyKey?: string | symbol): any[] { if (!IsObject(target)) throw new TypeError(); - if (!IsUndefined(targetKey)) targetKey = ToPropertyKey(targetKey); - return OrdinaryMetadataKeys(target, targetKey); + if (!IsUndefined(propertyKey)) propertyKey = ToPropertyKey(propertyKey); + return OrdinaryMetadataKeys(target, propertyKey); } + // 4.1.9 Reflect.getOwnMetadataKeys(target [, propertyKey]) + // https://rbuckton.github.io/reflect-metadata/#reflect-getownmetadata + /** * Gets the unique metadata keys defined on the target object. * @param target The target object on which the metadata is defined. @@ -895,7 +917,7 @@ namespace Reflect { /** * Gets the unique metadata keys defined on the target object. * @param target The target object on which the metadata is defined. - * @param targetKey The property key for the target. + * @param propertyKey The property key for the target. * @returns An array of unique metadata keys. * @example * @@ -921,12 +943,12 @@ namespace Reflect { * result = Reflect.getOwnMetadataKeys(Example.prototype, "method"); * */ - export function getOwnMetadataKeys(target: any, targetKey: string | symbol): any[]; + export function getOwnMetadataKeys(target: any, propertyKey: string | symbol): any[]; /** * Gets the unique metadata keys defined on the target object. * @param target The target object on which the metadata is defined. - * @param targetKey (Optional) The property key for the target. + * @param propertyKey (Optional) The property key for the target. * @returns An array of unique metadata keys. * @example * @@ -956,12 +978,15 @@ namespace Reflect { * result = Reflect.getOwnMetadataKeys(Example.prototype, "method"); * */ - export function getOwnMetadataKeys(target: any, targetKey?: string | symbol): any[] { + export function getOwnMetadataKeys(target: any, propertyKey?: string | symbol): any[] { if (!IsObject(target)) throw new TypeError(); - if (!IsUndefined(targetKey)) targetKey = ToPropertyKey(targetKey); - return OrdinaryOwnMetadataKeys(target, targetKey); + if (!IsUndefined(propertyKey)) propertyKey = ToPropertyKey(propertyKey); + return OrdinaryOwnMetadataKeys(target, propertyKey); } + // 4.1.10 Reflect.deleteMetadata(metadataKey, target [, propertyKey]) + // https://rbuckton.github.io/reflect-metadata/#reflect-deletemetadata + /** * Deletes the metadata entry from the target object with the provided key. * @param metadataKey A key used to store and retrieve metadata. @@ -982,7 +1007,7 @@ namespace Reflect { * Deletes the metadata entry from the target object with the provided key. * @param metadataKey A key used to store and retrieve metadata. * @param target The target object on which the metadata is defined. - * @param targetKey The property key for the target. + * @param propertyKey The property key for the target. * @returns `true` if the metadata entry was found and deleted; otherwise, false. * @example * @@ -1008,13 +1033,13 @@ namespace Reflect { * result = Reflect.deleteMetadata("custom:annotation", Example.prototype, "method"); * */ - export function deleteMetadata(metadataKey: any, target: any, targetKey: string | symbol): boolean; + export function deleteMetadata(metadataKey: any, target: any, propertyKey: string | symbol): boolean; /** * Deletes the metadata entry from the target object with the provided key. * @param metadataKey A key used to store and retrieve metadata. * @param target The target object on which the metadata is defined. - * @param targetKey (Optional) The property key for the target. + * @param propertyKey (Optional) The property key for the target. * @returns `true` if the metadata entry was found and deleted; otherwise, false. * @example * @@ -1044,16 +1069,15 @@ namespace Reflect { * result = Reflect.deleteMetadata("custom:annotation", Example.prototype, "method"); * */ - export function deleteMetadata(metadataKey: any, target: any, targetKey?: string | symbol): boolean { - // https://github.com/rbuckton/ReflectDecorators/blob/master/spec/metadata.md#deletemetadata-metadatakey-p- + export function deleteMetadata(metadataKey: any, target: any, propertyKey?: string | symbol): boolean { if (!IsObject(target)) throw new TypeError(); - if (!IsUndefined(targetKey)) targetKey = ToPropertyKey(targetKey); - const metadataMap = GetOrCreateMetadataMap(target, targetKey, /*create*/ false); + if (!IsUndefined(propertyKey)) propertyKey = ToPropertyKey(propertyKey); + const metadataMap = GetOrCreateMetadataMap(target, propertyKey, /*Create*/ false); if (IsUndefined(metadataMap)) return false; if (!metadataMap.delete(metadataKey)) return false; if (metadataMap.size > 0) return true; const targetMetadata = Metadata.get(target); - targetMetadata.delete(targetKey); + targetMetadata.delete(propertyKey); if (targetMetadata.size > 0) return true; Metadata.delete(target); return true; @@ -1083,14 +1107,8 @@ namespace Reflect { return descriptor; } - // Metadata Proposal - // https://github.com/rbuckton/ReflectDecorators/blob/master/spec/metadata.md - - // Operations on Objects - // https://github.com/rbuckton/ReflectDecorators/blob/master/spec/metadata.md#operations-on-objects - - // GetOrCreateMetadataMap(O, P, Create) - // https://github.com/rbuckton/ReflectDecorators/blob/master/spec/metadata.md#getorcreatemetadatamap--o-p-create- + // 2.1.1 GetOrCreateMetadataMap(O, P, Create) + // https://rbuckton.github.io/reflect-metadata/#getorcreatemetadatamap function GetOrCreateMetadataMap(O: any, P: string | symbol | undefined, Create: true): Map; function GetOrCreateMetadataMap(O: any, P: string | symbol | undefined, Create: false): Map | undefined; function GetOrCreateMetadataMap(O: any, P: string | symbol | undefined, Create: boolean): Map | undefined { @@ -1109,29 +1127,26 @@ namespace Reflect { return metadataMap; } - // Ordinary Object Internal Methods and Internal Slots - // https://github.com/rbuckton/ReflectDecorators/blob/master/spec/metadata.md#ordinary-object-internal-methods-and-internal-slots - - // OrdinaryHasMetadata(MetadataKey, O, P) - // https://github.com/rbuckton/ReflectDecorators/blob/master/spec/metadata.md#ordinaryhasmetadata--metadatakey-o-p- + // 3.1.1.1 OrdinaryHasMetadata(MetadataKey, O, P) + // https://rbuckton.github.io/reflect-metadata/#ordinaryhasmetadata function OrdinaryHasMetadata(MetadataKey: any, O: any, P: string | symbol | undefined): boolean { const hasOwn = OrdinaryHasOwnMetadata(MetadataKey, O, P); if (hasOwn) return true; const parent = OrdinaryGetPrototypeOf(O); - if (!IsNull(parent)) return OrdinaryHasMetadata(MetadataKey, parent, P); + if (!IsNull(parent)) OrdinaryHasMetadata(MetadataKey, parent, P); return false; } - // OrdinaryHasOwnMetadata(MetadataKey, O, P) - // https://github.com/rbuckton/ReflectDecorators/blob/master/spec/metadata.md#ordinaryhasownmetadata--metadatakey-o-p- + // 3.1.2.1 OrdinaryHasOwnMetadata(MetadataKey, O, P) + // https://rbuckton.github.io/reflect-metadata/#ordinaryhasownmetadata function OrdinaryHasOwnMetadata(MetadataKey: any, O: any, P: string | symbol | undefined): boolean { - const metadataMap = GetOrCreateMetadataMap(O, P, /*create*/ false); + const metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false); if (IsUndefined(metadataMap)) return false; return ToBoolean(metadataMap.has(MetadataKey)); } - // OrdinaryGetMetadata(MetadataKey, O, P) - // https://github.com/rbuckton/ReflectDecorators/blob/master/spec/metadata.md#ordinarygetmetadata--metadatakey-o-p- + // 3.1.3.1 OrdinaryGetMetadata(MetadataKey, O, P) + // https://rbuckton.github.io/reflect-metadata/#ordinarygetmetadata function OrdinaryGetMetadata(MetadataKey: any, O: any, P: string | symbol | undefined): any { const hasOwn = OrdinaryHasOwnMetadata(MetadataKey, O, P); if (hasOwn) return OrdinaryGetOwnMetadata(MetadataKey, O, P); @@ -1140,23 +1155,23 @@ namespace Reflect { return undefined; } - // OrdinaryGetOwnMetadata(MetadataKey, O, P) - // https://github.com/rbuckton/ReflectDecorators/blob/master/spec/metadata.md#ordinarygetownmetadata--metadatakey-o-p- + // 3.1.4.1 OrdinaryGetOwnMetadata(MetadataKey, O, P) + // https://rbuckton.github.io/reflect-metadata/#ordinarygetownmetadata function OrdinaryGetOwnMetadata(MetadataKey: any, O: any, P: string | symbol | undefined): any { - const metadataMap = GetOrCreateMetadataMap(O, P, /*create*/ false); + const metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false); if (IsUndefined(metadataMap)) return undefined; return metadataMap.get(MetadataKey); } - // OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P) - // https://github.com/rbuckton/ReflectDecorators/blob/master/spec/metadata.md#ordinarydefineownmetadata--metadatakey-metadatavalue-o-p- + // 3.1.5.1 OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P) + // https://rbuckton.github.io/reflect-metadata/#ordinarydefineownmetadata function OrdinaryDefineOwnMetadata(MetadataKey: any, MetadataValue: any, O: any, P: string | symbol | undefined): void { - const metadataMap = GetOrCreateMetadataMap(O, P, /*create*/ true); + const metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ true); metadataMap.set(MetadataKey, MetadataValue); } - // OrdinaryMetadataKeys(O, P) - // https://github.com/rbuckton/ReflectDecorators/blob/master/spec/metadata.md#ordinarymetadatakeys--o-p- + // 3.1.6.1 OrdinaryMetadataKeys(O, P) + // https://rbuckton.github.io/reflect-metadata/#ordinarymetadatakeys function OrdinaryMetadataKeys(O: any, P: string | symbol | undefined): any[] { const ownKeys = OrdinaryOwnMetadataKeys(O, P); const parent = OrdinaryGetPrototypeOf(O); @@ -1183,41 +1198,37 @@ namespace Reflect { return keys; } - // OrdinaryOwnMetadataKeys(O, P) - // https://github.com/rbuckton/ReflectDecorators/blob/master/spec/metadata.md#ordinaryownmetadatakeys--o-p- + // 3.1.7.1 OrdinaryOwnMetadataKeys(O, P) + // https://rbuckton.github.io/reflect-metadata/#ordinaryownmetadatakeys function OrdinaryOwnMetadataKeys(O: any, P: string | symbol | undefined): any[] { - const metadataMap = GetOrCreateMetadataMap(O, P, /*create*/ false); const keys: any[] = []; + const metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false); if (IsUndefined(metadataMap)) return keys; const keysObj = metadataMap.keys(); const iterator = GetIterator(keysObj); + let k = 0; while (true) { - let next = IteratorStep(iterator); + const next = IteratorStep(iterator); + if (!next) { + keys.length = k; + return keys; + } + const nextValue = IteratorValue(next); try { - if (!next) return keys; - const nextValue = IteratorValue(next); - keys.push(nextValue); + keys[k] = nextValue; } catch (e) { try { - if (next) { - next = false; - IteratorClose(iterator); - } + IteratorClose(iterator); } finally { throw e; } } - finally { - if (next) IteratorClose(iterator); - } + k++; } } - // ECMAScript Specification - // https://tc39.github.io/ecma262/ - // 6 ECMAScript Data Typ0es and Values // https://tc39.github.io/ecma262/#sec-ecmascript-data-types-and-values function Type(x: any): Tag { @@ -1370,6 +1381,16 @@ namespace Reflect { return typeof argument === "function"; } + // 7.2.7 IsPropertyKey(argument) + // https://tc39.github.io/ecma262/#sec-ispropertykey + function IsPropertyKey(argument: any): argument is string | symbol { + switch (Type(argument)) { + case Tag.String: return true; + case Tag.Symbol: return true; + default: return false; + } + } + // 7.3 Operations on Objects // https://tc39.github.io/ecma262/#sec-operations-on-objects @@ -1594,20 +1615,20 @@ namespace Reflect { return class WeakMap { private _key = CreateUniqueKey(); has(target: K): boolean { - const table = GetOrCreateWeakMapTable(target, /*create*/ false); + const table = GetOrCreateWeakMapTable(target, /*Create*/ false); return table !== undefined ? HashMap.has(table, this._key) : false; } get(target: K): V { - const table = GetOrCreateWeakMapTable(target, /*create*/ false); + const table = GetOrCreateWeakMapTable(target, /*Create*/ false); return table !== undefined ? HashMap.get(table, this._key) : undefined; } set(target: K, value: V): WeakMap { - const table = GetOrCreateWeakMapTable(target, /*create*/ true); + const table = GetOrCreateWeakMapTable(target, /*Create*/ true); table[this._key] = value; return this; } delete(target: K): boolean { - const table = GetOrCreateWeakMapTable(target, /*create*/ false); + const table = GetOrCreateWeakMapTable(target, /*Create*/ false); return table !== undefined ? delete table[this._key] : false; } clear(): void { diff --git a/bower.json b/bower.json index 03c038f..419973d 100644 --- a/bower.json +++ b/bower.json @@ -2,7 +2,7 @@ "name": "reflect-metadata", "version": "0.1.9", "description": "Polyfill for Metadata Reflection API", - "homepage": "https://github.com/rbuckton/ReflectDecorators", + "homepage": "https://github.com/rbuckton/reflect-metadata", "authors": [ "Ron Buckton " ], @@ -31,6 +31,6 @@ }, "repository": { "type": "git", - "url": "https://github.com/rbuckton/ReflectDecorators.git" + "url": "https://github.com/rbuckton/reflect-metadata.git" } } diff --git a/docs/index.html b/docs/index.html index b29794a..81e673a 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,6 +1,6 @@ -Metadata +Metadata Proposal - ECMAScript @@ -9,7 +9,7 @@ location.protocol = 'https:'; } -
+

Metadata Proposal - ECMAScriptlinkpin

@@ -1552,7 +1552,7 @@

3.1.1[[HasMetadata]] ( MetadataKey, P )

3.1.1.1OrdinaryHasMetadata ( MetadataKey, O, P )linkpin

When the abstract operation OrdinaryHasMetadata is called with ECMAScript language value MetadataKey, Object O, and property key P, the following steps are taken:

-
  1. Assert: P is undefined or IsPropertyKey(P) is true.
  2. Let hasOwn be ? OrdinaryHasOwnMetadata(MetadataKey, O, P).
  3. If hasOwn is true, return true.
  4. Let parent be ? O.[[GetPrototypeOf]]().
  5. If parent is not null, then
    1. Return ? parent.[[HasMetadata]](MetadataKey, P).
  6. Return false. +
    1. Assert: P is undefined or IsPropertyKey(P) is true.
    2. Let hasOwn be ? OrdinaryHasOwnMetadata(MetadataKey, O, P).
    3. If hasOwn is true, return true.
    4. Let parent be ? O.[[GetPrototypeOf]]().
    5. If parent is not null, Return ? parent.[[HasMetadata]](MetadataKey, P).
    6. Return false.
    @@ -1565,7 +1565,7 @@

    3.1.2[[HasOwnMetadata]] ( MetadataKey, P )

    3.1.2.1OrdinaryHasOwnMetadata ( MetadataKey, O, P )linkpin

    When the abstract operation OrdinaryHasOwnMetadata is called with ECMAScript language value MetadataKey, Object O, and property key P, the following steps are taken:

    -
    1. Assert: P is undefined or IsPropertyKey(P) is true.
    2. Let metadataMap be ? GetOrCreateMetadataMap(O, P, false).
    3. If metadataMap is undefined, return false.
    4. Return ? Invoke(metadataMap, "has", MetadataKey). +
      1. Assert: P is undefined or IsPropertyKey(P) is true.
      2. Let metadataMap be ? GetOrCreateMetadataMap(O, P, false).
      3. If metadataMap is undefined, return false.
      4. Return ? ToBoolean(? Invoke(metadataMap, "has", MetadataKey)).
      @@ -1578,7 +1578,7 @@

      3.1.3[[GetMetadata]] ( MetadataKey, P )

      3.1.3.1OrdinaryGetMetadata ( MetadataKey, O, P )linkpin

      When the abstract operation OrdinaryGetMetadata is called with ECMAScript language value MetadataKey, Object O, and property key P, the following steps are taken:

      -
      1. Assert: P is undefined or IsPropertyKey(P) is true.
      2. Let hasOwn be ? OrdinaryHasOwnMetadata(MetadataKey, O, P).
      3. If hasOwn is true, then
        1. Return ? OrdinaryGetOwnMetadata(MetadataKey, O, P).
      4. Let parent be ? O.[[GetPrototypeOf]]().
      5. If parent is not null, then
        1. return ? parent.[[GetMetadata]](MetadataKey, P).
      6. Return undefined. +
        1. Assert: P is undefined or IsPropertyKey(P) is true.
        2. Let hasOwn be ? OrdinaryHasOwnMetadata(MetadataKey, O, P).
        3. If hasOwn is true, return ? OrdinaryGetOwnMetadata(MetadataKey, O, P).
        4. Let parent be ? O.[[GetPrototypeOf]]().
        5. If parent is not null, return ? parent.[[GetMetadata]](MetadataKey, P).
        6. Return undefined.
        @@ -1666,56 +1666,56 @@

        4.1.2Reflect.metadata ( metadataKey, metadataVal -

        4.1.3Reflect.defineMetadata ( metadataKey, metadataValue, target, propertyKey )linkpin

        +

        4.1.3Reflect.defineMetadata ( metadataKey, metadataValue, target [, propertyKey] )linkpin

        When the defineMetadata function is called with arguments metadataKey, metadataValue, target, and propertyKey, the following steps are taken:

        1. If Type(target) is not Object, throw a TypeError exception.
        2. Return ? target.[[DefineMetadata]](metadataKey, metadataValue, propertyKey).
        -

        4.1.4Reflect.hasMetadata ( metadataKey, target, propertyKey )linkpin

        +

        4.1.4Reflect.hasMetadata ( metadataKey, target [, propertyKey] )linkpin

        When the hasMetadata function is called with arguments metadataKey, target, and propertyKey, the following steps are taken:

        1. If Type(target) is not Object, throw a TypeError exception.
        2. Return ? target.[[HasMetadata]](metadataKey, propertyKey).
        -

        4.1.5Reflect.hasOwnMetadata ( metadataKey, target, propertyKey )linkpin

        +

        4.1.5Reflect.hasOwnMetadata ( metadataKey, target [, propertyKey] )linkpin

        When the hasOwnMetadata function is called with arguments metadataKey, target, and propertyKey, the following steps are taken:

        1. If Type(target) is not Object, throw a TypeError exception.
        2. Return ? target.[[HasOwn]](metadataKey, propertyKey).
        -

        4.1.6Reflect.getMetadata ( metadataKey, target, propertyKey )linkpin

        +

        4.1.6Reflect.getMetadata ( metadataKey, target [, propertyKey] )linkpin

        When the getMetadata function is called with arguments metadataKey, target, and propertyKey, the following steps are taken:

        1. If Type(target) is not Object, throw a TypeError exception.
        2. Return ? target.[[GetMetadata]](metadataKey, propertyKey).
        -

        4.1.7Reflect.getOwnMetadata ( metadataKey, target, propertyKey )linkpin

        +

        4.1.7Reflect.getOwnMetadata ( metadataKey, target [, propertyKey] )linkpin

        When the getOwnMetadata function is called with arguments metadataKey, target, and propertyKey, the following steps are taken:

        1. If Type(target) is not Object, throw a TypeError exception.
        2. Return ? target.[[GetOwnMetadata]](metadataKey, propertyKey).
        -

        4.1.8Reflect.getMetadataKeys ( target, propertyKey )linkpin

        +

        4.1.8Reflect.getMetadataKeys ( target [, propertyKey] )linkpin

        When the getMetadataKeys function is called with arguments target and propertyKey, the following steps are taken:

        1. If Type(target) is not Object, throw a TypeError exception.
        2. Return ? target.[[GetMetadataKeys]](propertyKey).
        -

        4.1.9Reflect.getOwnMetadataKeys ( target, propertyKey )linkpin

        +

        4.1.9Reflect.getOwnMetadataKeys ( target [, propertyKey] )linkpin

        When the getOwnMetadataKeys function is called with arguments target and propertyKey, the following steps are taken:

        1. If Type(target) is not Object, throw a TypeError exception.
        2. Return ? target.[[GetOwnMetadataKeys]](propertyKey).
        -

        4.1.10Reflect.deleteMetadata ( metadataKey, target, propertyKey )linkpin

        +

        4.1.10Reflect.deleteMetadata ( metadataKey, target [, propertyKey] )linkpin

        When the deleteMetadata function is called with arguments metadataKey, target, and propertyKey, the following steps are taken:

        1. If Type(target) is not Object, throw a TypeError exception.
        2. Return ? target.[[DeleteMetadata]](metadataKey, propertyKey).
        diff --git a/docs/spec.biblio.json b/docs/spec.biblio.json index 7397632..10a8ac9 100644 --- a/docs/spec.biblio.json +++ b/docs/spec.biblio.json @@ -1 +1 @@ -{"https://rbuckton.github.io/ReflectDecorators":[{"type":"clause","id":"introduction","aoid":null,"title":"Metadata Proposal - ECMAScript","titleHTML":"Metadata Proposal - ECMAScript","number":"","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"Metadata Proposal - ECMAScript"},{"type":"clause","id":"syntax","aoid":null,"title":"Syntax","titleHTML":"Syntax","number":"1","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"Syntax"},{"type":"op","aoid":"GetOrCreateMetadataMap","refId":"getorcreatemetadatamap","location":"","key":"GetOrCreateMetadataMap"},{"type":"clause","id":"getorcreatemetadatamap","aoid":"GetOrCreateMetadataMap","title":"GetOrCreateMetadataMap ( O, P, Create )","titleHTML":"GetOrCreateMetadataMap ( O, P, Create )","number":"2.1.1","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"GetOrCreateMetadataMap ( O, P, Create )"},{"type":"clause","id":"operations-on-objects","aoid":null,"title":"Operations on Objects","titleHTML":"Operations on Objects","number":"2.1","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"Operations on Objects"},{"type":"clause","id":"abstract-operations","aoid":null,"title":"Abstract Operations","titleHTML":"Abstract Operations","number":"2","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"Abstract Operations"},{"type":"op","aoid":"OrdinaryHasMetadata","refId":"ordinaryhasmetadata","location":"","key":"OrdinaryHasMetadata"},{"type":"clause","id":"ordinaryhasmetadata","aoid":"OrdinaryHasMetadata","title":"OrdinaryHasMetadata ( MetadataKey, O, P )","titleHTML":"OrdinaryHasMetadata ( MetadataKey, O, P )","number":"3.1.1.1","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"OrdinaryHasMetadata ( MetadataKey, O, P )"},{"type":"clause","id":"ordinary-object-internal-methods-and-internal-slots-hasmetadata","aoid":null,"title":"[[HasMetadata]] ( MetadataKey, P )","titleHTML":"[[HasMetadata]] ( MetadataKey, P )","number":"3.1.1","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"[[HasMetadata]] ( MetadataKey, P )"},{"type":"op","aoid":"OrdinaryHasOwnMetadata","refId":"ordinaryhasownmetadata","location":"","key":"OrdinaryHasOwnMetadata"},{"type":"clause","id":"ordinaryhasownmetadata","aoid":"OrdinaryHasOwnMetadata","title":"OrdinaryHasOwnMetadata ( MetadataKey, O, P )","titleHTML":"OrdinaryHasOwnMetadata ( MetadataKey, O, P )","number":"3.1.2.1","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"OrdinaryHasOwnMetadata ( MetadataKey, O, P )"},{"type":"clause","id":"ordinary-object-internal-methods-and-internal-slots-hasownmetadata","aoid":null,"title":"[[HasOwnMetadata]] ( MetadataKey, P )","titleHTML":"[[HasOwnMetadata]] ( MetadataKey, P )","number":"3.1.2","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"[[HasOwnMetadata]] ( MetadataKey, P )"},{"type":"op","aoid":"OrdinaryGetMetadata","refId":"ordinarygetmetadata","location":"","key":"OrdinaryGetMetadata"},{"type":"clause","id":"ordinarygetmetadata","aoid":"OrdinaryGetMetadata","title":"OrdinaryGetMetadata ( MetadataKey, O, P )","titleHTML":"OrdinaryGetMetadata ( MetadataKey, O, P )","number":"3.1.3.1","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"OrdinaryGetMetadata ( MetadataKey, O, P )"},{"type":"clause","id":"ordinary-object-internal-methods-and-internal-slots-getmetadata","aoid":null,"title":"[[GetMetadata]] ( MetadataKey, P )","titleHTML":"[[GetMetadata]] ( MetadataKey, P )","number":"3.1.3","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"[[GetMetadata]] ( MetadataKey, P )"},{"type":"op","aoid":"OrdinaryGetOwnMetadata","refId":"ordinarygetownmetadata","location":"","key":"OrdinaryGetOwnMetadata"},{"type":"clause","id":"ordinarygetownmetadata","aoid":"OrdinaryGetOwnMetadata","title":"OrdinaryGetOwnMetadata ( MetadataKey, O, P )","titleHTML":"OrdinaryGetOwnMetadata ( MetadataKey, O, P )","number":"3.1.4.1","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"OrdinaryGetOwnMetadata ( MetadataKey, O, P )"},{"type":"clause","id":"ordinary-object-internal-methods-and-internal-slots-getownmetadata","aoid":null,"title":"[[GetOwnMetadata]] ( MetadataKey, P, ParamIndex )","titleHTML":"[[GetOwnMetadata]] ( MetadataKey, P, ParamIndex )","number":"3.1.4","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"[[GetOwnMetadata]] ( MetadataKey, P, ParamIndex )"},{"type":"op","aoid":"OrdinaryDefineOwnMetadata","refId":"ordinarydefineownmetadata","location":"","key":"OrdinaryDefineOwnMetadata"},{"type":"clause","id":"ordinarydefineownmetadata","aoid":"OrdinaryDefineOwnMetadata","title":"OrdinaryDefineOwnMetadata ( MetadataKey, MetadataValue, O, P )","titleHTML":"OrdinaryDefineOwnMetadata ( MetadataKey, MetadataValue, O, P )","number":"3.1.5.1","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"OrdinaryDefineOwnMetadata ( MetadataKey, MetadataValue, O, P )"},{"type":"clause","id":"ordinary-object-internal-methods-and-internal-slots-defineownmetadata","aoid":null,"title":"[[DefineOwnMetadata]] ( MetadataKey, MetadataValue, P )","titleHTML":"[[DefineOwnMetadata]] ( MetadataKey, MetadataValue, P )","number":"3.1.5","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"[[DefineOwnMetadata]] ( MetadataKey, MetadataValue, P )"},{"type":"op","aoid":"OrdinaryMetadataKeys","refId":"ordinarymetadatakeys","location":"","key":"OrdinaryMetadataKeys"},{"type":"clause","id":"ordinarymetadatakeys","aoid":"OrdinaryMetadataKeys","title":"OrdinaryMetadataKeys ( O, P )","titleHTML":"OrdinaryMetadataKeys ( O, P )","number":"3.1.6.1","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"OrdinaryMetadataKeys ( O, P )"},{"type":"clause","id":"ordinary-object-internal-methods-and-internal-slots-metadatakeys","aoid":null,"title":"[[MetadataKeys]] ( P )","titleHTML":"[[MetadataKeys]] ( P )","number":"3.1.6","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"[[MetadataKeys]] ( P )"},{"type":"op","aoid":"OrdinaryOwnMetadataKeys","refId":"ordinaryownmetadatakeys","location":"","key":"OrdinaryOwnMetadataKeys"},{"type":"clause","id":"ordinaryownmetadatakeys","aoid":"OrdinaryOwnMetadataKeys","title":"OrdinaryOwnMetadataKeys ( O, P )","titleHTML":"OrdinaryOwnMetadataKeys ( O, P )","number":"3.1.7.1","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"OrdinaryOwnMetadataKeys ( O, P )"},{"type":"clause","id":"ordinary-object-internal-methods-and-internal-slots-ownmetadatakeys","aoid":null,"title":"[[OwnMetadataKeys]] ( P )","titleHTML":"[[OwnMetadataKeys]] ( P )","number":"3.1.7","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"[[OwnMetadataKeys]] ( P )"},{"type":"clause","id":"ordinary-object-internal-methods-and-internal-slots-deletemetadata","aoid":null,"title":"[[DeleteMetadata]]( MetadataKey, P )","titleHTML":"[[DeleteMetadata]]( MetadataKey, P )","number":"3.1.8","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"[[DeleteMetadata]]( MetadataKey, P )"},{"type":"clause","id":"ordinary-object-internal-methods-and-internal-slots","aoid":null,"title":"Ordinary Object Internal Methods and Internal Slots","titleHTML":"Ordinary Object Internal Methods and Internal Slots","number":"3.1","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"Ordinary Object Internal Methods and Internal Slots"},{"type":"clause","id":"ordinary-and-exotic-objects-behaviors","aoid":null,"title":"Ordinary and Exotic Objects Behaviors","titleHTML":"Ordinary and Exotic Objects Behaviors","number":"3","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"Ordinary and Exotic Objects Behaviors"},{"type":"clause","id":"reflect-metadatadecoratorfunctions","aoid":null,"title":"Metadata Decorator Functions","titleHTML":"Metadata Decorator Functions","number":"4.1.1","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"Metadata Decorator Functions"},{"type":"clause","id":"reflect.metadata","aoid":null,"title":"Reflect.metadata ( metadataKey, metadataValue )","titleHTML":"Reflect.metadata ( metadataKey, metadataValue )","number":"4.1.2","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"Reflect.metadata ( metadataKey, metadataValue )"},{"type":"clause","id":"reflect.definemetadata","aoid":null,"title":"Reflect.defineMetadata ( metadataKey, metadataValue, target, propertyKey )","titleHTML":"Reflect.defineMetadata ( metadataKey, metadataValue, target, propertyKey )","number":"4.1.3","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"Reflect.defineMetadata ( metadataKey, metadataValue, target, propertyKey )"},{"type":"clause","id":"reflect.hasmetadata","aoid":null,"title":"Reflect.hasMetadata ( metadataKey, target, propertyKey )","titleHTML":"Reflect.hasMetadata ( metadataKey, target, propertyKey )","number":"4.1.4","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"Reflect.hasMetadata ( metadataKey, target, propertyKey )"},{"type":"clause","id":"reflect-hasownmetadata","aoid":null,"title":"Reflect.hasOwnMetadata ( metadataKey, target, propertyKey )","titleHTML":"Reflect.hasOwnMetadata ( metadataKey, target, propertyKey )","number":"4.1.5","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"Reflect.hasOwnMetadata ( metadataKey, target, propertyKey )"},{"type":"clause","id":"reflect-getmetadata","aoid":null,"title":"Reflect.getMetadata ( metadataKey, target, propertyKey )","titleHTML":"Reflect.getMetadata ( metadataKey, target, propertyKey )","number":"4.1.6","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"Reflect.getMetadata ( metadataKey, target, propertyKey )"},{"type":"clause","id":"reflect-getownmetadata","aoid":null,"title":"Reflect.getOwnMetadata ( metadataKey, target, propertyKey )","titleHTML":"Reflect.getOwnMetadata ( metadataKey, target, propertyKey )","number":"4.1.7","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"Reflect.getOwnMetadata ( metadataKey, target, propertyKey )"},{"type":"clause","id":"reflect-getmetadatakeys","aoid":null,"title":"Reflect.getMetadataKeys ( target, propertyKey )","titleHTML":"Reflect.getMetadataKeys ( target, propertyKey )","number":"4.1.8","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"Reflect.getMetadataKeys ( target, propertyKey )"},{"type":"clause","id":"reflect-getownmetadata","aoid":null,"title":"Reflect.getOwnMetadataKeys ( target, propertyKey )","titleHTML":"Reflect.getOwnMetadataKeys ( target, propertyKey )","number":"4.1.9","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"Reflect.getOwnMetadataKeys ( target, propertyKey )"},{"type":"clause","id":"reflect-deletemetadata","aoid":null,"title":"Reflect.deleteMetadata ( metadataKey, target, propertyKey )","titleHTML":"Reflect.deleteMetadata ( metadataKey, target, propertyKey )","number":"4.1.10","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"Reflect.deleteMetadata ( metadataKey, target, propertyKey )"},{"type":"clause","id":"reflect","aoid":null,"title":"The Reflect Object","titleHTML":"The Reflect Object","number":"4.1","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"The Reflect Object"},{"type":"clause","id":"reflection","aoid":null,"title":"Reflection","titleHTML":"Reflection","number":"4","namespace":"https://rbuckton.github.io/ReflectDecorators","location":"","key":"Reflection"}]} \ No newline at end of file +{"https://rbuckton.github.io/reflect-metadata":[{"type":"clause","id":"introduction","aoid":null,"title":"Metadata Proposal - ECMAScript","titleHTML":"Metadata Proposal - ECMAScript","number":"","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"Metadata Proposal - ECMAScript"},{"type":"clause","id":"syntax","aoid":null,"title":"Syntax","titleHTML":"Syntax","number":"1","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"Syntax"},{"type":"op","aoid":"GetOrCreateMetadataMap","refId":"getorcreatemetadatamap","location":"","key":"GetOrCreateMetadataMap"},{"type":"clause","id":"getorcreatemetadatamap","aoid":"GetOrCreateMetadataMap","title":"GetOrCreateMetadataMap ( O, P, Create )","titleHTML":"GetOrCreateMetadataMap ( O, P, Create )","number":"2.1.1","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"GetOrCreateMetadataMap ( O, P, Create )"},{"type":"clause","id":"operations-on-objects","aoid":null,"title":"Operations on Objects","titleHTML":"Operations on Objects","number":"2.1","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"Operations on Objects"},{"type":"clause","id":"abstract-operations","aoid":null,"title":"Abstract Operations","titleHTML":"Abstract Operations","number":"2","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"Abstract Operations"},{"type":"op","aoid":"OrdinaryHasMetadata","refId":"ordinaryhasmetadata","location":"","key":"OrdinaryHasMetadata"},{"type":"clause","id":"ordinaryhasmetadata","aoid":"OrdinaryHasMetadata","title":"OrdinaryHasMetadata ( MetadataKey, O, P )","titleHTML":"OrdinaryHasMetadata ( MetadataKey, O, P )","number":"3.1.1.1","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"OrdinaryHasMetadata ( MetadataKey, O, P )"},{"type":"clause","id":"ordinary-object-internal-methods-and-internal-slots-hasmetadata","aoid":null,"title":"[[HasMetadata]] ( MetadataKey, P )","titleHTML":"[[HasMetadata]] ( MetadataKey, P )","number":"3.1.1","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"[[HasMetadata]] ( MetadataKey, P )"},{"type":"op","aoid":"OrdinaryHasOwnMetadata","refId":"ordinaryhasownmetadata","location":"","key":"OrdinaryHasOwnMetadata"},{"type":"clause","id":"ordinaryhasownmetadata","aoid":"OrdinaryHasOwnMetadata","title":"OrdinaryHasOwnMetadata ( MetadataKey, O, P )","titleHTML":"OrdinaryHasOwnMetadata ( MetadataKey, O, P )","number":"3.1.2.1","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"OrdinaryHasOwnMetadata ( MetadataKey, O, P )"},{"type":"clause","id":"ordinary-object-internal-methods-and-internal-slots-hasownmetadata","aoid":null,"title":"[[HasOwnMetadata]] ( MetadataKey, P )","titleHTML":"[[HasOwnMetadata]] ( MetadataKey, P )","number":"3.1.2","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"[[HasOwnMetadata]] ( MetadataKey, P )"},{"type":"op","aoid":"OrdinaryGetMetadata","refId":"ordinarygetmetadata","location":"","key":"OrdinaryGetMetadata"},{"type":"clause","id":"ordinarygetmetadata","aoid":"OrdinaryGetMetadata","title":"OrdinaryGetMetadata ( MetadataKey, O, P )","titleHTML":"OrdinaryGetMetadata ( MetadataKey, O, P )","number":"3.1.3.1","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"OrdinaryGetMetadata ( MetadataKey, O, P )"},{"type":"clause","id":"ordinary-object-internal-methods-and-internal-slots-getmetadata","aoid":null,"title":"[[GetMetadata]] ( MetadataKey, P )","titleHTML":"[[GetMetadata]] ( MetadataKey, P )","number":"3.1.3","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"[[GetMetadata]] ( MetadataKey, P )"},{"type":"op","aoid":"OrdinaryGetOwnMetadata","refId":"ordinarygetownmetadata","location":"","key":"OrdinaryGetOwnMetadata"},{"type":"clause","id":"ordinarygetownmetadata","aoid":"OrdinaryGetOwnMetadata","title":"OrdinaryGetOwnMetadata ( MetadataKey, O, P )","titleHTML":"OrdinaryGetOwnMetadata ( MetadataKey, O, P )","number":"3.1.4.1","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"OrdinaryGetOwnMetadata ( MetadataKey, O, P )"},{"type":"clause","id":"ordinary-object-internal-methods-and-internal-slots-getownmetadata","aoid":null,"title":"[[GetOwnMetadata]] ( MetadataKey, P, ParamIndex )","titleHTML":"[[GetOwnMetadata]] ( MetadataKey, P, ParamIndex )","number":"3.1.4","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"[[GetOwnMetadata]] ( MetadataKey, P, ParamIndex )"},{"type":"op","aoid":"OrdinaryDefineOwnMetadata","refId":"ordinarydefineownmetadata","location":"","key":"OrdinaryDefineOwnMetadata"},{"type":"clause","id":"ordinarydefineownmetadata","aoid":"OrdinaryDefineOwnMetadata","title":"OrdinaryDefineOwnMetadata ( MetadataKey, MetadataValue, O, P )","titleHTML":"OrdinaryDefineOwnMetadata ( MetadataKey, MetadataValue, O, P )","number":"3.1.5.1","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"OrdinaryDefineOwnMetadata ( MetadataKey, MetadataValue, O, P )"},{"type":"clause","id":"ordinary-object-internal-methods-and-internal-slots-defineownmetadata","aoid":null,"title":"[[DefineOwnMetadata]] ( MetadataKey, MetadataValue, P )","titleHTML":"[[DefineOwnMetadata]] ( MetadataKey, MetadataValue, P )","number":"3.1.5","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"[[DefineOwnMetadata]] ( MetadataKey, MetadataValue, P )"},{"type":"op","aoid":"OrdinaryMetadataKeys","refId":"ordinarymetadatakeys","location":"","key":"OrdinaryMetadataKeys"},{"type":"clause","id":"ordinarymetadatakeys","aoid":"OrdinaryMetadataKeys","title":"OrdinaryMetadataKeys ( O, P )","titleHTML":"OrdinaryMetadataKeys ( O, P )","number":"3.1.6.1","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"OrdinaryMetadataKeys ( O, P )"},{"type":"clause","id":"ordinary-object-internal-methods-and-internal-slots-metadatakeys","aoid":null,"title":"[[MetadataKeys]] ( P )","titleHTML":"[[MetadataKeys]] ( P )","number":"3.1.6","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"[[MetadataKeys]] ( P )"},{"type":"op","aoid":"OrdinaryOwnMetadataKeys","refId":"ordinaryownmetadatakeys","location":"","key":"OrdinaryOwnMetadataKeys"},{"type":"clause","id":"ordinaryownmetadatakeys","aoid":"OrdinaryOwnMetadataKeys","title":"OrdinaryOwnMetadataKeys ( O, P )","titleHTML":"OrdinaryOwnMetadataKeys ( O, P )","number":"3.1.7.1","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"OrdinaryOwnMetadataKeys ( O, P )"},{"type":"clause","id":"ordinary-object-internal-methods-and-internal-slots-ownmetadatakeys","aoid":null,"title":"[[OwnMetadataKeys]] ( P )","titleHTML":"[[OwnMetadataKeys]] ( P )","number":"3.1.7","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"[[OwnMetadataKeys]] ( P )"},{"type":"clause","id":"ordinary-object-internal-methods-and-internal-slots-deletemetadata","aoid":null,"title":"[[DeleteMetadata]]( MetadataKey, P )","titleHTML":"[[DeleteMetadata]]( MetadataKey, P )","number":"3.1.8","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"[[DeleteMetadata]]( MetadataKey, P )"},{"type":"clause","id":"ordinary-object-internal-methods-and-internal-slots","aoid":null,"title":"Ordinary Object Internal Methods and Internal Slots","titleHTML":"Ordinary Object Internal Methods and Internal Slots","number":"3.1","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"Ordinary Object Internal Methods and Internal Slots"},{"type":"clause","id":"ordinary-and-exotic-objects-behaviors","aoid":null,"title":"Ordinary and Exotic Objects Behaviors","titleHTML":"Ordinary and Exotic Objects Behaviors","number":"3","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"Ordinary and Exotic Objects Behaviors"},{"type":"clause","id":"reflect-metadatadecoratorfunctions","aoid":null,"title":"Metadata Decorator Functions","titleHTML":"Metadata Decorator Functions","number":"4.1.1","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"Metadata Decorator Functions"},{"type":"clause","id":"reflect.metadata","aoid":null,"title":"Reflect.metadata ( metadataKey, metadataValue )","titleHTML":"Reflect.metadata ( metadataKey, metadataValue )","number":"4.1.2","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"Reflect.metadata ( metadataKey, metadataValue )"},{"type":"clause","id":"reflect.definemetadata","aoid":null,"title":"Reflect.defineMetadata ( metadataKey, metadataValue, target [, propertyKey] )","titleHTML":"Reflect.defineMetadata ( metadataKey, metadataValue, target [, propertyKey] )","number":"4.1.3","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"Reflect.defineMetadata ( metadataKey, metadataValue, target [, propertyKey] )"},{"type":"clause","id":"reflect.hasmetadata","aoid":null,"title":"Reflect.hasMetadata ( metadataKey, target [, propertyKey] )","titleHTML":"Reflect.hasMetadata ( metadataKey, target [, propertyKey] )","number":"4.1.4","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"Reflect.hasMetadata ( metadataKey, target [, propertyKey] )"},{"type":"clause","id":"reflect-hasownmetadata","aoid":null,"title":"Reflect.hasOwnMetadata ( metadataKey, target [, propertyKey] )","titleHTML":"Reflect.hasOwnMetadata ( metadataKey, target [, propertyKey] )","number":"4.1.5","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"Reflect.hasOwnMetadata ( metadataKey, target [, propertyKey] )"},{"type":"clause","id":"reflect-getmetadata","aoid":null,"title":"Reflect.getMetadata ( metadataKey, target [, propertyKey] )","titleHTML":"Reflect.getMetadata ( metadataKey, target [, propertyKey] )","number":"4.1.6","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"Reflect.getMetadata ( metadataKey, target [, propertyKey] )"},{"type":"clause","id":"reflect-getownmetadata","aoid":null,"title":"Reflect.getOwnMetadata ( metadataKey, target [, propertyKey] )","titleHTML":"Reflect.getOwnMetadata ( metadataKey, target [, propertyKey] )","number":"4.1.7","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"Reflect.getOwnMetadata ( metadataKey, target [, propertyKey] )"},{"type":"clause","id":"reflect-getmetadatakeys","aoid":null,"title":"Reflect.getMetadataKeys ( target [, propertyKey] )","titleHTML":"Reflect.getMetadataKeys ( target [, propertyKey] )","number":"4.1.8","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"Reflect.getMetadataKeys ( target [, propertyKey] )"},{"type":"clause","id":"reflect-getownmetadata","aoid":null,"title":"Reflect.getOwnMetadataKeys ( target [, propertyKey] )","titleHTML":"Reflect.getOwnMetadataKeys ( target [, propertyKey] )","number":"4.1.9","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"Reflect.getOwnMetadataKeys ( target [, propertyKey] )"},{"type":"clause","id":"reflect-deletemetadata","aoid":null,"title":"Reflect.deleteMetadata ( metadataKey, target [, propertyKey] )","titleHTML":"Reflect.deleteMetadata ( metadataKey, target [, propertyKey] )","number":"4.1.10","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"Reflect.deleteMetadata ( metadataKey, target [, propertyKey] )"},{"type":"clause","id":"reflect","aoid":null,"title":"The Reflect Object","titleHTML":"The Reflect Object","number":"4.1","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"The Reflect Object"},{"type":"clause","id":"reflection","aoid":null,"title":"Reflection","titleHTML":"Reflection","number":"4","namespace":"https://rbuckton.github.io/reflect-metadata","location":"","key":"Reflection"}]} \ No newline at end of file diff --git a/index.d.ts b/index.d.ts index 1244744..47fc8c5 100644 --- a/index.d.ts +++ b/index.d.ts @@ -37,8 +37,8 @@ declare global { * Applies a set of decorators to a property of a target object. * @param decorators An array of decorators. * @param target The target object. - * @param targetKey The property key to decorate. - * @param descriptor A property descriptor + * @param propertyKey The property key to decorate. + * @param attributes A property descriptor. * @remarks Decorators are applied in reverse order. * @example * @@ -68,7 +68,7 @@ declare global { * Object.getOwnPropertyDescriptor(Example.prototype, "method"))); * */ - function decorate(decorators: (PropertyDecorator | MethodDecorator)[], target: Object, targetKey: string | symbol, descriptor?: PropertyDescriptor): PropertyDescriptor; + function decorate(decorators: (PropertyDecorator | MethodDecorator)[], target: Object, propertyKey: string | symbol, attributes?: PropertyDescriptor): PropertyDescriptor; /** * A default metadata decorator factory that can be used on a class, class member, or parameter. * @param metadataKey The key for the metadata entry. @@ -111,7 +111,7 @@ declare global { */ function metadata(metadataKey: any, metadataValue: any): { (target: Function): void; - (target: Object, targetKey: string | symbol): void; + (target: Object, propertyKey: string | symbol): void; }; /** * Define a unique metadata entry on the target. @@ -138,7 +138,7 @@ declare global { * @param metadataKey A key used to store and retrieve metadata. * @param metadataValue A value that contains attached metadata. * @param target The target object on which to define metadata. - * @param targetKey The property key for the target. + * @param propertyKey The property key for the target. * @example * * class Example { @@ -168,7 +168,7 @@ declare global { * } * */ - function defineMetadata(metadataKey: any, metadataValue: any, target: Object, targetKey: string | symbol): void; + function defineMetadata(metadataKey: any, metadataValue: any, target: Object, propertyKey: string | symbol): void; /** * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined. * @param metadataKey A key used to store and retrieve metadata. @@ -188,7 +188,7 @@ declare global { * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined. * @param metadataKey A key used to store and retrieve metadata. * @param target The target object on which the metadata is defined. - * @param targetKey The property key for the target. + * @param propertyKey The property key for the target. * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`. * @example * @@ -214,7 +214,7 @@ declare global { * result = Reflect.hasMetadata("custom:annotation", Example.prototype, "method"); * */ - function hasMetadata(metadataKey: any, target: Object, targetKey: string | symbol): boolean; + function hasMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): boolean; /** * Gets a value indicating whether the target object has the provided metadata key defined. * @param metadataKey A key used to store and retrieve metadata. @@ -234,7 +234,7 @@ declare global { * Gets a value indicating whether the target object has the provided metadata key defined. * @param metadataKey A key used to store and retrieve metadata. * @param target The target object on which the metadata is defined. - * @param targetKey The property key for the target. + * @param propertyKey The property key for the target. * @returns `true` if the metadata key was defined on the target object; otherwise, `false`. * @example * @@ -260,7 +260,7 @@ declare global { * result = Reflect.hasOwnMetadata("custom:annotation", Example.prototype, "method"); * */ - function hasOwnMetadata(metadataKey: any, target: Object, targetKey: string | symbol): boolean; + function hasOwnMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): boolean; /** * Gets the metadata value for the provided metadata key on the target object or its prototype chain. * @param metadataKey A key used to store and retrieve metadata. @@ -280,7 +280,7 @@ declare global { * Gets the metadata value for the provided metadata key on the target object or its prototype chain. * @param metadataKey A key used to store and retrieve metadata. * @param target The target object on which the metadata is defined. - * @param targetKey The property key for the target. + * @param propertyKey The property key for the target. * @returns The metadata value for the metadata key if found; otherwise, `undefined`. * @example * @@ -306,7 +306,7 @@ declare global { * result = Reflect.getMetadata("custom:annotation", Example.prototype, "method"); * */ - function getMetadata(metadataKey: any, target: Object, targetKey: string | symbol): any; + function getMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): any; /** * Gets the metadata value for the provided metadata key on the target object. * @param metadataKey A key used to store and retrieve metadata. @@ -326,7 +326,7 @@ declare global { * Gets the metadata value for the provided metadata key on the target object. * @param metadataKey A key used to store and retrieve metadata. * @param target The target object on which the metadata is defined. - * @param targetKey The property key for the target. + * @param propertyKey The property key for the target. * @returns The metadata value for the metadata key if found; otherwise, `undefined`. * @example * @@ -352,7 +352,7 @@ declare global { * result = Reflect.getOwnMetadata("custom:annotation", Example.prototype, "method"); * */ - function getOwnMetadata(metadataKey: any, target: Object, targetKey: string | symbol): any; + function getOwnMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): any; /** * Gets the metadata keys defined on the target object or its prototype chain. * @param target The target object on which the metadata is defined. @@ -370,7 +370,7 @@ declare global { /** * Gets the metadata keys defined on the target object or its prototype chain. * @param target The target object on which the metadata is defined. - * @param targetKey The property key for the target. + * @param propertyKey The property key for the target. * @returns An array of unique metadata keys. * @example * @@ -396,7 +396,7 @@ declare global { * result = Reflect.getMetadataKeys(Example.prototype, "method"); * */ - function getMetadataKeys(target: Object, targetKey: string | symbol): any[]; + function getMetadataKeys(target: Object, propertyKey: string | symbol): any[]; /** * Gets the unique metadata keys defined on the target object. * @param target The target object on which the metadata is defined. @@ -414,7 +414,7 @@ declare global { /** * Gets the unique metadata keys defined on the target object. * @param target The target object on which the metadata is defined. - * @param targetKey The property key for the target. + * @param propertyKey The property key for the target. * @returns An array of unique metadata keys. * @example * @@ -440,7 +440,7 @@ declare global { * result = Reflect.getOwnMetadataKeys(Example.prototype, "method"); * */ - function getOwnMetadataKeys(target: Object, targetKey: string | symbol): any[]; + function getOwnMetadataKeys(target: Object, propertyKey: string | symbol): any[]; /** * Deletes the metadata entry from the target object with the provided key. * @param metadataKey A key used to store and retrieve metadata. @@ -460,7 +460,7 @@ declare global { * Deletes the metadata entry from the target object with the provided key. * @param metadataKey A key used to store and retrieve metadata. * @param target The target object on which the metadata is defined. - * @param targetKey The property key for the target. + * @param propertyKey The property key for the target. * @returns `true` if the metadata entry was found and deleted; otherwise, false. * @example * @@ -486,6 +486,6 @@ declare global { * result = Reflect.deleteMetadata("custom:annotation", Example.prototype, "method"); * */ - function deleteMetadata(metadataKey: any, target: Object, targetKey: string | symbol): boolean; + function deleteMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): boolean; } } \ No newline at end of file diff --git a/package.json b/package.json index 2a73eb9..7421f0f 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ }, "repository": { "type": "git", - "url": "https://github.com/rbuckton/ReflectDecorators.git" + "url": "https://github.com/rbuckton/reflect-metadata.git" }, "keywords": [ "decorator", @@ -31,14 +31,14 @@ "licenses": [ { "license": "Apache-2.0", - "url": "http://github.com/rbuckton/ReflectDecorators/raw/master/LICENSE" + "url": "http://github.com/rbuckton/reflect-metadata/raw/master/LICENSE" } ], "license": "Apache-2.0", "bugs": { - "url": "https://github.com/rbuckton/ReflectDecorators/issues" + "url": "https://github.com/rbuckton/reflect-metadata/issues" }, - "homepage": "http://rbuckton.github.io/ReflectDecorators", + "homepage": "http://rbuckton.github.io/reflect-metadata", "dependencies": {}, "devDependencies": { "@types/chai": "^3.4.34", diff --git a/spec.html b/spec.html index a1ca641..7786b86 100644 --- a/spec.html +++ b/spec.html @@ -1,6 +1,6 @@  -Metadata +Metadata Proposal - ECMAScript @@ -12,7 +12,7 @@ @@ -140,8 +140,7 @@

        OrdinaryHasMetadata ( MetadataKey, O, P )

        2. Let _hasOwn_ be ? OrdinaryHasOwnMetadata(_MetadataKey_, _O_, _P_). 3. If _hasOwn_ is *true*, return *true*. 4. Let _parent_ be ? _O_.[[GetPrototypeOf]](). - 5. If _parent_ is not *null*, then - 1. Return ? _parent_.[[HasMetadata]](_MetadataKey_, _P_). + 5. If _parent_ is not *null*, Return ? _parent_.[[HasMetadata]](_MetadataKey_, _P_). 6. Return *false*.
        @@ -160,7 +159,7 @@

        OrdinaryHasOwnMetadata ( MetadataKey, O, P )

        1. Assert: _P_ is *undefined* or IsPropertyKey(_P_) is *true*. 2. Let _metadataMap_ be ? GetOrCreateMetadataMap(_O_, _P_, *false*). 3. If _metadataMap_ is *undefined*, return *false*. - 4. Return ? Invoke(_metadataMap_, `"has"`, _MetadataKey_). + 4. Return ? ToBoolean(? Invoke(_metadataMap_, `"has"`, _MetadataKey_)). @@ -177,11 +176,9 @@

        OrdinaryGetMetadata ( MetadataKey, O, P )

        1. Assert: _P_ is *undefined* or IsPropertyKey(_P_) is *true*. 2. Let _hasOwn_ be ? OrdinaryHasOwnMetadata(_MetadataKey_, _O_, _P_). - 3. If _hasOwn_ is *true*, then - 1. Return ? OrdinaryGetOwnMetadata(_MetadataKey_, _O_, _P_). + 3. If _hasOwn_ is *true*, return ? OrdinaryGetOwnMetadata(_MetadataKey_, _O_, _P_). 4. Let _parent_ be ? _O_.[[GetPrototypeOf]](). - 5. If _parent_ is not *null*, then - 1. return ? _parent_.[[GetMetadata]](_MetadataKey_, _P_). + 5. If _parent_ is not *null*, return ? _parent_.[[GetMetadata]](_MetadataKey_, _P_). 6. Return *undefined*. @@ -345,7 +342,7 @@

        Reflect.metadata ( metadataKey, metadataValue )

        -

        Reflect.defineMetadata ( metadataKey, metadataValue, target, propertyKey )

        +

        Reflect.defineMetadata ( metadataKey, metadataValue, target [, propertyKey] )

        When the `defineMetadata` function is called with arguments _metadataKey_, _metadataValue_, _target_, and _propertyKey_, the following steps are taken:

        1. If Type(_target_) is not Object, throw a *TypeError* exception. @@ -354,7 +351,7 @@

        Reflect.defineMetadata ( metadataKey, metadataValue, target, propertyKey ) -

        Reflect.hasMetadata ( metadataKey, target, propertyKey )

        +

        Reflect.hasMetadata ( metadataKey, target [, propertyKey] )

        When the `hasMetadata` function is called with arguments _metadataKey_, _target_, and _propertyKey_, the following steps are taken:

        1. If Type(_target_) is not Object, throw a *TypeError* exception. @@ -363,7 +360,7 @@

        Reflect.hasMetadata ( metadataKey, target, propertyKey )

        -

        Reflect.hasOwnMetadata ( metadataKey, target, propertyKey )

        +

        Reflect.hasOwnMetadata ( metadataKey, target [, propertyKey] )

        When the `hasOwnMetadata` function is called with arguments _metadataKey_, _target_, and _propertyKey_, the following steps are taken:

        1. If Type(_target_) is not Object, throw a *TypeError* exception. @@ -372,7 +369,7 @@

        Reflect.hasOwnMetadata ( metadataKey, target, propertyKey )

        -

        Reflect.getMetadata ( metadataKey, target, propertyKey )

        +

        Reflect.getMetadata ( metadataKey, target [, propertyKey] )

        When the `getMetadata` function is called with arguments _metadataKey_, _target_, and _propertyKey_, the following steps are taken:

        1. If Type(_target_) is not Object, throw a *TypeError* exception. @@ -381,7 +378,7 @@

        Reflect.getMetadata ( metadataKey, target, propertyKey )

        -

        Reflect.getOwnMetadata ( metadataKey, target, propertyKey )

        +

        Reflect.getOwnMetadata ( metadataKey, target [, propertyKey] )

        When the `getOwnMetadata` function is called with arguments _metadataKey_, _target_, and _propertyKey_, the following steps are taken:

        1. If Type(_target_) is not Object, throw a *TypeError* exception. @@ -390,7 +387,7 @@

        Reflect.getOwnMetadata ( metadataKey, target, propertyKey )

        -

        Reflect.getMetadataKeys ( target, propertyKey )

        +

        Reflect.getMetadataKeys ( target [, propertyKey] )

        When the `getMetadataKeys` function is called with arguments _target_ and _propertyKey_, the following steps are taken:

        1. If Type(_target_) is not Object, throw a *TypeError* exception. @@ -399,7 +396,7 @@

        Reflect.getMetadataKeys ( target, propertyKey )

        -

        Reflect.getOwnMetadataKeys ( target, propertyKey )

        +

        Reflect.getOwnMetadataKeys ( target [, propertyKey] )

        When the `getOwnMetadataKeys` function is called with arguments _target_ and _propertyKey_, the following steps are taken:

        1. If Type(_target_) is not Object, throw a *TypeError* exception. @@ -408,7 +405,7 @@

        Reflect.getOwnMetadataKeys ( target, propertyKey )

        -

        Reflect.deleteMetadata ( metadataKey, target, propertyKey )

        +

        Reflect.deleteMetadata ( metadataKey, target [, propertyKey] )

        When the `deleteMetadata` function is called with arguments _metadataKey_, _target_, and _propertyKey_, the following steps are taken:

        1. If Type(_target_) is not Object, throw a *TypeError* exception. diff --git a/spec/metadata.md b/spec/metadata.md index 3e15e0f..0bb6ab3 100644 --- a/spec/metadata.md +++ b/spec/metadata.md @@ -1,568 +1,3 @@ # Metadata Reflection API -> NOTE - This section is non-normative. - -*A shim for this API can be found here: https://github.com/rbuckton/ReflectDecorators.* - -## Syntax - -> NOTE - This section is non-normative. - -```JavaScript -// define metadata on an object or property -Reflect.defineMetadata(metadataKey, metadataValue, target); -Reflect.defineMetadata(metadataKey, metadataValue, target, propertyKey); - -// check for presence of a metadata key on the prototype chain of an object or property -let result = Reflect.hasMetadata(metadataKey, target); -let result = Reflect.hasMetadata(metadataKey, target, propertyKey); - -// check for presence of an own metadata key of an object or property -let result = Reflect.hasOwnMetadata(metadataKey, target); -let result = Reflect.hasOwnMetadata(metadataKey, target, propertyKey); - -// get metadata value of a metadata key on the prototype chain of an object or property -let result = Reflect.getMetadata(metadataKey, target); -let result = Reflect.getMetadata(metadataKey, target, propertyKey); - -// get metadata value of an own metadata key of an object or property -let result = Reflect.getOwnMetadata(metadataKey, target); -let result = Reflect.getOwnMetadata(metadataKey, target, propertyKey); - -// get all metadata keys on the prototype chain of an object or property -let result = Reflect.getMetadataKeys(target); -let result = Reflect.getMetadataKeys(target, propertyKey); - -// get all own metadata keys of an object or property -let result = Reflect.getOwnMetadataKeys(target); -let result = Reflect.getOwnMetadataKeys(target, propertyKey); - -// delete metadata from an object or property -let result = Reflect.deleteMetadata(metadataKey, target); -let result = Reflect.deleteMetadata(metadataKey, target, propertyKey); - -// apply metadata via a decorator to a constructor -@Reflect.metadata(metadataKey, metadataValue) -class C { - // apply metadata via a decorator to a method (property) - @Reflect.metadata(metadataKey, metadataValue) - method() { - } -} -``` - -## Examples - -> NOTE - This section is non-normative. - -```JavaScript -// Design-time type annotations -function Type(type) { return Reflect.metadata("design:type", type); } -function ParamTypes(...types) { return Reflect.metadata("design:paramtypes", types); } -function ReturnType(type) { return Reflect.metadata("design:returntype", type); } - -// Decorator application -@ParamTypes(String, Number) -class C { - constructor(text, i) { - } - - @Type(String) - get name() { return "text"; } - - @Type(Function) - @ParamTypes(Number, Number) - @ReturnType(Number) - add(x, y) { - return x + y; - } -} - -// Metadata introspection -let obj = new C("a", 1); -let paramTypes = Reflect.getMetadata("design:paramtypes", inst, "add"); // [Number, Number] -``` - -# Abstract Operations - -## Operations on Objects - -### GetOrCreateMetadataMap ( O, P, Create ) - -When the abstract operation GetOrCreateMetadataMap is called with Object O, [property key][] P, and Boolean Create the following steps are taken: - - 1. [Assert][]: P is **undefined** or [IsPropertyKey][](P) is **true**. - 2. Let targetMetadata be the value of O's \[\[Metadata\]\] [internal slot][]. - 3. If targetMetadata is **undefined**, then - 1. If Create is **false**, return **undefined**. - 2. Set targetMetadata to be a newly created **Map** object. - 3. Set the \[\[Metadata\]\] [internal slot][] of O to targetMetadata. - 4. Let metadataMap be [Invoke][](targetMetadata, `"get"`, P). - 5. [ReturnIfAbrupt][](metadataMap). - 6. If metadataMap is **undefined**, then - 1. If Create is **false**, return **undefined**. - 2. Set metadataMap to be a newly created **Map** object. - 3. Let setStatus be [Invoke][](targetMetadata, `"set"`, P, metadataMap). - 4. [ReturnIfAbrupt][](setStatus). - 7. Return metadataMap. - -# Ordinary and Exotic Objects Behaviours - -## Ordinary Object Internal Methods and Internal Slots - -All ordinary objects have an [internal slot][] called \[\[Metadata\]\]. The value of this [internal slot][] is either **null** or a **Map** object and is used for storing metadata for an object. - -### \[\[HasMetadata\]\] ( MetadataKey, P ) - -When the \[\[HasMetadata\]\] internal method of O is called with [ECMAScript language value][] MetadataKey and [property key][] P, the following steps are taken: - -1. Return [OrdinaryHasMetadata][](MetadataKey, O, P). - -### OrdinaryHasMetadata ( MetadataKey, O, P ) - -When the abstract operation OrdinaryHasMetadata is called with [ECMAScript language value][] MetadataKey, Object O, and [property key][] P, the following steps are taken: - -1. [Assert][]: P is **undefined** or [IsPropertyKey][](P) is **true**. -2. Let hasOwn be [OrdinaryHasOwnMetadata][](MetadataKey, O, P). -3. If hasOwn is **true**, return **true**. -4. Let parent be O.\[\[GetPrototypeOf\]\](). -5. [ReturnIfAbrupt][](parent). -6. If parent is not **null**, then - 1. return parent.\[\[HasMetadata\]\](MetadataKey, P). -7. Return **false**. - -### \[\[HasOwnMetadata\]\] ( MetadataKey, P ) - -When the \[\[HasOwnMetadata\]\] internal method of O is called with [ECMAScript language value][] MetadataKey and [property key][] P, the following steps are taken: - -1. Return [OrdinaryHasOwnMetadata][](MetadataKey, O, P). - -### OrdinaryHasOwnMetadata ( MetadataKey, O, P ) - -When the abstract operation OrdinaryHasOwnMetadata is called with [ECMAScript language value][] MetadataKey, Object O, and [property key][] P, the following steps are taken: - -1. [Assert][]: P is **undefined** or [IsPropertyKey][](P) is **true**. -2. Let metadataMap be [GetOrCreateMetadataMap][](O, P, **false**). -3. [ReturnIfAbrupt][](metadataMap). -4. If metadataMap is **undefined**, return **false**. -5. Return [ToBoolean][]([Invoke][](metadataMap, `"has"`, MetadataKey)). - -### \[\[GetMetadata\]\] ( MetadataKey, P ) - -When the \[\[GetMatadata\]\] internal method of O is called with [ECMAScript language value][] MetadataKey and [property key][] P, the following steps are taken: - -1. Return [OrdinaryGetMetadata][](MetadataKey, O, P). - -### OrdinaryGetMetadata ( MetadataKey, O, P ) - -When the abstract operation OrdinaryGetMetadata is called with [ECMAScript language value][] MetadataKey, Object O, and [property key][] P, the following steps are taken: - -1. [Assert][]: P is **undefined** or [IsPropertyKey][](P) is **true**. -2. Let hasOwn be [OrdinaryHasOwnMetadata][](MetadataKey, O, P). -3. If hasOwn is **true**, then - 1. return [OrdinaryGetOwnMetadata][](MetadataKey, O, P). -4. Let parent be O.\[\[GetPrototypeOf\]\](). -5. [ReturnIfAbrupt][](parent). -6. If parent is not **null**, then - 1. return parent.\[\[GetMetadata\]\](MetadataKey, P). -7. Return **undefined**. - -### \[\[GetOwnMetadata\]\] ( MetadataKey, P, ParamIndex ) - -When the \[\[GetOwnMetadata\]\] internal method of O is called with [ECMAScript language value][] MetadataKey and [property key][] P, the following steps are taken: - -1. Return [OrdinaryGetOwnMetadata][](MetadataKey, O, P). - -### OrdinaryGetOwnMetadata ( MetadataKey, O, P ) - -When the abstract operation OrdinaryGetOwnMetadata is called with [ECMAScript language value][] MetadataKey, Object O, and [property key][] P, the following steps are taken: - -1. [Assert][]: P is **undefined** or [IsPropertyKey][](P) is **true**. -2. Let metadataMap be [GetOrCreateMetadataMap][](O, P, **false**). -3. [ReturnIfAbrupt][](metadataMap). -4. If metadataMap is **undefined**, return **undefined**. -5. Return [Invoke][](metadataMap, `"get"`, MetadataKey). - -### \[\[DefineOwnMetadata\]\] ( MetadataKey, MetadataValue, P ) - -When the \[\[DefineOwnMetadata\]\] internal method of O is called with [ECMAScript language value][] MetadataKey, [ECMAScript language value][] MetadataValue, and [property key][] P, the following steps are taken: - -1. Return [OrdinaryDefineOwnMetadata][](MetadataKey, MetadataValue, O, P) - -### OrdinaryDefineOwnMetadata ( MetadataKey, MetadataValue, O, P ) - -When the abstract operation OrdinaryDefineOwnMetadata is called with [ECMAScript language value][] MetadataKey, [ECMAScript language value][] MetadataValue, Object O, and [property key][] P, the following steps are taken: - -1. [Assert][]: P is **undefined** or [IsPropertyKey][](P) is **true**. -2. Let metadataMap be [GetOrCreateMetadataMap][](O, P, **true**). -3. [ReturnIfAbrupt][](metadataMap). -4. Return [Invoke][](metadataMap, `"set"`, MetadataKey, MetadataValue). - -### \[\[MetadataKeys\]\] ( P ) - -When the \[\[MetadataKeys\]\] internal method of O is called with [property key][] P the following steps are taken: - -1. Return [OrdinaryMetadataKeys][](O, P). - -### OrdinaryMetadataKeys ( O, P ) - -When the abstract operation OrdinaryMetadataKeys is called with Object O and [property key][] P, the following steps are taken: - -1. [Assert][]: P is **undefined** or [IsPropertyKey][](P) is **true**. -2. Let ownKeys be [OrdinaryOwnMetadataKeys][](O, P). -3. Let parent = O.\[\[GetPrototypeOf\]\](). -4. [ReturnIfAbrupt][](parent). -5. If parent is **null**, then return ownKeys. -6. Let parentKeys be O.\[\[OrdinaryMetadataKeys\]\](P). -7. [ReturnIfAbrupt][](parentKeys). -8. If parentKeys is empty, return ownKeys. -9. If ownKeys is empty, return parentKeys. -10. Let set be a newly created **Set** object. -11. Let keys be an empty [List][]. -12. For each element key of ownKeys - 1. Let hasKey be [Invoke][](set, `"has"`, key). - 2. [ReturnIfAbrupt][](hasKey). - 3. If hasKey is **false**, then - 1. Let addStatus be [Invoke][](set, `"add"`, key). - 2. [ReturnIfAbrupt][](addStatus). - 3. Append key as an element of keys. -13. For each element key of parentKeys - 1. Let hasKey be [Invoke][](set, `"has"`, key). - 2. [ReturnIfAbrupt][](hasKey). - 3. If hasKey is **false**, then - 1. Let addStatus be [Invoke][](set, `"add"`, key). - 2. [ReturnIfAbrupt][](addStatus). - 3. Append key as an element of keys. -14. Return keys. - -### \[\[OwnMetadataKeys\]\] ( P ) - -When the \[\[OwnMetadataKeys\]\] internal method of O is called with [property key][] P, the following steps are taken: - -1. Return [OrdinaryOwnMetadataKeys][](O, P). - -### OrdinaryOwnMetadataKeys ( O, P ) - -When the abstract operation OrdinaryOwnMetadataKeys is called with Object O and [property key][] P the following steps are taken: - -1. [Assert][]: P is **undefined** or [IsPropertyKey][](P) is **true**. -2. Let metadataMap be [GetOrCreateMetadataMap][](O, P, **false**). -3. [ReturnIfAbrupt][](metadataMap). -4. Let keys be an empty [List][]. -5. If metadataMap is **undefined**, return keys. -6. Let keysObj be [Invoke][](metadataMap, `"keys"`). -7. [ReturnIfAbrupt][](keysObj). -8. Let iterator be [GetIterator][](keysObj). -9. [ReturnIfAbrupt][](iterator). -10. Repeat - 1. Let next be [IteratorStep][](iterator). - 2. [ReturnIfAbrupt][](next). - 3. If next is **false**, then - 1. Return keys. - 4. Let nextValue be [IteratorValue][](next). - 5. [ReturnIfAbrupt][](nextValue). - 6. Append nextValue as an element of keys. - -### \[\[DeleteMetadata\]\]( MetadataKey, P ) - -When the \[\[DeleteMetadata\]\] internal method of O is called with [ECMAScript language value][] MetadataKey and [property key][] P the following steps are taken: - -1. [Assert][]: P is **undefined** or [IsPropertyKey][](P) is **true**. -2. Let metadataMap be [GetOrCreateMetadataMap][](O, P, **false**). -3. [ReturnIfAbrupt][](metadataMap). -4. If metadataMap is **undefined**, return **false**. -5. Return [ToBoolean][]([Invoke][](metadataMap, `"delete"`, MetadataKey)). - -## Proxy Object Internal Methods and Internal Slots - -This proposal adds the following additional proxy handler methods, as an addendum to [Table 30](https://tc39.github.io/ecma262/2016/#table-30): - -| Internal Method | Handler Method | -|---------------------------|-------------------| -| \[\[HasMetadata\]\] | `hasMetadata` | -| \[\[HasOwnMetadata\]\] | `hasOwnMetadata` | -| \[\[GetMetadata\]\] | `getMetadata` | -| \[\[GetOwnMetadata\]\] | `getOwnMetadata` | -| \[\[MetadataKeys\]\] | `metadataKeys` | -| \[\[OwnMetadataKeys\]\] | `ownMetadataKeys` | -| \[\[DefineOwnMetadata\]\] | `defineMetadata` | -| \[\[DeleteMetadata\]\] | `deleteMetadata` | - -### \[\[HasMetadata\]\] ( MetadataKey, P ) - -When the \[\[HasMetadata\]\] internal method of a Proxy exotic object O is called with [ECMAScript language value][] MetadataKey and [property key][] P, the following steps are taken: - -1. [Assert][]: P is **undefined** or [IsPropertyKey][](P) is **true**. -2. Let handler be the value of the \[\[ProxyHandler\]\] [internal slot][] of O. -3. If handler is **null**, throw a **TypeError** exception. -4. [Assert][]: [Type][](handler) is Object. -5. Let target be the value of the \[\[ProxyTarget\]\] [internal slot][] of O. -6. Let trap be [GetMethod][](handler, `"hasMetadata"`). -7. [ReturnIfAbrupt][](trap). -8. If trap is **undefined**, then - 1. Return target.\[\[HasMetadata\]\](metadataKey, P). -9. Return [ToBoolean][]([Call][](trap, handler, «metadataKey, target, P»)). - -### \[\[HasOwnMetadata\]\] ( MetadataKey, P ) - -When the \[\[HasOwnMetadata\]\] internal method of a Proxy exotic object O is called with [ECMAScript language value][] MetadataKey and [property key][] P, the following steps are taken: - -1. [Assert][]: P is **undefined** or [IsPropertyKey][](P) is **true**. -2. Let handler be the value of the \[\[ProxyHandler\]\] [internal slot][] of O. -3. If handler is **null**, throw a **TypeError** exception. -4. [Assert][]: [Type][](handler) is Object. -5. Let target be the value of the \[\[ProxyTarget\]\] [internal slot][] of O. -6. Let trap be [GetMethod][](handler, `"hasOwnMetadata"`). -7. [ReturnIfAbrupt][](trap). -8. If trap is **undefined**, then - 1. Return target.\[\[HasOwnMetadata\]\](metadataKey, P). -9. Return [ToBoolean][]([Call][](trap, handler, «metadataKey, target, P»)). - -### \[\[GetMetadata\]\] ( MetadataKey, P ) - -When the \[\[GetMatadata\]\] internal method of a Proxy exotic object O is called with [ECMAScript language value][] MetadataKey and [property key][] P, the following steps are taken: - -1. [Assert][]: P is **undefined** or [IsPropertyKey][](P) is **true**. -2. Let handler be the value of the \[\[ProxyHandler\]\] [internal slot][] of O. -3. If handler is **null**, throw a **TypeError** exception. -4. [Assert][]: [Type][](handler) is Object. -5. Let target be the value of the \[\[ProxyTarget\]\] [internal slot][] of O. -6. Let trap be [GetMethod][](handler, `"getMetadata"`). -7. [ReturnIfAbrupt][](trap). -8. If trap is **undefined**, then - 1. Return target.\[\[GetMetadata\]\](metadataKey, P). -9. Return [Call][](trap, handler, «metadataKey, target, P»). - -### \[\[GetOwnMetadata\]\] ( MetadataKey, P, ParamIndex ) - -When the \[\[GetOwnMetadata\]\] internal method of a Proxy exotic object O is called with [ECMAScript language value][] MetadataKey and [property key][] P, the following steps are taken: - -1. [Assert][]: P is **undefined** or [IsPropertyKey][](P) is **true**. -2. Let handler be the value of the \[\[ProxyHandler\]\] [internal slot][] of O. -3. If handler is **null**, throw a **TypeError** exception. -4. [Assert][]: [Type][](handler) is Object. -5. Let target be the value of the \[\[ProxyTarget\]\] [internal slot][] of O. -6. Let trap be [GetMethod][](handler, `"getOwnMetadata"`). -7. [ReturnIfAbrupt][](trap). -8. If trap is **undefined**, then - 1. Return target.\[\[GetOwnMetadata\]\](metadataKey, P). -9. Return [Call][](trap, handler, «metadataKey, target, P»). - -### \[\[DefineOwnMetadata\]\] ( MetadataKey, MetadataValue, P ) - -When the \[\[DefineOwnMetadata\]\] internal method of a Proxy exotic object O is called with [ECMAScript language value][] MetadataKey, [ECMAScript language value][] MetadataValue, and [property key][] P, the following steps are taken: - -1. [Assert][]: P is **undefined** or [IsPropertyKey][](P) is **true**. -2. Let handler be the value of the \[\[ProxyHandler\]\] [internal slot][] of O. -3. If handler is **null**, throw a **TypeError** exception. -4. [Assert][]: [Type][](handler) is Object. -5. Let target be the value of the \[\[ProxyTarget\]\] [internal slot][] of O. -6. Let trap be [GetMethod][](handler, `"defineMetadata"`). -7. [ReturnIfAbrupt][](trap). -8. If trap is **undefined**, then - 1. Return target.\[\[DefineOwnMetadata\]\](metadataKey, metadataValue, P). -9. Return [Call][](trap, handler, «metadataKey, metadataValue, target, P»). - -### \[\[MetadataKeys\]\] ( P ) - -When the \[\[MetadataKeys\]\] internal method of a Proxy exotic object O is called with [property key][] P the following steps are taken: - -1. [Assert][]: P is **undefined** or [IsPropertyKey][](P) is **true**. -2. Let handler be the value of the \[\[ProxyHandler\]\] [internal slot][] of O. -3. If handler is **null**, throw a **TypeError** exception. -4. [Assert][]: [Type][](handler) is Object. -5. Let target be the value of the \[\[ProxyTarget\]\] [internal slot][] of O. -6. Let trap be [GetMethod][](handler, `"metadataKeys"`). -7. [ReturnIfAbrupt][](trap). -8. If trap is **undefined**, then - 1. Return target.\[\[MetadataKeys\]\](P). -9. Let trapResultArray be [Call][](trap, handler, «target, P»). -10. Return [CreateListFromArrayLike][](trapResultArray). - -### \[\[OwnMetadataKeys\]\] ( P ) - -When the \[\[OwnMetadataKeys\]\] internal method of a Proxy exotic object O is called with [property key][] P the following steps are taken: - -1. [Assert][]: P is **undefined** or [IsPropertyKey][](P) is **true**. -2. Let handler be the value of the \[\[ProxyHandler\]\] [internal slot][] of O. -3. If handler is **null**, throw a **TypeError** exception. -4. [Assert][]: [Type][](handler) is Object. -5. Let target be the value of the \[\[ProxyTarget\]\] [internal slot][] of O. -6. Let trap be [GetMethod][](handler, `"ownMetadataKeys"`). -7. [ReturnIfAbrupt][](trap). -8. If trap is **undefined**, then - 1. Return target.\[\[OwnMetadataKeys\]\](P). -9. Let trapResultArray be [Call][](trap, handler, «target, P»). -10. Return [CreateListFromArrayLike][](trapResultArray). - -### \[\[DeleteMetadata\]\]( MetadataKey, P ) - -When the \[\[DeleteMetadata\]\] internal method of a Proxy exotic object O is called with [ECMAScript language value][] MetadataKey and [property key][] P the following steps are taken: - -1. [Assert][]: P is **undefined** or [IsPropertyKey][](P) is **true**. -2. Let handler be the value of the \[\[ProxyHandler\]\] [internal slot][] of O. -3. If handler is **null**, throw a **TypeError** exception. -4. [Assert][]: [Type][](handler) is Object. -5. Let target be the value of the \[\[ProxyTarget\]\] [internal slot][] of O. -6. Let trap be [GetMethod][](handler, `"deleteMetadata"`). -7. [ReturnIfAbrupt][](trap). -8. If trap is **undefined**, then - 1. Return target.\[\[DeleteMetadata\]\](metadataKey, P). -9. Return [ToBoolean][]([Call][](trap, handler, «metadataKey, target, P»)). - -# Reflection - -## The Reflect Object - -This section contains amendments to the Reflect object. - -### Metadata Decorator Functions - -A [metadata decorator function][mdf] is an anonymous built-in function that has \[\[MetadataKey\]\] and \[\[MetadataValue\]\] [internal slots][internal slot]. - -When a metadata decorator function F is called with arguments target and propertyKey, the following steps are taken: - -1. [Assert][]: F has a \[\[MetadataKey\]\] [internal slot][] whose value is an ECMAScript language value, or **undefined**. -2. [Assert][]: F has a \[\[MetadataValue\]\] [internal slot][] whose value is an ECMAScript language value, or **undefined**. -3. If [Type][](target) is not Object, throw a **TypeError** exception. -4. Let key be **undefined**. -5. If propertyKey is not **undefined**, then - 1. Set key to be [ToPropertyKey][](propertyKey). -6. [ReturnIfAbrupt][](key). -7. Let metadataKey be the value of F's \[\[MetadataKey\]\] [internal slot][]. -8. Let metadataValue be the value of F's \[\[MetadataValue\]\] [internal slot][]. -9. Return target.\[\[DefineMetadata\]\](metadataKey, metadataValue, target, key). - -### Reflect.metadata ( metadataKey, metadataValue ) - -When the `metadata` function is called with arguments metadataKey and metadataValue, the following steps are taken: - -1. Let decorator be a new built-in function object as defined in [Metadata Decorator Functions][mdf]. -2. Set the \[\[MetadataKey\]\] [internal slot][] of decorator to metadataKey. -3. Set the \[\[MetadataValue\]\] [internal slot][] of decorator to metadataValue. -4. return decorator. - -### Reflect.defineMetadata ( metadataKey, metadataValue, target, propertyKey ) -When the `defineMetadata` function is called with arguments metadataKey, metadataValue, target, and propertyKey, the following steps are taken: - -1. If [Type][](target) is not Object, throw a **TypeError** exception. -2. Let key be **undefined**. -3. If propertyKey is not **undefined**, then - 1. Set key to be [ToPropertyKey][](propertyKey). - 2. [ReturnIfAbrupt][](key). -4. return target.\[\[DefineMetadata\]\](metadataKey, metadataValue, key). - -### Reflect.hasMetadata ( metadataKey, target \[, propertyKey\] ) - -When the `hasMetadata` function is called with arguments metadataKey, target, and propertyKey, the following steps are taken: - -1. If [Type][](target) is not Object, throw a **TypeError** exception. -2. Let key be **undefined**. -3. If propertyKey is not **undefined**, then - 1. Set key to be [ToPropertyKey][](propertyKey). - 2. [ReturnIfAbrupt][](key). -4. return target.\[\[HasMetadata\]\](metadataKey, key). - -### Reflect.hasOwnMetadata ( metadataKey, target \[, propertyKey\] ) - -When the `hasOwnMetadata` function is called with arguments metadataKey, target, and propertyKey, the following steps are taken: - -1. If [Type][](target) is not Object, throw a **TypeError** exception. -2. Let key be **undefined**. -3. If propertyKey is not **undefined**, then - 1. Set key to be [ToPropertyKey][](propertyKey). - 2. [ReturnIfAbrupt][](key). -4. return target.\[\[HasOwn\]\](metadataKey, key). - -### Reflect.getMetadata ( metadataKey, target \[, propertyKey\] ) - -When the `getMetadata` function is called with arguments metadataKey, target, and propertyKey, the following steps are taken: - -1. If [Type][](target) is not Object, throw a **TypeError** exception. -2. Let key be **undefined**. -3. If propertyKey is not **undefined**, then - 1. Set key to be [ToPropertyKey][](propertyKey). - 2. [ReturnIfAbrupt][](key). -4. return target.\[\[GetMetadata\]\](metadataKey, key). - -### Reflect.getOwnMetadata ( metadataKey, target \[, propertyKey\] ) - -When the `getOwnMetadata` function is called with arguments metadataKey, target, and propertyKey, the following steps are taken: - -1. If [Type][](target) is not Object, throw a **TypeError** exception. -2. Let key be **undefined**. -3. If propertyKey is not **undefined**, then - 1. Set key to be [ToPropertyKey][](propertyKey). - 2. [ReturnIfAbrupt][](key). -4. return target.\[\[GetOwnMetadata\]\](metadataKey, key). - -### Reflect.getMetadataKeys ( target \[, propertyKey\] ) - -When the `getMetadataKeys` function is called with arguments target and propertyKey, the following steps are taken: - -1. If [Type][](target) is not Object, throw a **TypeError** exception. -2. Let key be **undefined**. -3. If propertyKey is not **undefined**, then - 1. Set key to be [ToPropertyKey][](propertyKey). - 2. [ReturnIfAbrupt][](key). -4. Let keys be target.\[\[GetMetadataKeys\]\](key). -5. Return [CreateArrayFromList][](keys). - -### Reflect.getOwnMetadataKeys ( target \[, propertyKey\] ) - -When the `getOwnMetadataKeys` function is called with arguments target and propertyKey, the following steps are taken: - -1. If [Type][](target) is not Object, throw a **TypeError** exception. -2. Let key be **undefined**. -3. If propertyKey is not **undefined**, then - 1. Set key to be [ToPropertyKey][](propertyKey). - 2. [ReturnIfAbrupt][](key). -4. Let keys be target.\[\[GetOwnMetadataKeys\]\](key). -5. Return [CreateArrayFromList][](keys). - -### Reflect.deleteMetadata ( metadataKey, target \[, propertyKey\] ) - -When the `deleteMetadata` function is called with arguments metadataKey, target, and propertyKey, the following steps are taken: - -1. If [Type][](target) is not Object, throw a **TypeError** exception. -2. Let key be **undefined**. -3. If propertyKey is not **undefined**, then - 1. Set key to be [ToPropertyKey][](propertyKey). - 2. [ReturnIfAbrupt][](key). -4. return target.\[\[DeleteMetadata\]\](metadataKey, key). - -[ECMAScript language value]: https://tc39.github.io/ecma262/2016/#sec-ecmascript-language-types -[property key]: https://tc39.github.io/ecma262/2016/#sec-object-type -[Completion Record]: https://tc39.github.io/ecma262/2016/#sec-completion-record-specification-type -[internal slot]: https://tc39.github.io/ecma262/2016/#sec-object-internal-methods-and-internal-slots -[List]: https://tc39.github.io/ecma262/2016/#sec-list-and-record-specification-type -[ArrayCreate]: https://tc39.github.io/ecma262/2016/#sec-arraycreate -[Assert]: https://tc39.github.io/ecma262/2016/#sec-algorithm-conventions -[Call]: https://tc39.github.io/ecma262/2016/#sec-call -[CreateArrayFromList]: https://tc39.github.io/ecma262/2016/#sec-createarrayfromlist -[CreateDataPropertyOrThrow]: https://tc39.github.io/ecma262/2016/#sec-createdatapropertyorthrow -[CreateListFromArrayLike]: https://tc39.github.io/ecma262/2016/#sec-createlistfromarraylike -[GetMethod]: https://tc39.github.io/ecma262/2016/#sec-getmethod -[Get]: https://tc39.github.io/ecma262/2016/#sec-get-o-p -[Set]: https://tc39.github.io/ecma262/2016/#sec-set-o-p-v-throw -[GetIterator]: https://tc39.github.io/ecma262/2016/#sec-getiterator -[Invoke]: https://tc39.github.io/ecma262/2016/#sec-invoke -[IsPropertyKey]: https://tc39.github.io/ecma262/2016/#sec-ispropertykey -[IteratorStep]: https://tc39.github.io/ecma262/2016/#sec-iteratorstep -[IteratorClose]: https://tc39.github.io/ecma262/2016/#sec-iteratorclose -[IteratorValue]: https://tc39.github.io/ecma262/2016/#sec-iteratorvalue -[ReturnIfAbrupt]: https://tc39.github.io/ecma262/2016/#sec-returnifabrupt -[ToPrimitive]: https://tc39.github.io/ecma262/2016/#sec-toprimitive -[ToBoolean]: https://tc39.github.io/ecma262/2016/#sec-toboolean -[ToString]: https://tc39.github.io/ecma262/2016/#sec-tostring -[ToPropertyKey]: https://tc39.github.io/ecma262/2016/#sec-topropertykey -[Type]: https://tc39.github.io/ecma262/2016/#sec-ecmascript-data-types-and-values -[GetOrCreateMetadataMap]: #getorcreatemetadatamap--o-p-create- -[OrdinaryDefineOwnMetadata]: #ordinarydefineownmetadata--metadatakey-metadatavalue-o-p- -[OrdinaryGetMetadata]: #ordinarygetmetadata--metadatakey-o-p- -[OrdinaryGetOwnMetadata]: #ordinarygetownmetadata--metadatakey-o-p- -[OrdinaryHasMetadata]: #ordinaryhasmetadata--metadatakey-o-p- -[OrdinaryHasOwnMetadata]: #ordinaryhasownmetadata--metadatakey-o-p- -[OrdinaryMetadataKeys]: #ordinarymetadatakeys--o-p- -[OrdinaryOwnMetadataKeys]: #ordinaryownmetadatakeys--o-p- -[mdf]: #metadata-decorator-functions +The spec has moved to https://rbuckton.github.io/reflect-metadata/ \ No newline at end of file diff --git a/standalone.d.ts b/standalone.d.ts index b57aa66..1b36927 100644 --- a/standalone.d.ts +++ b/standalone.d.ts @@ -32,8 +32,8 @@ declare namespace Reflect { * Applies a set of decorators to a property of a target object. * @param decorators An array of decorators. * @param target The target object. - * @param targetKey The property key to decorate. - * @param descriptor A property descriptor + * @param propertyKey The property key to decorate. + * @param attributes A property descriptor. * @remarks Decorators are applied in reverse order. * @example * @@ -63,7 +63,7 @@ declare namespace Reflect { * Object.getOwnPropertyDescriptor(Example.prototype, "method"))); * */ - function decorate(decorators: (PropertyDecorator | MethodDecorator)[], target: Object, targetKey: string | symbol, descriptor?: PropertyDescriptor): PropertyDescriptor; + function decorate(decorators: (PropertyDecorator | MethodDecorator)[], target: Object, propertyKey: string | symbol, attributes?: PropertyDescriptor): PropertyDescriptor; /** * A default metadata decorator factory that can be used on a class, class member, or parameter. * @param metadataKey The key for the metadata entry. @@ -106,7 +106,7 @@ declare namespace Reflect { */ function metadata(metadataKey: any, metadataValue: any): { (target: Function): void; - (target: Object, targetKey: string | symbol): void; + (target: Object, propertyKey: string | symbol): void; }; /** * Define a unique metadata entry on the target. @@ -133,7 +133,7 @@ declare namespace Reflect { * @param metadataKey A key used to store and retrieve metadata. * @param metadataValue A value that contains attached metadata. * @param target The target object on which to define metadata. - * @param targetKey The property key for the target. + * @param propertyKey The property key for the target. * @example * * class Example { @@ -163,7 +163,7 @@ declare namespace Reflect { * } * */ - function defineMetadata(metadataKey: any, metadataValue: any, target: Object, targetKey: string | symbol): void; + function defineMetadata(metadataKey: any, metadataValue: any, target: Object, propertyKey: string | symbol): void; /** * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined. * @param metadataKey A key used to store and retrieve metadata. @@ -183,7 +183,7 @@ declare namespace Reflect { * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined. * @param metadataKey A key used to store and retrieve metadata. * @param target The target object on which the metadata is defined. - * @param targetKey The property key for the target. + * @param propertyKey The property key for the target. * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`. * @example * @@ -209,7 +209,7 @@ declare namespace Reflect { * result = Reflect.hasMetadata("custom:annotation", Example.prototype, "method"); * */ - function hasMetadata(metadataKey: any, target: Object, targetKey: string | symbol): boolean; + function hasMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): boolean; /** * Gets a value indicating whether the target object has the provided metadata key defined. * @param metadataKey A key used to store and retrieve metadata. @@ -229,7 +229,7 @@ declare namespace Reflect { * Gets a value indicating whether the target object has the provided metadata key defined. * @param metadataKey A key used to store and retrieve metadata. * @param target The target object on which the metadata is defined. - * @param targetKey The property key for the target. + * @param propertyKey The property key for the target. * @returns `true` if the metadata key was defined on the target object; otherwise, `false`. * @example * @@ -255,7 +255,7 @@ declare namespace Reflect { * result = Reflect.hasOwnMetadata("custom:annotation", Example.prototype, "method"); * */ - function hasOwnMetadata(metadataKey: any, target: Object, targetKey: string | symbol): boolean; + function hasOwnMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): boolean; /** * Gets the metadata value for the provided metadata key on the target object or its prototype chain. * @param metadataKey A key used to store and retrieve metadata. @@ -275,7 +275,7 @@ declare namespace Reflect { * Gets the metadata value for the provided metadata key on the target object or its prototype chain. * @param metadataKey A key used to store and retrieve metadata. * @param target The target object on which the metadata is defined. - * @param targetKey The property key for the target. + * @param propertyKey The property key for the target. * @returns The metadata value for the metadata key if found; otherwise, `undefined`. * @example * @@ -301,7 +301,7 @@ declare namespace Reflect { * result = Reflect.getMetadata("custom:annotation", Example.prototype, "method"); * */ - function getMetadata(metadataKey: any, target: Object, targetKey: string | symbol): any; + function getMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): any; /** * Gets the metadata value for the provided metadata key on the target object. * @param metadataKey A key used to store and retrieve metadata. @@ -321,7 +321,7 @@ declare namespace Reflect { * Gets the metadata value for the provided metadata key on the target object. * @param metadataKey A key used to store and retrieve metadata. * @param target The target object on which the metadata is defined. - * @param targetKey The property key for the target. + * @param propertyKey The property key for the target. * @returns The metadata value for the metadata key if found; otherwise, `undefined`. * @example * @@ -347,7 +347,7 @@ declare namespace Reflect { * result = Reflect.getOwnMetadata("custom:annotation", Example.prototype, "method"); * */ - function getOwnMetadata(metadataKey: any, target: Object, targetKey: string | symbol): any; + function getOwnMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): any; /** * Gets the metadata keys defined on the target object or its prototype chain. * @param target The target object on which the metadata is defined. @@ -365,7 +365,7 @@ declare namespace Reflect { /** * Gets the metadata keys defined on the target object or its prototype chain. * @param target The target object on which the metadata is defined. - * @param targetKey The property key for the target. + * @param propertyKey The property key for the target. * @returns An array of unique metadata keys. * @example * @@ -391,7 +391,7 @@ declare namespace Reflect { * result = Reflect.getMetadataKeys(Example.prototype, "method"); * */ - function getMetadataKeys(target: Object, targetKey: string | symbol): any[]; + function getMetadataKeys(target: Object, propertyKey: string | symbol): any[]; /** * Gets the unique metadata keys defined on the target object. * @param target The target object on which the metadata is defined. @@ -409,7 +409,7 @@ declare namespace Reflect { /** * Gets the unique metadata keys defined on the target object. * @param target The target object on which the metadata is defined. - * @param targetKey The property key for the target. + * @param propertyKey The property key for the target. * @returns An array of unique metadata keys. * @example * @@ -435,7 +435,7 @@ declare namespace Reflect { * result = Reflect.getOwnMetadataKeys(Example.prototype, "method"); * */ - function getOwnMetadataKeys(target: Object, targetKey: string | symbol): any[]; + function getOwnMetadataKeys(target: Object, propertyKey: string | symbol): any[]; /** * Deletes the metadata entry from the target object with the provided key. * @param metadataKey A key used to store and retrieve metadata. @@ -455,7 +455,7 @@ declare namespace Reflect { * Deletes the metadata entry from the target object with the provided key. * @param metadataKey A key used to store and retrieve metadata. * @param target The target object on which the metadata is defined. - * @param targetKey The property key for the target. + * @param propertyKey The property key for the target. * @returns `true` if the metadata entry was found and deleted; otherwise, false. * @example * @@ -481,5 +481,5 @@ declare namespace Reflect { * result = Reflect.deleteMetadata("custom:annotation", Example.prototype, "method"); * */ - function deleteMetadata(metadataKey: any, target: Object, targetKey: string | symbol): boolean; + function deleteMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): boolean; } \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 0a50ecf..30ef258 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,11 +1,15 @@ { "compilerOptions": { "target": "es5", - "noImplicitAny": true, + "module": "commonjs", + "newLine": "LF", "sourceMap": true, + "strictNullChecks": true, + "noImplicitAny": true, "noUnusedLocals": true, "noUnusedParameters": true, - "strictNullChecks": true + "noImplicitReturns": true, + "noImplicitThis": true }, "files": [ "Reflect.ts"