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