object-get-own-property-descriptor.js 1.1 KB

12345678910111213141516171819202122
  1. var DESCRIPTORS = require('../internals/descriptors');
  2. var call = require('../internals/function-call');
  3. var propertyIsEnumerableModule = require('../internals/object-property-is-enumerable');
  4. var createPropertyDescriptor = require('../internals/create-property-descriptor');
  5. var toIndexedObject = require('../internals/to-indexed-object');
  6. var toPropertyKey = require('../internals/to-property-key');
  7. var hasOwn = require('../internals/has-own-property');
  8. var IE8_DOM_DEFINE = require('../internals/ie8-dom-define');
  9. // eslint-disable-next-line es-x/no-object-getownpropertydescriptor -- safe
  10. var $getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  11. // `Object.getOwnPropertyDescriptor` method
  12. // https://tc39.es/ecma262/#sec-object.getownpropertydescriptor
  13. exports.f = DESCRIPTORS ? $getOwnPropertyDescriptor : function getOwnPropertyDescriptor(O, P) {
  14. O = toIndexedObject(O);
  15. P = toPropertyKey(P);
  16. if (IE8_DOM_DEFINE) try {
  17. return $getOwnPropertyDescriptor(O, P);
  18. } catch (error) { /* empty */ }
  19. if (hasOwn(O, P)) return createPropertyDescriptor(!call(propertyIsEnumerableModule.f, O, P), O[P]);
  20. };