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/6.0/#sec-objectdefineproperties
|
---|
17 | module.exports = function ObjectDefineProperties(O, Properties) {
|
---|
18 | var props = ToObject(Properties); // step 1
|
---|
19 | var keys = OwnPropertyKeys(props); // step 2
|
---|
20 | var descriptors = []; // step 3
|
---|
21 |
|
---|
22 | forEach(keys, function (nextKey) { // step 4
|
---|
23 | var propDesc = ToPropertyDescriptor(getOwnPropertyDescriptor(props, nextKey)); // step 4.a
|
---|
24 | if (typeof propDesc !== 'undefined' && propDesc['[[Enumerable]]']) { // step 4.b
|
---|
25 | var descObj = Get(props, nextKey); // step 4.b.i
|
---|
26 | var desc = ToPropertyDescriptor(descObj); // step 4.b.ii
|
---|
27 | $push(descriptors, [nextKey, desc]); // step 4.b.iii
|
---|
28 | }
|
---|
29 | });
|
---|
30 |
|
---|
31 | forEach(descriptors, function (pair) { // step 5
|
---|
32 | var P = pair[0]; // step 5.a
|
---|
33 | var desc = pair[1]; // step 5.b
|
---|
34 | DefinePropertyOrThrow(O, P, desc); // step 5.c
|
---|
35 | });
|
---|
36 |
|
---|
37 | return O; // step 6
|
---|
38 | };
|
---|