implementation.js 1.1 KB

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