[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
[79a0317] | 3 | var callBound = require('call-bound');
|
---|
[d565449] | 4 |
|
---|
| 5 | var DefinePropertyOrThrow = require('./DefinePropertyOrThrow');
|
---|
| 6 | var Get = require('./Get');
|
---|
| 7 | var ToObject = require('./ToObject');
|
---|
| 8 | var ToPropertyDescriptor = require('./ToPropertyDescriptor');
|
---|
| 9 |
|
---|
| 10 | var forEach = require('../helpers/forEach');
|
---|
| 11 | var getOwnPropertyDescriptor = require('gopd');
|
---|
[79a0317] | 12 | var OwnPropertyKeys = require('own-keys');
|
---|
[d565449] | 13 |
|
---|
| 14 | var $push = callBound('Array.prototype.push');
|
---|
| 15 |
|
---|
| 16 | // https://262.ecma-international.org/6.0/#sec-objectdefineproperties
|
---|
[79a0317] | 17 |
|
---|
| 18 | /** @type {<T extends Record<PropertyKey, unknown> = {}>(O: T, Properties: object) => T} */
|
---|
[d565449] | 19 | module.exports = function ObjectDefineProperties(O, Properties) {
|
---|
| 20 | var props = ToObject(Properties); // step 1
|
---|
| 21 | var keys = OwnPropertyKeys(props); // step 2
|
---|
[79a0317] | 22 | /** @type {[string | symbol, import('../types').Descriptor][]} */
|
---|
[d565449] | 23 | var descriptors = []; // step 3
|
---|
| 24 |
|
---|
| 25 | forEach(keys, function (nextKey) { // step 4
|
---|
| 26 | var propDesc = ToPropertyDescriptor(getOwnPropertyDescriptor(props, nextKey)); // step 4.a
|
---|
| 27 | if (typeof propDesc !== 'undefined' && propDesc['[[Enumerable]]']) { // step 4.b
|
---|
| 28 | var descObj = Get(props, nextKey); // step 4.b.i
|
---|
| 29 | var desc = ToPropertyDescriptor(descObj); // step 4.b.ii
|
---|
| 30 | $push(descriptors, [nextKey, desc]); // step 4.b.iii
|
---|
| 31 | }
|
---|
| 32 | });
|
---|
| 33 |
|
---|
| 34 | forEach(descriptors, function (pair) { // step 5
|
---|
| 35 | var P = pair[0]; // step 5.a
|
---|
| 36 | var desc = pair[1]; // step 5.b
|
---|
| 37 | DefinePropertyOrThrow(O, P, desc); // step 5.c
|
---|
| 38 | });
|
---|
| 39 |
|
---|
| 40 | return O; // step 6
|
---|
| 41 | };
|
---|