55 lines
2.2 KiB
JavaScript
55 lines
2.2 KiB
JavaScript
'use strict';
|
|
var DESCRIPTORS = require('../internals/descriptors');
|
|
var fails = require('../internals/fails');
|
|
var objectKeys = require('../internals/object-keys');
|
|
var getOwnPropertySymbolsModule = require('../internals/object-get-own-property-symbols');
|
|
var propertyIsEnumerableModule = require('../internals/object-property-is-enumerable');
|
|
var toObject = require('../internals/to-object');
|
|
var IndexedObject = require('../internals/indexed-object');
|
|
|
|
// eslint-disable-next-line es/no-object-assign -- safe
|
|
var $assign = Object.assign;
|
|
// eslint-disable-next-line es/no-object-defineproperty -- required for testing
|
|
var defineProperty = Object.defineProperty;
|
|
|
|
// `Object.assign` method
|
|
// https://tc39.es/ecma262/#sec-object.assign
|
|
module.exports = !$assign || fails(function () {
|
|
// should have correct order of operations (Edge bug)
|
|
if (DESCRIPTORS && $assign({ b: 1 }, $assign(defineProperty({}, 'a', {
|
|
enumerable: true,
|
|
get: function () {
|
|
defineProperty(this, 'b', {
|
|
value: 3,
|
|
enumerable: false
|
|
});
|
|
}
|
|
}), { b: 2 })).b !== 1) return true;
|
|
// should work with symbols and should have deterministic property order (V8 bug)
|
|
var A = {};
|
|
var B = {};
|
|
// eslint-disable-next-line es/no-symbol -- safe
|
|
var symbol = Symbol();
|
|
var alphabet = 'abcdefghijklmnopqrst';
|
|
A[symbol] = 7;
|
|
alphabet.split('').forEach(function (chr) { B[chr] = chr; });
|
|
return $assign({}, A)[symbol] != 7 || objectKeys($assign({}, B)).join('') != alphabet;
|
|
}) ? function assign(target, source) { // eslint-disable-line no-unused-vars -- required for `.length`
|
|
var T = toObject(target);
|
|
var argumentsLength = arguments.length;
|
|
var index = 1;
|
|
var getOwnPropertySymbols = getOwnPropertySymbolsModule.f;
|
|
var propertyIsEnumerable = propertyIsEnumerableModule.f;
|
|
while (argumentsLength > index) {
|
|
var S = IndexedObject(arguments[index++]);
|
|
var keys = getOwnPropertySymbols ? objectKeys(S).concat(getOwnPropertySymbols(S)) : objectKeys(S);
|
|
var length = keys.length;
|
|
var j = 0;
|
|
var key;
|
|
while (length > j) {
|
|
key = keys[j++];
|
|
if (!DESCRIPTORS || propertyIsEnumerable.call(S, key)) T[key] = S[key];
|
|
}
|
|
} return T;
|
|
} : $assign;
|