es.reflect.get.js 1.1 KB

123456789101112131415161718192021222324
  1. var $ = require('../internals/export');
  2. var call = require('../internals/function-call');
  3. var isObject = require('../internals/is-object');
  4. var anObject = require('../internals/an-object');
  5. var isDataDescriptor = require('../internals/is-data-descriptor');
  6. var getOwnPropertyDescriptorModule = require('../internals/object-get-own-property-descriptor');
  7. var getPrototypeOf = require('../internals/object-get-prototype-of');
  8. // `Reflect.get` method
  9. // https://tc39.es/ecma262/#sec-reflect.get
  10. function get(target, propertyKey /* , receiver */) {
  11. var receiver = arguments.length < 3 ? target : arguments[2];
  12. var descriptor, prototype;
  13. if (anObject(target) === receiver) return target[propertyKey];
  14. descriptor = getOwnPropertyDescriptorModule.f(target, propertyKey);
  15. if (descriptor) return isDataDescriptor(descriptor)
  16. ? descriptor.value
  17. : descriptor.get === undefined ? undefined : call(descriptor.get, receiver);
  18. if (isObject(prototype = getPrototypeOf(target))) return get(prototype, propertyKey, receiver);
  19. }
  20. $({ target: 'Reflect', stat: true }, {
  21. get: get
  22. });