implementation.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. var CreateDataProperty = require('es-abstract/2023/CreateDataProperty');
  3. var IsCallable = require('es-abstract/2023/IsCallable');
  4. var RequireObjectCoercible = require('es-abstract/2023/RequireObjectCoercible');
  5. var ToObject = require('es-abstract/2023/ToObject');
  6. var safeConcat = require('safe-array-concat');
  7. var reduce = require('array.prototype.reduce');
  8. var $gOPD = Object.getOwnPropertyDescriptor;
  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 = IsCallable($gOPD) && IsCallable($getOwnNames);
  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. };