esnext.reflect.get-metadata.js 1.1 KB

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