bigint-crypto-utils/node_modules/object.getownpropertydescri.../implementation.js

39 lines
1.2 KiB
JavaScript

'use strict';
var CreateDataProperty = require('es-abstract/2019/CreateDataProperty');
var IsCallable = require('es-abstract/2019/IsCallable');
var RequireObjectCoercible = require('es-abstract/2019/RequireObjectCoercible');
var ToObject = require('es-abstract/2019/ToObject');
var callBound = require('es-abstract/helpers/callBound');
var $gOPD = Object.getOwnPropertyDescriptor;
var $getOwnNames = Object.getOwnPropertyNames;
var $getSymbols = Object.getOwnPropertySymbols;
var $concat = callBound('Array.prototype.concat');
var $reduce = callBound('Array.prototype.reduce');
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;
},
{}
);
};