esnext.reflect.get-metadata.js 1.1 KB

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