Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

reflect-metadata

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reflect-metadata - npm Package Compare versions

Comparing version 0.1.9 to 0.1.10

AUTHORS.md

4

bower.json

@@ -5,3 +5,3 @@ {

"description": "Polyfill for Metadata Reflection API",
"homepage": "https://github.com/rbuckton/ReflectDecorators",
"homepage": "https://github.com/rbuckton/reflect-metadata",
"authors": [

@@ -35,4 +35,4 @@ "Ron Buckton <ron.buckton@microsoft.com>"

"type": "git",
"url": "https://github.com/rbuckton/ReflectDecorators.git"
"url": "https://github.com/rbuckton/reflect-metadata.git"
}
}

@@ -40,4 +40,4 @@ /*! *****************************************************************************

* @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.

@@ -72,3 +72,3 @@ * @example

*/
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;
/**

@@ -116,3 +116,3 @@ * A default metadata decorator factory that can be used on a class, class member, or parameter.

(target: Function): void;
(target: Object, targetKey: string | symbol): void;
(target: Object, propertyKey: string | symbol): void;
};

@@ -144,3 +144,3 @@ /**

* @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

@@ -175,3 +175,3 @@ *

*/
function defineMetadata(metadataKey: any, metadataValue: any, target: Object, targetKey: string | symbol): void;
function defineMetadata(metadataKey: any, metadataValue: any, target: Object, propertyKey: string | symbol): void;
/**

@@ -196,3 +196,3 @@ * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined.

* @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`.

@@ -223,3 +223,3 @@ * @example

*/
function hasMetadata(metadataKey: any, target: Object, targetKey: string | symbol): boolean;
function hasMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): boolean;
/**

@@ -244,3 +244,3 @@ * Gets a value indicating whether the target object has the provided metadata key defined.

* @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`.

@@ -271,3 +271,3 @@ * @example

*/
function hasOwnMetadata(metadataKey: any, target: Object, targetKey: string | symbol): boolean;
function hasOwnMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): boolean;
/**

@@ -292,3 +292,3 @@ * Gets the metadata value for the provided metadata key 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 The metadata value for the metadata key if found; otherwise, `undefined`.

@@ -319,3 +319,3 @@ * @example

*/
function getMetadata(metadataKey: any, target: Object, targetKey: string | symbol): any;
function getMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): any;
/**

@@ -340,3 +340,3 @@ * Gets the metadata value for the provided metadata key 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 The metadata value for the metadata key if found; otherwise, `undefined`.

@@ -367,3 +367,3 @@ * @example

*/
function getOwnMetadata(metadataKey: any, target: Object, targetKey: string | symbol): any;
function getOwnMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): any;
/**

@@ -386,3 +386,3 @@ * 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.

@@ -413,3 +413,3 @@ * @example

*/
function getMetadataKeys(target: Object, targetKey: string | symbol): any[];
function getMetadataKeys(target: Object, propertyKey: string | symbol): any[];
/**

@@ -432,3 +432,3 @@ * 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.

@@ -459,3 +459,3 @@ * @example

*/
function getOwnMetadataKeys(target: Object, targetKey: string | symbol): any[];
function getOwnMetadataKeys(target: Object, propertyKey: string | symbol): any[];
/**

@@ -480,3 +480,3 @@ * Deletes the metadata entry from the target object with the provided key.

* @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.

@@ -507,4 +507,4 @@ * @example

*/
function deleteMetadata(metadataKey: any, target: Object, targetKey: string | symbol): boolean;
function deleteMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): boolean;
}
}
{
"name": "reflect-metadata",
"version": "0.1.9",
"version": "0.1.10",
"description": "Polyfill for Metadata Reflection API",

@@ -11,10 +11,10 @@ "main": "Reflect.js",

"scripts": {
"prepublish": "npm run test",
"build": "tsc",
"build-test": "tsc --project ./test/",
"test": "npm run build & npm run build-test & node ./temp/test/run.js"
"prepublish": "gulp prepublish",
"build": "gulp build",
"test": "gulp test",
"start": "gulp start"
},
"repository": {
"type": "git",
"url": "https://github.com/rbuckton/ReflectDecorators.git"
"url": "https://github.com/rbuckton/reflect-metadata.git"
},

@@ -35,3 +35,3 @@ "keywords": [

"license": "Apache-2.0",
"url": "http://github.com/rbuckton/ReflectDecorators/raw/master/LICENSE"
"url": "http://github.com/rbuckton/reflect-metadata/raw/master/LICENSE"
}

@@ -41,9 +41,23 @@ ],

"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",
"@types/mocha": "^2.2.34",
"@types/node": "^6.0.52",
"chai": "^3.5.0",
"del": "^2.2.2",
"ecmarkup": "^3.9.3",
"gulp": "^3.9.1",
"gulp-emu": "^1.1.0",
"gulp-live-server": "0.0.30",
"gulp-mocha": "^3.0.1",
"gulp-rename": "^1.2.2",
"gulp-sequence": "^0.4.6",
"gulp-tsb": "^2.0.3",
"mocha": "^3.2.0",
"typescript": "^2.1.4"
}
}

@@ -1,3 +0,1 @@

Proposal to add Decorators to ES7, along with a prototype for an ES7 Reflection API for Decorator Metadata
# Metadata Reflection API

@@ -180,2 +178,2 @@

[Metadata-Spec]: https://github.com/rbuckton/ReflectDecorators/blob/master/spec/metadata.md
[Metadata-Spec]: https://rbuckton.github.io/reflect-metadata

