implementation.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. var CreateDataProperty = require('es-abstract/2021/CreateDataProperty');
  3. var IsCallable = require('es-abstract/2021/IsCallable');
  4. var RequireObjectCoercible = require('es-abstract/2021/RequireObjectCoercible');
  5. var ToObject = require('es-abstract/2021/ToObject');
  6. var callBound = require('call-bind/callBound');
  7. var reduce = require('array.prototype.reduce');
  8. var $gOPD = Object.getOwnPropertyDescriptor;
  9. var $getOwnNames = Object.getOwnPropertyNames;
  10. var $getSymbols = Object.getOwnPropertySymbols;
  11. var $concat = callBound('Array.prototype.concat');
  12. var getAll = $getSymbols ? function (obj) {
  13. return $concat($getOwnNames(obj), $getSymbols(obj));
  14. } : $getOwnNames;
  15. var isES5 = IsCallable($gOPD) && IsCallable($getOwnNames);
  16. module.exports = function getOwnPropertyDescriptors(value) {
  17. RequireObjectCoercible(value);
  18. if (!isES5) {
  19. throw new TypeError('getOwnPropertyDescriptors requires Object.getOwnPropertyDescriptor');
  20. }
  21. var O = ToObject(value);
  22. return reduce(
  23. getAll(O),
  24. function (acc, key) {
  25. var descriptor = $gOPD(O, key);
  26. if (typeof descriptor !== 'undefined') {
  27. CreateDataProperty(acc, key, descriptor);
  28. }
  29. return acc;
  30. },
  31. {}
  32. );
  33. };