es.reflect.get.js 1.1 KB

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