_object-assign.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. // 19.1.2.1 Object.assign(target, source, ...)
  3. var getKeys = require('./_object-keys');
  4. var gOPS = require('./_object-gops');
  5. var pIE = require('./_object-pie');
  6. var toObject = require('./_to-object');
  7. var IObject = require('./_iobject');
  8. var $assign = Object.assign;
  9. // should work with symbols and should have deterministic property order (V8 bug)
  10. module.exports = !$assign || require('./_fails')(function () {
  11. var A = {};
  12. var B = {};
  13. // eslint-disable-next-line no-undef
  14. var S = Symbol();
  15. var K = 'abcdefghijklmnopqrst';
  16. A[S] = 7;
  17. K.split('').forEach(function (k) { B[k] = k; });
  18. return $assign({}, A)[S] != 7 || Object.keys($assign({}, B)).join('') != K;
  19. }) ? function assign(target, source) { // eslint-disable-line no-unused-vars
  20. var T = toObject(target);
  21. var aLen = arguments.length;
  22. var index = 1;
  23. var getSymbols = gOPS.f;
  24. var isEnum = pIE.f;
  25. while (aLen > index) {
  26. var S = IObject(arguments[index++]);
  27. var keys = getSymbols ? getKeys(S).concat(getSymbols(S)) : getKeys(S);
  28. var length = keys.length;
  29. var j = 0;
  30. var key;
  31. while (length > j) if (isEnum.call(S, key = keys[j++])) T[key] = S[key];
  32. } return T;
  33. } : $assign;