esnext.reflect.get-metadata-keys.js 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. var $ = require('../internals/export');
  2. // TODO: in core-js@4, move /modules/ dependencies to public entries for better optimization by tools like `preset-env`
  3. var Set = require('../modules/es.set');
  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 iterate = require('../internals/iterate');
  8. var ordinaryOwnMetadataKeys = ReflectMetadataModule.keys;
  9. var toMetadataKey = ReflectMetadataModule.toKey;
  10. var from = function (iter) {
  11. var result = [];
  12. iterate(iter, result.push, result);
  13. return result;
  14. };
  15. var ordinaryMetadataKeys = function (O, P) {
  16. var oKeys = ordinaryOwnMetadataKeys(O, P);
  17. var parent = getPrototypeOf(O);
  18. if (parent === null) return oKeys;
  19. var pKeys = ordinaryMetadataKeys(parent, P);
  20. return pKeys.length ? oKeys.length ? from(new Set(oKeys.concat(pKeys))) : pKeys : oKeys;
  21. };
  22. // `Reflect.getMetadataKeys` method
  23. // https://github.com/rbuckton/reflect-metadata
  24. $({ target: 'Reflect', stat: true }, {
  25. getMetadataKeys: function getMetadataKeys(target /* , targetKey */) {
  26. var targetKey = arguments.length < 2 ? undefined : toMetadataKey(arguments[1]);
  27. return ordinaryMetadataKeys(anObject(target), targetKey);
  28. }
  29. });