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

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