ObjectDefineProperties.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. var callBound = require('call-bind/callBound');
  3. var DefinePropertyOrThrow = require('./DefinePropertyOrThrow');
  4. var Get = require('./Get');
  5. var ToObject = require('./ToObject');
  6. var ToPropertyDescriptor = require('./ToPropertyDescriptor');
  7. var forEach = require('../helpers/forEach');
  8. var getOwnPropertyDescriptor = require('gopd');
  9. var OwnPropertyKeys = require('../helpers/OwnPropertyKeys');
  10. var $push = callBound('Array.prototype.push');
  11. // https://262.ecma-international.org/6.0/#sec-objectdefineproperties
  12. module.exports = function ObjectDefineProperties(O, Properties) {
  13. var props = ToObject(Properties); // step 1
  14. var keys = OwnPropertyKeys(props); // step 2
  15. var descriptors = []; // step 3
  16. forEach(keys, function (nextKey) { // step 4
  17. var propDesc = ToPropertyDescriptor(getOwnPropertyDescriptor(props, nextKey)); // step 4.a
  18. if (typeof propDesc !== 'undefined' && propDesc['[[Enumerable]]']) { // step 4.b
  19. var descObj = Get(props, nextKey); // step 4.b.i
  20. var desc = ToPropertyDescriptor(descObj); // step 4.b.ii
  21. $push(descriptors, [nextKey, desc]); // step 4.b.iii
  22. }
  23. });
  24. forEach(descriptors, function (pair) { // step 5
  25. var P = pair[0]; // step 5.a
  26. var desc = pair[1]; // step 5.b
  27. DefinePropertyOrThrow(O, P, desc); // step 5.c
  28. });
  29. return O; // step 6
  30. };