2017-07-11 10:43:53 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2017-07-11 10:43:53 +00:00
|
|
|
*
|
2018-05-11 02:06:46 +00:00
|
|
|
* @format
|
2017-07-11 10:43:53 +00:00
|
|
|
* @polyfill
|
2017-07-17 10:02:14 +00:00
|
|
|
* @nolint
|
2017-07-11 10:43:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
// WARNING: This is an optimized version that fails on hasOwnProperty checks
|
|
|
|
// and non objects. It's not spec-compliant. It's a perf optimization.
|
|
|
|
// This is only needed for iOS 8 and current Android JSC.
|
|
|
|
|
|
|
|
Object.assign = function(target, sources) {
|
|
|
|
if (__DEV__) {
|
|
|
|
if (target == null) {
|
|
|
|
throw new TypeError('Object.assign target cannot be null or undefined');
|
|
|
|
}
|
|
|
|
if (typeof target !== 'object' && typeof target !== 'function') {
|
|
|
|
throw new TypeError(
|
2017-08-10 10:45:12 +00:00
|
|
|
'In this environment the target of assign MUST be an object. ' +
|
2018-05-11 02:06:46 +00:00
|
|
|
'This error is a performance optimization and not spec compliant.',
|
2017-07-11 10:43:53 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var nextIndex = 1; nextIndex < arguments.length; nextIndex++) {
|
|
|
|
var nextSource = arguments[nextIndex];
|
|
|
|
if (nextSource == null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (__DEV__) {
|
2018-05-11 02:06:46 +00:00
|
|
|
if (typeof nextSource !== 'object' && typeof nextSource !== 'function') {
|
2017-07-11 10:43:53 +00:00
|
|
|
throw new TypeError(
|
2017-08-10 10:45:12 +00:00
|
|
|
'In this environment the sources for assign MUST be an object. ' +
|
2018-05-11 02:06:46 +00:00
|
|
|
'This error is a performance optimization and not spec compliant.',
|
2017-07-11 10:43:53 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We don't currently support accessors nor proxies. Therefore this
|
|
|
|
// copy cannot throw. If we ever supported this then we must handle
|
|
|
|
// exceptions and side-effects.
|
|
|
|
|
|
|
|
for (var key in nextSource) {
|
|
|
|
if (__DEV__) {
|
|
|
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
|
|
if (!hasOwnProperty.call(nextSource, key)) {
|
|
|
|
throw new TypeError(
|
|
|
|
'One of the sources for assign has an enumerable key on the ' +
|
2018-05-11 02:06:46 +00:00
|
|
|
'prototype chain. Are you trying to assign a prototype property? ' +
|
|
|
|
"We don't allow it, as this is an edge case that we do not support. " +
|
|
|
|
'This error is a performance optimization and not spec compliant.',
|
2017-07-11 10:43:53 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
target[key] = nextSource[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return target;
|
|
|
|
};
|