@@ -19,6 +19,2 @@ /*! *****************************************************************************

var hasOwn = Object.prototype.hasOwnProperty;
// feature test for Object.create support
var supportsCreate = typeof Object.create === "function";
// feature test for __proto__ support
var supportsProto = { __proto__: [] } instanceof Array;
// feature test for Symbol support

@@ -28,9 +24,13 @@ var supportsSymbol = typeof Symbol === "function";

var iteratorSymbol = supportsSymbol && typeof Symbol.iterator !== "undefined" ? Symbol.iterator : "@@iterator";
// create an object in dictionary mode (a.k.a. "slow" mode in v8)
var createDictionary = supportsCreate ? function () { return MakeDictionary(Object.create(null)); } :
supportsProto ? function () { return MakeDictionary({ __proto__: null }); } :
function () { return MakeDictionary({}); };
var HashMap;
(function (HashMap) {
var supportsCreate = typeof Object.create === "function"; // feature test for Object.create support
var supportsProto = { __proto__: [] } instanceof Array; // feature test for __proto__ support
var downLevel = !supportsCreate && !supportsProto;
// create an object in dictionary mode (a.k.a. "slow" mode in v8)
HashMap.create = supportsCreate
? function () { return MakeDictionary(Object.create(null)); }
: supportsProto
? function () { return MakeDictionary({ __proto__: null }); }
: function () { return MakeDictionary({}); };
HashMap.has = downLevel

@@ -45,6 +45,8 @@ ? function (map, key) { return hasOwn.call(map, key); }

var functionPrototype = Object.getPrototypeOf(Function);
var _Map = typeof Map === "function" && typeof Map.prototype.entries === "function" ? Map : CreateMapPolyfill();
var _Set = typeof Set === "function" && typeof Set.prototype.entries === "function" ? Set : CreateSetPolyfill();
var _WeakMap = typeof WeakMap === "function" ? WeakMap : CreateWeakMapPolyfill();
var usePolyfill = typeof process === "object" && process.env && process.env["REFLECT_METADATA_USE_MAP_POLYFILL"] === "true";
var _Map = !usePolyfill && typeof Map === "function" && typeof Map.prototype.entries === "function" ? Map : CreateMapPolyfill();
var _Set = !usePolyfill && typeof Set === "function" && typeof Set.prototype.entries === "function" ? Set : CreateSetPolyfill();
var _WeakMap = !usePolyfill && typeof WeakMap === "function" ? WeakMap : CreateWeakMapPolyfill();
// [[Metadata]] internal slot
// https://rbuckton.github.io/reflect-metadata/#ordinary-object-internal-methods-and-internal-slots
var Metadata = new _WeakMap();

@@ -55,4 +57,4 @@ /**

* @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.

@@ -91,4 +93,4 @@ * @example

*/
function decorate(decorators, target, targetKey, targetDescriptor) {
if (!IsUndefined(targetKey)) {
function decorate(decorators, target, propertyKey, attributes) {
if (!IsUndefined(propertyKey)) {
if (!IsArray(decorators))

@@ -98,8 +100,8 @@ throw new TypeError();

throw new TypeError();
if (!IsObject(targetDescriptor) && !IsUndefined(targetDescriptor) && !IsNull(targetDescriptor))
if (!IsObject(attributes) && !IsUndefined(attributes) && !IsNull(attributes))
throw new TypeError();
if (IsNull(targetDescriptor))
targetDescriptor = undefined;
targetKey = ToPropertyKey(targetKey);
return DecorateProperty(decorators, target, targetKey, targetDescriptor);
if (IsNull(attributes))
attributes = undefined;
propertyKey = ToPropertyKey(propertyKey);
return DecorateProperty(decorators, target, propertyKey, attributes);
}

@@ -115,2 +117,4 @@ else {

Reflect.decorate = decorate;
// 4.1.2 Reflect.metadata(metadataKey, metadataValue)
// https://rbuckton.github.io/reflect-metadata/#reflect.metadata
/**

@@ -157,14 +161,8 @@ * A default metadata decorator factory that can be used on a class, class member, or parameter.

function metadata(metadataKey, metadataValue) {
function decorator(target, targetKey) {
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, propertyKey) {
if (!IsObject(target))
throw new TypeError();
if (!IsUndefined(propertyKey) && !IsPropertyKey(propertyKey))
throw new TypeError();
OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey);
}

@@ -179,3 +177,3 @@ return decorator;

* @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

@@ -214,8 +212,8 @@ *

*/
function defineMetadata(metadataKey, metadataValue, target, targetKey) {
function defineMetadata(metadataKey, metadataValue, target, propertyKey) {
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);
}

@@ -227,3 +225,3 @@ Reflect.defineMetadata = defineMetadata;

* @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`.

@@ -258,8 +256,8 @@ * @example

*/
function hasMetadata(metadataKey, target, targetKey) {
function hasMetadata(metadataKey, target, propertyKey) {
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);
}

@@ -271,3 +269,3 @@ Reflect.hasMetadata = hasMetadata;

* @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`.

@@ -302,8 +300,8 @@ * @example

*/
function hasOwnMetadata(metadataKey, target, targetKey) {
function hasOwnMetadata(metadataKey, target, propertyKey) {
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);
}

@@ -315,3 +313,3 @@ Reflect.hasOwnMetadata = hasOwnMetadata;

* @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`.

@@ -346,8 +344,8 @@ * @example

*/
function getMetadata(metadataKey, target, targetKey) {
function getMetadata(metadataKey, target, propertyKey) {
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);
}

@@ -359,3 +357,3 @@ Reflect.getMetadata = getMetadata;

* @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`.

@@ -390,8 +388,8 @@ * @example

*/
function getOwnMetadata(metadataKey, target, targetKey) {
function getOwnMetadata(metadataKey, target, propertyKey) {
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);
}

@@ -402,3 +400,3 @@ Reflect.getOwnMetadata = getOwnMetadata;

* @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.

@@ -433,8 +431,8 @@ * @example

*/
function getMetadataKeys(target, targetKey) {
function getMetadataKeys(target, propertyKey) {
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);
}

@@ -445,3 +443,3 @@ Reflect.getMetadataKeys = getMetadataKeys;

* @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.

@@ -476,8 +474,8 @@ * @example

*/
function getOwnMetadataKeys(target, targetKey) {
function getOwnMetadataKeys(target, propertyKey) {
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);
}

@@ -489,3 +487,3 @@ Reflect.getOwnMetadataKeys = getOwnMetadataKeys;

* @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.

@@ -520,9 +518,8 @@ * @example

*/
function deleteMetadata(metadataKey, target, targetKey) {
// https://github.com/rbuckton/ReflectDecorators/blob/master/spec/metadata.md#deletemetadata-metadatakey-p-
function deleteMetadata(metadataKey, target, propertyKey) {
if (!IsObject(target))
throw new TypeError();
if (!IsUndefined(targetKey))
targetKey = ToPropertyKey(targetKey);
var metadataMap = GetOrCreateMetadataMap(target, targetKey, /*create*/ false);
if (!IsUndefined(propertyKey))
propertyKey = ToPropertyKey(propertyKey);
var metadataMap = GetOrCreateMetadataMap(target, propertyKey, /*Create*/ false);
if (IsUndefined(metadataMap))

@@ -535,3 +532,3 @@ return false;

var targetMetadata = Metadata.get(target);
targetMetadata.delete(targetKey);
targetMetadata.delete(propertyKey);
if (targetMetadata.size > 0)

@@ -584,6 +581,4 @@ return true;

}
// 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, O, P) {

@@ -598,6 +593,6 @@ var hasOwn = OrdinaryHasOwnMetadata(MetadataKey, O, P);

}
// 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, O, P) {
var metadataMap = GetOrCreateMetadataMap(O, P, /*create*/ false);
var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);
if (IsUndefined(metadataMap))

@@ -607,4 +602,4 @@ return false;

}
// 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, O, P) {

@@ -619,6 +614,6 @@ var hasOwn = OrdinaryHasOwnMetadata(MetadataKey, O, P);

}
// 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, O, P) {
var metadataMap = GetOrCreateMetadataMap(O, P, /*create*/ false);
var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);
if (IsUndefined(metadataMap))

