esnext.reflect.get-metadata.js 1.0 KB

123456789101112131415161718192021222324
  1. var $ = require('../internals/export');
  2. var ReflectMetadataModule = require('../internals/reflect-metadata');
  3. var anObject = require('../internals/an-object');
  4. var getPrototypeOf = require('../internals/object-get-prototype-of');
  5. var ordinaryHasOwnMetadata = ReflectMetadataModule.has;
  6. var ordinaryGetOwnMetadata = ReflectMetadataModule.get;
  7. var toMetadataKey = ReflectMetadataModule.toKey;
  8. var ordinaryGetMetadata = function (MetadataKey, O, P) {
  9. var hasOwn = ordinaryHasOwnMetadata(MetadataKey, O, P);
  10. if (hasOwn) return ordinaryGetOwnMetadata(MetadataKey, O, P);
  11. var parent = getPrototypeOf(O);
  12. return parent !== null ? ordinaryGetMetadata(MetadataKey, parent, P) : undefined;
  13. };
  14. // `Reflect.getMetadata` method
  15. // https://github.com/rbuckton/reflect-metadata
  16. $({ target: 'Reflect', stat: true }, {
  17. getMetadata: function getMetadata(metadataKey, target /* , targetKey */) {
  18. var targetKey = arguments.length < 3 ? undefined : toMetadataKey(arguments[2]);
  19. return ordinaryGetMetadata(metadataKey, anObject(target), targetKey);
  20. }
  21. });