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