@@ -628,10 +623,10 @@ return undefined;

}
// 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, MetadataValue, O, P) {
var metadataMap = GetOrCreateMetadataMap(O, P, /*create*/ true);
var 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, P) {

@@ -667,7 +662,7 @@ var ownKeys = OrdinaryOwnMetadataKeys(O, P);

}
// 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, P) {
var metadataMap = GetOrCreateMetadataMap(O, P, /*create*/ false);
var keys = [];
var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);
if (IsUndefined(metadataMap))

@@ -677,16 +672,16 @@ return keys;

var iterator = GetIterator(keysObj);
var k = 0;
while (true) {
var next = IteratorStep(iterator);
if (!next) {
keys.length = k;
return keys;
}
var nextValue = IteratorValue(next);
try {
if (!next)
return keys;
var nextValue = IteratorValue(next);
keys.push(nextValue);
keys[k] = nextValue;
}
catch (e) {
try {
if (next) {
next = false;
IteratorClose(iterator);
}
IteratorClose(iterator);
}

@@ -697,10 +692,5 @@ finally {

}
finally {
if (next)
IteratorClose(iterator);
}
k++;
}
}
// ECMAScript Specification
// https://tc39.github.io/ecma262/
// 6 ECMAScript Data Typ0es and Values

@@ -838,2 +828,11 @@ // https://tc39.github.io/ecma262/#sec-ecmascript-data-types-and-values

}
// 7.2.7 IsPropertyKey(argument)
// https://tc39.github.io/ecma262/#sec-ispropertykey
function IsPropertyKey(argument) {
switch (Type(argument)) {
case 3 /* String */: return true;
case 4 /* Symbol */: return true;
default: return false;
}
}
// 7.3 Operations on Objects

@@ -1011,11 +1010,11 @@ // https://tc39.github.io/ecma262/#sec-operations-on-objects

