Keine Beschreibung

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. object-assign
  3. (c) Sindre Sorhus
  4. @license MIT
  5. */
  6. 'use strict';
  7. /* eslint-disable no-unused-vars */
  8. var getOwnPropertySymbols = Object.getOwnPropertySymbols;
  9. var hasOwnProperty = Object.prototype.hasOwnProperty;
  10. var propIsEnumerable = Object.prototype.propertyIsEnumerable;
  11. function toObject(val) {
  12. if (val === null || val === undefined) {
  13. throw new TypeError('Object.assign cannot be called with null or undefined');
  14. }
  15. return Object(val);
  16. }
  17. function shouldUseNative() {
  18. try {
  19. if (!Object.assign) {
  20. return false;
  21. }
  22. // Detect buggy property enumeration order in older V8 versions.
  23. // https://bugs.chromium.org/p/v8/issues/detail?id=4118
  24. var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
  25. test1[5] = 'de';
  26. if (Object.getOwnPropertyNames(test1)[0] === '5') {
  27. return false;
  28. }
  29. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  30. var test2 = {};
  31. for (var i = 0; i < 10; i++) {
  32. test2['_' + String.fromCharCode(i)] = i;
  33. }
  34. var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
  35. return test2[n];
  36. });
  37. if (order2.join('') !== '0123456789') {
  38. return false;
  39. }
  40. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  41. var test3 = {};
  42. 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
  43. test3[letter] = letter;
  44. });
  45. if (Object.keys(Object.assign({}, test3)).join('') !==
  46. 'abcdefghijklmnopqrst') {
  47. return false;
  48. }
  49. return true;
  50. } catch (err) {
  51. // We don't expect any of the above to throw, but better to be safe.
  52. return false;
  53. }
  54. }
  55. module.exports = shouldUseNative() ? Object.assign : function (target, source) {
  56. var from;
  57. var to = toObject(target);
  58. var symbols;
  59. for (var s = 1; s < arguments.length; s++) {
  60. from = Object(arguments[s]);
  61. for (var key in from) {
  62. if (hasOwnProperty.call(from, key)) {
  63. to[key] = from[key];
  64. }
  65. }
  66. if (getOwnPropertySymbols) {
  67. symbols = getOwnPropertySymbols(from);
  68. for (var i = 0; i < symbols.length; i++) {
  69. if (propIsEnumerable.call(from, symbols[i])) {
  70. to[symbols[i]] = from[symbols[i]];
  71. }
  72. }
  73. }
  74. }
  75. return to;
  76. };