1 | 'use strict';
|
---|
2 |
|
---|
3 | var callBound = require('call-bind/callBound');
|
---|
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');
|
---|
12 | var OwnPropertyKeys = require('../helpers/OwnPropertyKeys');
|
---|
13 |
|
---|
14 | var $push = callBound('Array.prototype.push');
|
---|
15 |
|
---|
16 | // https://262.ecma-international.org/15.0/#sec-objectdefineproperties
|
---|
17 |
|
---|
18 | module.exports = function ObjectDefineProperties(O, Properties) {
|
---|
19 | var props = ToObject(Properties); // step 1
|
---|
20 | var keys = OwnPropertyKeys(props); // step 2
|
---|
21 | var descriptors = []; // step 3
|
---|
22 |
|
---|
23 | forEach(keys, function (nextKey) { // step 4
|
---|
24 | var propDesc = ToPropertyDescriptor(getOwnPropertyDescriptor(props, nextKey)); // step 4.a
|
---|
25 | if (typeof propDesc !== 'undefined' && propDesc['[[Enumerable]]']) { // step 4.b
|
---|
26 | var descObj = Get(props, nextKey); // step 4.b.i
|
---|
27 | var desc = ToPropertyDescriptor(descObj); // step 4.b.ii
|
---|
28 | $push(descriptors, { '[[Key]]': nextKey, '[[Descriptor]]': desc }); // step 4.b.iii
|
---|
29 | }
|
---|
30 | });
|
---|
31 |
|
---|
32 | forEach(descriptors, function (pair) { // step 5
|
---|
33 | DefinePropertyOrThrow(O, pair['[[Key]]'], pair['[[Descriptor]]']); // step 5.c
|
---|
34 | });
|
---|
35 |
|
---|
36 | return O; // step 6
|
---|
37 | };
|
---|