Map.prototype._find = function (key, insert) {
if (this._cacheKey === key)
return this._cacheIndex;
var index = this._keys.indexOf(key);
if (index < 0 && insert) {
index = this._keys.length;
if (this._cacheKey !== key) {
this._cacheIndex = this._keys.indexOf(this._cacheKey = key);
}
if (this._cacheIndex < 0 && insert) {
this._cacheIndex = this._keys.length;
this._keys.push(key);
this._values.push(undefined);
}
return this._cacheKey = key, this._cacheIndex = index;
return this._cacheIndex;
};

@@ -1060,3 +1059,3 @@ return Map;

var UUID_SIZE = 16;
var keys = createDictionary();
var keys = HashMap.create();
var rootKey = CreateUniqueKey();

@@ -1102,3 +1101,3 @@ return (function () {

return undefined;
Object.defineProperty(target, rootKey, { value: createDictionary() });
Object.defineProperty(target, rootKey, { value: HashMap.create() });
}

@@ -1105,0 +1104,0 @@ return target[rootKey];

# 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 <var>O</var>, [property key][] <var>P</var>, and Boolean <var>Create</var> the following steps are taken:
1. [Assert][]: <var>P</var> is **undefined** or [IsPropertyKey][](<var>P</var>) is **true**.
2. Let <var>targetMetadata</var> be the value of <var>O</var>'s \[\[Metadata\]\] [internal slot][].
3. If <var>targetMetadata</var> is **undefined**, then
1. If <var>Create</var> is **false**, return **undefined**.
2. Set <var>targetMetadata</var> to be a newly created **Map** object.
3. Set the \[\[Metadata\]\] [internal slot][] of <var>O</var> to <var>targetMetadata</var>.
4. Let <var>metadataMap</var> be [Invoke][](<var>targetMetadata</var>, `"get"`, <var>P</var>).
5. [ReturnIfAbrupt][](<var>metadataMap</var>).
6. If <var>metadataMap</var> is **undefined**, then
1. If <var>Create</var> is **false**, return **undefined**.
2. Set <var>metadataMap</var> to be a newly created **Map** object.
3. Let <var>setStatus</var> be [Invoke][](<var>targetMetadata</var>, `"set"`, <var>P</var>, <var>metadataMap</var>).
4. [ReturnIfAbrupt][](<var>setStatus</var>).
7. Return <var>metadataMap</var>.
# 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 <var>O</var> is called with [ECMAScript language value][] <var>MetadataKey</var> and [property key][] <var>P</var>, the following steps are taken:
1. Return [OrdinaryHasMetadata][](<var>MetadataKey</var>, <var>O</var>, <var>P</var>).
### OrdinaryHasMetadata ( MetadataKey, O, P )
When the abstract operation OrdinaryHasMetadata is called with [ECMAScript language value][] <var>MetadataKey</var>, Object <var>O</var>, and [property key][] <var>P</var>, the following steps are taken:
1. [Assert][]: <var>P</var> is **undefined** or [IsPropertyKey][](<var>P</var>) is **true**.
2. Let <var>hasOwn</var> be [OrdinaryHasOwnMetadata][](<var>MetadataKey</var>, <var>O</var>, <var>P</var>).
3. If <var>hasOwn</var> is **true**, return **true**.
4. Let <var>parent</var> be <var>O</var>.\[\[GetPrototypeOf\]\]().
5. [ReturnIfAbrupt][](<var>parent</var>).
6. If <var>parent</var> is not **null**, then
1. return <var>parent</var>.\[\[HasMetadata\]\](<var>MetadataKey</var>, <var>P</var>).
7. Return **false**.
### \[\[HasOwnMetadata\]\] ( MetadataKey, P )
When the \[\[HasOwnMetadata\]\] internal method of <var>O</var> is called with [ECMAScript language value][] <var>MetadataKey</var> and [property key][] <var>P</var>, the following steps are taken:
1. Return [OrdinaryHasOwnMetadata][](<var>MetadataKey</var>, <var>O</var>, <var>P</var>).
### OrdinaryHasOwnMetadata ( MetadataKey, O, P )
When the abstract operation OrdinaryHasOwnMetadata is called with [ECMAScript language value][] <var>MetadataKey</var>, Object <var>O</var>, and [property key][] <var>P</var>, the following steps are taken:
1. [Assert][]: <var>P</var> is **undefined** or [IsPropertyKey][](<var>P</var>) is **true**.
2. Let <var>metadataMap</var> be [GetOrCreateMetadataMap][](<var>O</var>, <var>P</var>, **false**).
3. [ReturnIfAbrupt][](<var>metadataMap</var>).
4. If <var>metadataMap</var> is **undefined**, return **false**.
5. Return [ToBoolean][]([Invoke][](<var>metadataMap</var>, `"has"`, <var>MetadataKey</var>)).
### \[\[GetMetadata\]\] ( MetadataKey, P )
When the \[\[GetMatadata\]\] internal method of <var>O</var> is called with [ECMAScript language value][] <var>MetadataKey</var> and [property key][] <var>P</var>, the following steps are taken:
1. Return [OrdinaryGetMetadata][](<var>MetadataKey</var>, <var>O</var>, <var>P</var>).
### OrdinaryGetMetadata ( MetadataKey, O, P )
When the abstract operation OrdinaryGetMetadata is called with [ECMAScript language value][] <var>MetadataKey</var>, Object <var>O</var>, and [property key][] <var>P</var>, the following steps are taken:
1. [Assert][]: <var>P</var> is **undefined** or [IsPropertyKey][](<var>P</var>) is **true**.
2. Let <var>hasOwn</var> be [OrdinaryHasOwnMetadata][](<var>MetadataKey</var>, <var>O</var>, <var>P</var>).
3. If <var>hasOwn</var> is **true**, then
1. return [OrdinaryGetOwnMetadata][](<var>MetadataKey</var>, <var>O</var>, <var>P</var>).
4. Let <var>parent</var> be <var>O</var>.\[\[GetPrototypeOf\]\]().
5. [ReturnIfAbrupt][](<var>parent</var>).
6. If <var>parent</var> is not **null**, then
1. return <var>parent</var>.\[\[GetMetadata\]\](<var>MetadataKey</var>, <var>P</var>).
7. Return **undefined**.
### \[\[GetOwnMetadata\]\] ( MetadataKey, P, ParamIndex )
When the \[\[GetOwnMetadata\]\] internal method of <var>O</var> is called with [ECMAScript language value][] <var>MetadataKey</var> and [property key][] <var>P</var>, the following steps are taken:
1. Return [OrdinaryGetOwnMetadata][](<var>MetadataKey</var>, <var>O</var>, <var>P</var>).
### OrdinaryGetOwnMetadata ( MetadataKey, O, P )
When the abstract operation OrdinaryGetOwnMetadata is called with [ECMAScript language value][] <var>MetadataKey</var>, Object <var>O</var>, and [property key][] <var>P</var>, the following steps are taken:
1. [Assert][]: <var>P</var> is **undefined** or [IsPropertyKey][](<var>P</var>) is **true**.
2. Let <var>metadataMap</var> be [GetOrCreateMetadataMap][](<var>O</var>, <var>P</var>, **false**).
3. [ReturnIfAbrupt][](<var>metadataMap</var>).
4. If <var>metadataMap</var> is **undefined**, return **undefined**.
5. Return [Invoke][](<var>metadataMap</var>, `"get"`, <var>MetadataKey</var>).
### \[\[DefineOwnMetadata\]\] ( MetadataKey, MetadataValue, P )
When the \[\[DefineOwnMetadata\]\] internal method of <var>O</var> is called with [ECMAScript language value][] <var>MetadataKey</var>, [ECMAScript language value][] <var>MetadataValue</var>, and [property key][] <var>P</var>, the following steps are taken:
1. Return [OrdinaryDefineOwnMetadata][](<var>MetadataKey</var>, <var>MetadataValue</var>, <var>O</var>, <var>P</var>)
### OrdinaryDefineOwnMetadata ( MetadataKey, MetadataValue, O, P )
When the abstract operation OrdinaryDefineOwnMetadata is called with [ECMAScript language value][] <var>MetadataKey</var>, [ECMAScript language value][] <var>MetadataValue</var>, Object <var>O</var>, and [property key][] <var>P</var>, the following steps are taken:
1. [Assert][]: <var>P</var> is **undefined** or [IsPropertyKey][](<var>P</var>) is **true**.
2. Let <var>metadataMap</var> be [GetOrCreateMetadataMap][](<var>O</var>, <var>P</var>, **true**).
3. [ReturnIfAbrupt][](<var>metadataMap</var>).
4. Return [Invoke][](<var>metadataMap</var>, `"set"`, <var>MetadataKey</var>, <var>MetadataValue</var>).
### \[\[MetadataKeys\]\] ( P )
When the \[\[MetadataKeys\]\] internal method of <var>O</var> is called with [property key][] <var>P</var> the following steps are taken:
1. Return [OrdinaryMetadataKeys][](<var>O</var>, <var>P</var>).
### OrdinaryMetadataKeys ( O, P )
When the abstract operation OrdinaryMetadataKeys is called with Object <var>O</var> and [property key][] <var>P</var>, the following steps are taken:
1. [Assert][]: <var>P</var> is **undefined** or [IsPropertyKey][](<var>P</var>) is **true**.
2. Let <var>ownKeys</var> be [OrdinaryOwnMetadataKeys][](<var>O</var>, <var>P</var>).
3. Let <var>parent</var> = <var>O</var>.\[\[GetPrototypeOf\]\]().
4. [ReturnIfAbrupt][](<var>parent</var>).
5. If <var>parent</var> is **null**, then return <var>ownKeys</var>.
6. Let <var>parentKeys</var> be <var>O</var>.\[\[OrdinaryMetadataKeys\]\](<var>P</var>).
7. [ReturnIfAbrupt][](<var>parentKeys</var>).
8. If <var>parentKeys</var> is empty, return <var>ownKeys</var>.
9. If <var>ownKeys</var> is empty, return <var>parentKeys</var>.
10. Let <var>set</var> be a newly created **Set** object.
11. Let <var>keys</var> be an empty [List][].
12. For each element <var>key</var> of <var>ownKeys</var>
1. Let <var>hasKey</var> be [Invoke][](<var>set</var>, `"has"`, <var>key</var>).
2. [ReturnIfAbrupt][](<var>hasKey</var>).
3. If <var>hasKey</var> is **false**, then
1. Let <var>addStatus</var> be [Invoke][](<var>set</var>, `"add"`, <var>key</var>).
2. [ReturnIfAbrupt][](<var>addStatus</var>).
3. Append <var>key</var> as an element of <var>keys</var>.
13. For each element <var>key</var> of <var>parentKeys</var>
1. Let <var>hasKey</var> be [Invoke][](<var>set</var>, `"has"`, <var>key</var>).
2. [ReturnIfAbrupt][](<var>hasKey</var>).
3. If <var>hasKey</var> is **false**, then
1. Let <var>addStatus</var> be [Invoke][](<var>set</var>, `"add"`, <var>key</var>).
2. [ReturnIfAbrupt][](<var>addStatus</var>).
3. Append <var>key</var> as an element of <var>keys</var>.
14. Return <var>keys</var>.
### \[\[OwnMetadataKeys\]\] ( P )
When the \[\[OwnMetadataKeys\]\] internal method of <var>O</var> is called with [property key][] <var>P</var>, the following steps are taken:
1. Return [OrdinaryOwnMetadataKeys][](<var>O</var>, <var>P</var>).
### OrdinaryOwnMetadataKeys ( O, P )
When the abstract operation OrdinaryOwnMetadataKeys is called with Object <var>O</var> and [property key][] <var>P</var> the following steps are taken:
1. [Assert][]: <var>P</var> is **undefined** or [IsPropertyKey][](<var>P</var>) is **true**.
2. Let <var>metadataMap</var> be [GetOrCreateMetadataMap][](<var>O</var>, <var>P</var>, **false**).
3. [ReturnIfAbrupt][](<var>metadataMap</var>).
4. Let <var>keys</var> be an empty [List][].
5. If <var>metadataMap</var> is **undefined**, return <var>keys</var>.
6. Let <var>keysObj</var> be [Invoke][](<var>metadataMap</var>, `"keys"`).
7. [ReturnIfAbrupt][](<var>keysObj</var>).
8. Let <var>iterator</var> be [GetIterator][](<var>keysObj</var>).
9. [ReturnIfAbrupt][](<var>iterator</var>).
10. Repeat
1. Let <var>next</var> be [IteratorStep][](<var>iterator</var>).
2. [ReturnIfAbrupt][](<var>next</var>).
3. If <var>next</var> is **false**, then
1. Return <var>keys</var>.
4. Let <var>nextValue</var> be [IteratorValue][](<var>next</var>).
5. [ReturnIfAbrupt][](<var>nextValue</var>).
6. Append <var>nextValue</var> as an element of <var>keys</var>.
### \[\[DeleteMetadata\]\]( MetadataKey, P )
When the \[\[DeleteMetadata\]\] internal method of <var>O</var> is called with [ECMAScript language value][] <var>MetadataKey</var> and [property key][] <var>P</var> the following steps are taken:
1. [Assert][]: <var>P</var> is **undefined** or [IsPropertyKey][](<var>P</var>) is **true**.
2. Let <var>metadataMap</var> be [GetOrCreateMetadataMap][](<var>O</var>, <var>P</var>, **false**).
3. [ReturnIfAbrupt][](<var>metadataMap</var>).
4. If <var>metadataMap</var> is **undefined**, return **false**.
5. Return [ToBoolean][]([Invoke][](<var>metadataMap</var>, `"delete"`, <var>MetadataKey</var>)).
## 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 <var>O</var> is called with [ECMAScript language value][] <var>MetadataKey</var> and [property key][] <var>P</var>, the following steps are taken:
1. [Assert][]: <var>P</var> is **undefined** or [IsPropertyKey][](<var>P</var>) is **true**.
2. Let <var>handler</var> be the value of the \[\[ProxyHandler\]\] [internal slot][] of <var>O</var>.
3. If <var>handler</var> is **null**, throw a **TypeError** exception.
4. [Assert][]: [Type][](<var>handler</var>) is Object.
5. Let <var>target</var> be the value of the \[\[ProxyTarget\]\] [internal slot][] of <var>O</var>.
6. Let <var>trap</var> be [GetMethod][](<var>handler</var>, `"hasMetadata"`).
7. [ReturnIfAbrupt][](<var>trap</var>).
8. If <var>trap</var> is **undefined**, then
1. Return <var>target</var>.\[\[HasMetadata\]\](<var>metadataKey</var>, <var>P</var>).
9. Return [ToBoolean][]([Call][](<var>trap</var>, <var>handler</var>, «<var>metadataKey</var>, <var>target</var>, <var>P</var>»)).
### \[\[HasOwnMetadata\]\] ( MetadataKey, P )
When the \[\[HasOwnMetadata\]\] internal method of a Proxy exotic object <var>O</var> is called with [ECMAScript language value][] <var>MetadataKey</var> and [property key][] <var>P</var>, the following steps are taken:
1. [Assert][]: <var>P</var> is **undefined** or [IsPropertyKey][](<var>P</var>) is **true**.
2. Let <var>handler</var> be the value of the \[\[ProxyHandler\]\] [internal slot][] of <var>O</var>.
3. If <var>handler</var> is **null**, throw a **TypeError** exception.
4. [Assert][]: [Type][](<var>handler</var>) is Object.
5. Let <var>target</var> be the value of the \[\[ProxyTarget\]\] [internal slot][] of <var>O</var>.
6. Let <var>trap</var> be [GetMethod][](<var>handler</var>, `"hasOwnMetadata"`).
7. [ReturnIfAbrupt][](<var>trap</var>).
8. If <var>trap</var> is **undefined**, then
1. Return <var>target</var>.\[\[HasOwnMetadata\]\](<var>metadataKey</var>, <var>P</var>).
9. Return [ToBoolean][]([Call][](<var>trap</var>, <var>handler</var>, «<var>metadataKey</var>, <var>target</var>, <var>P</var>»)).
### \[\[GetMetadata\]\] ( MetadataKey, P )
When the \[\[GetMatadata\]\] internal method of a Proxy exotic object <var>O</var> is called with [ECMAScript language value][] <var>MetadataKey</var> and [property key][] <var>P</var>, the following steps are taken:
1. [Assert][]: <var>P</var> is **undefined** or [IsPropertyKey][](<var>P</var>) is **true**.
2. Let <var>handler</var> be the value of the \[\[ProxyHandler\]\] [internal slot][] of <var>O</var>.
3. If <var>handler</var> is **null**, throw a **TypeError** exception.
4. [Assert][]: [Type][](<var>handler</var>) is Object.
5. Let <var>target</var> be the value of the \[\[ProxyTarget\]\] [internal slot][] of <var>O</var>.
6. Let <var>trap</var> be [GetMethod][](<var>handler</var>, `"getMetadata"`).
7. [ReturnIfAbrupt][](<var>trap</var>).
8. If <var>trap</var> is **undefined**, then
1. Return <var>target</var>.\[\[GetMetadata\]\](<var>metadataKey</var>, <var>P</var>).
9. Return [Call][](<var>trap</var>, <var>handler</var>, «<var>metadataKey</var>, <var>target</var>, <var>P</var>»).
### \[\[GetOwnMetadata\]\] ( MetadataKey, P, ParamIndex )
When the \[\[GetOwnMetadata\]\] internal method of a Proxy exotic object <var>O</var> is called with [ECMAScript language value][] <var>MetadataKey</var> and [property key][] <var>P</var>, the following steps are taken:
1. [Assert][]: <var>P</var> is **undefined** or [IsPropertyKey][](<var>P</var>) is **true**.
2. Let <var>handler</var> be the value of the \[\[ProxyHandler\]\] [internal slot][] of <var>O</var>.
3. If <var>handler</var> is **null**, throw a **TypeError** exception.
4. [Assert][]: [Type][](<var>handler</var>) is Object.
5. Let <var>target</var> be the value of the \[\[ProxyTarget\]\] [internal slot][] of <var>O</var>.
6. Let <var>trap</var> be [GetMethod][](<var>handler</var>, `"getOwnMetadata"`).
7. [ReturnIfAbrupt][](<var>trap</var>).
8. If <var>trap</var> is **undefined**, then
1. Return <var>target</var>.\[\[GetOwnMetadata\]\](<var>metadataKey</var>, <var>P</var>).
9. Return [Call][](<var>trap</var>, <var>handler</var>, «<var>metadataKey</var>, <var>target</var>, <var>P</var>»).
### \[\[DefineOwnMetadata\]\] ( MetadataKey, MetadataValue, P )
When the \[\[DefineOwnMetadata\]\] internal method of a Proxy exotic object <var>O</var> is called with [ECMAScript language value][] <var>MetadataKey</var>, [ECMAScript language value][] <var>MetadataValue</var>, and [property key][] <var>P</var>, the following steps are taken:
1. [Assert][]: <var>P</var> is **undefined** or [IsPropertyKey][](<var>P</var>) is **true**.
2. Let <var>handler</var> be the value of the \[\[ProxyHandler\]\] [internal slot][] of <var>O</var>.
3. If <var>handler</var> is **null**, throw a **TypeError** exception.
4. [Assert][]: [Type][](<var>handler</var>) is Object.
5. Let <var>target</var> be the value of the \[\[ProxyTarget\]\] [internal slot][] of <var>O</var>.
6. Let <var>trap</var> be [GetMethod][](<var>handler</var>, `"defineMetadata"`).
7. [ReturnIfAbrupt][](<var>trap</var>).
8. If <var>trap</var> is **undefined**, then
1. Return <var>target</var>.\[\[DefineOwnMetadata\]\](<var>metadataKey</var>, <var>metadataValue</var>, <var>P</var>).
9. Return [Call][](<var>trap</var>, <var>handler</var>, «<var>metadataKey</var>, <var>metadataValue</var>, <var>target</var>, <var>P</var>»).
### \[\[MetadataKeys\]\] ( P )
When the \[\[MetadataKeys\]\] internal method of a Proxy exotic object <var>O</var> is called with [property key][] <var>P</var> the following steps are taken:
1. [Assert][]: <var>P</var> is **undefined** or [IsPropertyKey][](<var>P</var>) is **true**.
2. Let <var>handler</var> be the value of the \[\[ProxyHandler\]\] [internal slot][] of <var>O</var>.
3. If <var>handler</var> is **null**, throw a **TypeError** exception.
4. [Assert][]: [Type][](<var>handler</var>) is Object.
5. Let <var>target</var> be the value of the \[\[ProxyTarget\]\] [internal slot][] of <var>O</var>.
6. Let <var>trap</var> be [GetMethod][](<var>handler</var>, `"metadataKeys"`).
7. [ReturnIfAbrupt][](<var>trap</var>).
8. If <var>trap</var> is **undefined**, then
1. Return <var>target</var>.\[\[MetadataKeys\]\](<var>P</var>).
9. Let <var>trapResultArray</var> be [Call][](<var>trap</var>, <var>handler</var>, «<var>target</var>, <var>P</var>»).
10. Return [CreateListFromArrayLike][](<var>trapResultArray</var>).
### \[\[OwnMetadataKeys\]\] ( P )
When the \[\[OwnMetadataKeys\]\] internal method of a Proxy exotic object <var>O</var> is called with [property key][] <var>P</var> the following steps are taken:
1. [Assert][]: <var>P</var> is **undefined** or [IsPropertyKey][](<var>P</var>) is **true**.
2. Let <var>handler</var> be the value of the \[\[ProxyHandler\]\] [internal slot][] of <var>O</var>.
3. If <var>handler</var> is **null**, throw a **TypeError** exception.
4. [Assert][]: [Type][](<var>handler</var>) is Object.
5. Let <var>target</var> be the value of the \[\[ProxyTarget\]\] [internal slot][] of <var>O</var>.
6. Let <var>trap</var> be [GetMethod][](<var>handler</var>, `"ownMetadataKeys"`).
7. [ReturnIfAbrupt][](<var>trap</var>).
8. If <var>trap</var> is **undefined**, then
1. Return <var>target</var>.\[\[OwnMetadataKeys\]\](<var>P</var>).
9. Let <var>trapResultArray</var> be [Call][](<var>trap</var>, <var>handler</var>, «<var>target</var>, <var>P</var>»).
10. Return [CreateListFromArrayLike][](<var>trapResultArray</var>).
### \[\[DeleteMetadata\]\]( MetadataKey, P )
When the \[\[DeleteMetadata\]\] internal method of a Proxy exotic object <var>O</var> is called with [ECMAScript language value][] <var>MetadataKey</var> and [property key][] <var>P</var> the following steps are taken:
1. [Assert][]: <var>P</var> is **undefined** or [IsPropertyKey][](<var>P</var>) is **true**.
2. Let <var>handler</var> be the value of the \[\[ProxyHandler\]\] [internal slot][] of <var>O</var>.
3. If <var>handler</var> is **null**, throw a **TypeError** exception.
4. [Assert][]: [Type][](<var>handler</var>) is Object.
5. Let <var>target</var> be the value of the \[\[ProxyTarget\]\] [internal slot][] of <var>O</var>.
6. Let <var>trap</var> be [GetMethod][](<var>handler</var>, `"deleteMetadata"`).
7. [ReturnIfAbrupt][](<var>trap</var>).
8. If <var>trap</var> is **undefined**, then
1. Return <var>target</var>.\[\[DeleteMetadata\]\](<var>metadataKey</var>, <var>P</var>).
9. Return [ToBoolean][]([Call][](<var>trap</var>, <var>handler</var>, «<var>metadataKey</var>, <var>target</var>, <var>P</var>»)).
# 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 <var>F</var> is called with arguments <var>target</var> and <var>propertyKey</var>, the following steps are taken:
1. [Assert][]: <var>F</var> has a \[\[MetadataKey\]\] [internal slot][] whose value is an ECMAScript language value, or **undefined**.
2. [Assert][]: <var>F</var> has a \[\[MetadataValue\]\] [internal slot][] whose value is an ECMAScript language value, or **undefined**.
3. If [Type][](<var>target</var>) is not Object, throw a **TypeError** exception.
4. Let <var>key</var> be **undefined**.
5. If <var>propertyKey</var> is not **undefined**, then
1. Set <var>key</var> to be [ToPropertyKey][](<var>propertyKey</var>).
6. [ReturnIfAbrupt][](<var>key</var>).
7. Let <var>metadataKey</var> be the value of <var>F</var>'s \[\[MetadataKey\]\] [internal slot][].
8. Let <var>metadataValue</var> be the value of <var>F</var>'s \[\[MetadataValue\]\] [internal slot][].
9. Return <var>target</var>.\[\[DefineMetadata\]\](<var>metadataKey</var>, <var>metadataValue</var>, <var>target</var>, <var>key</var>).
### Reflect.metadata ( metadataKey, metadataValue )
When the `metadata` function is called with arguments <var>metadataKey</var> and <var>metadataValue</var>, the following steps are taken:
1. Let <var>decorator</var> be a new built-in function object as defined in [Metadata Decorator Functions][mdf].
2. Set the \[\[MetadataKey\]\] [internal slot][] of <var>decorator</var> to <var>metadataKey</var>.
3. Set the \[\[MetadataValue\]\] [internal slot][] of <var>decorator</var> to <var>metadataValue</var>.
4. return <var>decorator</var>.
### Reflect.defineMetadata ( metadataKey, metadataValue, target, propertyKey )
When the `defineMetadata` function is called with arguments <var>metadataKey</var>, <var>metadataValue</var>, <var>target</var>, and <var>propertyKey</var>, the following steps are taken:
1. If [Type][](<var>target</var>) is not Object, throw a **TypeError** exception.
2. Let <var>key</var> be **undefined**.
3. If <var>propertyKey</var> is not **undefined**, then
1. Set <var>key</var> to be [ToPropertyKey][](<var>propertyKey</var>).
2. [ReturnIfAbrupt][](<var>key</var>).
4. return <var>target</var>.\[\[DefineMetadata\]\](<var>metadataKey</var>, <var>metadataValue</var>, <var>key</var>).
### Reflect.hasMetadata ( metadataKey, target \[, propertyKey\] )
When the `hasMetadata` function is called with arguments <var>metadataKey</var>, <var>target</var>, and <var>propertyKey</var>, the following steps are taken:
1. If [Type][](<var>target</var>) is not Object, throw a **TypeError** exception.
2. Let <var>key</var> be **undefined**.
3. If <var>propertyKey</var> is not **undefined**, then
1. Set <var>key</var> to be [ToPropertyKey][](<var>propertyKey</var>).
2. [ReturnIfAbrupt][](<var>key</var>).
4. return <var>target</var>.\[\[HasMetadata\]\](<var>metadataKey</var>, <var>key</var>).
### Reflect.hasOwnMetadata ( metadataKey, target \[, propertyKey\] )
When the `hasOwnMetadata` function is called with arguments <var>metadataKey</var>, <var>target</var>, and <var>propertyKey</var>, the following steps are taken:
1. If [Type][](<var>target</var>) is not Object, throw a **TypeError** exception.
2. Let <var>key</var> be **undefined**.
3. If <var>propertyKey</var> is not **undefined**, then
1. Set <var>key</var> to be [ToPropertyKey][](<var>propertyKey</var>).
2. [ReturnIfAbrupt][](<var>key</var>).
4. return <var>target</var>.\[\[HasOwn\]\](<var>metadataKey</var>, <var>key</var>).
### Reflect.getMetadata ( metadataKey, target \[, propertyKey\] )
When the `getMetadata` function is called with arguments <var>metadataKey</var>, <var>target</var>, and <var>propertyKey</var>, the following steps are taken:
1. If [Type][](<var>target</var>) is not Object, throw a **TypeError** exception.
2. Let <var>key</var> be **undefined**.
3. If <var>propertyKey</var> is not **undefined**, then
1. Set <var>key</var> to be [ToPropertyKey][](<var>propertyKey</var>).
2. [ReturnIfAbrupt][](<var>key</var>).
4. return <var>target</var>.\[\[GetMetadata\]\](<var>metadataKey</var>, <var>key</var>).
### Reflect.getOwnMetadata ( metadataKey, target \[, propertyKey\] )
When the `getOwnMetadata` function is called with arguments <var>metadataKey</var>, <var>target</var>, and <var>propertyKey</var>, the following steps are taken:
1. If [Type][](<var>target</var>) is not Object, throw a **TypeError** exception.
2. Let <var>key</var> be **undefined**.
3. If <var>propertyKey</var> is not **undefined**, then
1. Set <var>key</var> to be [ToPropertyKey][](<var>propertyKey</var>).
2. [ReturnIfAbrupt][](<var>key</var>).
4. return <var>target</var>.\[\[GetOwnMetadata\]\](<var>metadataKey</var>, <var>key</var>).
### Reflect.getMetadataKeys ( target \[, propertyKey\] )
When the `getMetadataKeys` function is called with arguments <var>target</var> and <var>propertyKey</var>, the following steps are taken:
1. If [Type][](<var>target</var>) is not Object, throw a **TypeError** exception.
2. Let <var>key</var> be **undefined**.
3. If <var>propertyKey</var> is not **undefined**, then
1. Set <var>key</var> to be [ToPropertyKey][](<var>propertyKey</var>).
2. [ReturnIfAbrupt][](<var>key</var>).
4. Let <var>keys</var> be <var>target</var>.\[\[GetMetadataKeys\]\](<var>key</var>).
5. Return [CreateArrayFromList][](<var>keys</var>).
### Reflect.getOwnMetadataKeys ( target \[, propertyKey\] )
When the `getOwnMetadataKeys` function is called with arguments <var>target</var> and <var>propertyKey</var>, the following steps are taken:
1. If [Type][](<var>target</var>) is not Object, throw a **TypeError** exception.
2. Let <var>key</var> be **undefined**.
3. If <var>propertyKey</var> is not **undefined**, then
1. Set <var>key</var> to be [ToPropertyKey][](<var>propertyKey</var>).
2. [ReturnIfAbrupt][](<var>key</var>).
4. Let <var>keys</var> be <var>target</var>.\[\[GetOwnMetadataKeys\]\](<var>key</var>).
5. Return [CreateArrayFromList][](<var>keys</var>).
### Reflect.deleteMetadata ( metadataKey, target \[, propertyKey\] )
When the `deleteMetadata` function is called with arguments <var>metadataKey</var>, <var>target</var>, and <var>propertyKey</var>, the following steps are taken:
1. If [Type][](<var>target</var>) is not Object, throw a **TypeError** exception.
2. Let <var>key</var> be **undefined**.
3. If <var>propertyKey</var> is not **undefined**, then
1. Set <var>key</var> to be [ToPropertyKey][](<var>propertyKey</var>).
2. [ReturnIfAbrupt][](<var>key</var>).
4. return <var>target</var>.\[\[DeleteMetadata\]\](<var>metadataKey</var>, <var>key</var>).
[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/

@@ -35,4 +35,4 @@ /*! *****************************************************************************

* @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.

@@ -67,3 +67,3 @@ * @example

*/
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;
/**

@@ -111,3 +111,3 @@ * A default metadata decorator factory that can be used on a class, class member, or parameter.

(target: Function): void;
(target: Object, targetKey: string | symbol): void;
(target: Object, propertyKey: string | symbol): void;
};

@@ -139,3 +139,3 @@ /**

* @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

@@ -170,3 +170,3 @@ *

*/
function defineMetadata(metadataKey: any, metadataValue: any, target: Object, targetKey: string | symbol): void;
function defineMetadata(metadataKey: any, metadataValue: any, target: Object, propertyKey: string | symbol): void;
/**

@@ -191,3 +191,3 @@ * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined.

* @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`.

@@ -218,3 +218,3 @@ * @example

*/
function hasMetadata(metadataKey: any, target: Object, targetKey: string | symbol): boolean;
function hasMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): boolean;
/**

@@ -239,3 +239,3 @@ * Gets a value indicating whether the target object has the provided metadata key defined.

* @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`.

@@ -266,3 +266,3 @@ * @example

*/
function hasOwnMetadata(metadataKey: any, target: Object, targetKey: string | symbol): boolean;
function hasOwnMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): boolean;
/**

@@ -287,3 +287,3 @@ * Gets the metadata value for the provided metadata key 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 The metadata value for the metadata key if found; otherwise, `undefined`.

@@ -314,3 +314,3 @@ * @example

*/
function getMetadata(metadataKey: any, target: Object, targetKey: string | symbol): any;
function getMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): any;
/**

@@ -335,3 +335,3 @@ * Gets the metadata value for the provided metadata key 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 The metadata value for the metadata key if found; otherwise, `undefined`.

@@ -362,3 +362,3 @@ * @example

*/
function getOwnMetadata(metadataKey: any, target: Object, targetKey: string | symbol): any;
function getOwnMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): any;
/**

@@ -381,3 +381,3 @@ * 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.

@@ -408,3 +408,3 @@ * @example

*/
function getMetadataKeys(target: Object, targetKey: string | symbol): any[];
function getMetadataKeys(target: Object, propertyKey: string | symbol): any[];
/**

@@ -427,3 +427,3 @@ * 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.

@@ -454,3 +454,3 @@ * @example

*/
function getOwnMetadataKeys(target: Object, targetKey: string | symbol): any[];
function getOwnMetadataKeys(target: Object, propertyKey: string | symbol): any[];
/**

@@ -475,3 +475,3 @@ * Deletes the metadata entry from the target object with the provided key.

* @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.

@@ -502,3 +502,3 @@ * @example

*/
function deleteMetadata(metadataKey: any, target: Object, targetKey: string | symbol): boolean;
function deleteMetadata(metadataKey: any, target: Object, propertyKey: string | symbol): boolean;
}

@@ -7,21 +7,9 @@ {

"module": "commonjs",
"outDir": "../temp/"
"types": ["node", "mocha"],
"typeRoots": ["../../node_modules/@types"],
"rootDir": "."
},
"files": [
"../Reflect.ts",
"../typings/node.d.ts",
"reflect/reflect-decorate.ts",
"reflect/reflect-metadata.ts",
"reflect/reflect-definemetadata.ts",
"reflect/reflect-hasownmetadata.ts",
"reflect/reflect-hasmetadata.ts",
"reflect/reflect-getownmetadata.ts",
"reflect/reflect-getmetadata.ts",
"reflect/reflect-getownmetadatakeys.ts",
"reflect/reflect-getmetadatakeys.ts",
"reflect/reflect-deletemetadata.ts",
"harness.ts",
"spec.ts",
"run.ts"
"include": [
"**/*.ts"
]
}
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"newLine": "LF",
"sourceMap": true,
"strictNullChecks": true,
"noImplicitAny": true,
"sourceMap": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"strictNullChecks": true
"noImplicitReturns": true,
"noImplicitThis": true
},

@@ -10,0 +14,0 @@ "files": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc