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