react-native/Libraries/polyfills/Object.es6.js

66 lines
2.1 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @polyfill
* @nolint
*/
// 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(
Improve spacing in polyfill error messages Summary: <!-- Thank you for sending the PR! If you changed any code, please provide us with clear instructions on how you verified your changes work. In other words, a test plan is *required*. Bonus points for screenshots and videos! Please read the Contribution Guidelines at https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md to learn more about contributing to React Native. Happy contributing! --> Noticed a lack of spacing in the following error message: ``` In this environment the sources for assign MUST be an object.This error is a performance optimization and not spec compliant. TypeError: In this environment the sources for assign MUST be an object.This error is a performance optimization and not spec compliant. at Object.assign (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:230:15) at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:134559:46 at Array.map (native) at GridComponent._callee$ (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:134554:58) at tryCatch (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7388:40) at Generator.invoke [as _invoke] (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7576:22) at Generator.prototype.(anonymous function) [as next] (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7413:21) at tryCatch (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7388:40) at invoke (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7446:20) at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7476:11 ``` Tested by updating the message locally in `/path/to/rn-project/node_modules/react-native/packager/src/Resolver/polyfills/Object.es6.js`. Closes https://github.com/facebook/react-native/pull/15166 Differential Revision: D5481475 Pulled By: javache fbshipit-source-id: f3e4e482a8ee61d52e8c3e0c5f038b1109bd1113
2017-08-10 10:45:12 +00:00
'In this environment the target of assign MUST be an object. ' +
'This error is a performance optimization and not spec compliant.',
);
}
}
for (var nextIndex = 1; nextIndex < arguments.length; nextIndex++) {
var nextSource = arguments[nextIndex];
if (nextSource == null) {
continue;
}
if (__DEV__) {
if (typeof nextSource !== 'object' && typeof nextSource !== 'function') {
throw new TypeError(
Improve spacing in polyfill error messages Summary: <!-- Thank you for sending the PR! If you changed any code, please provide us with clear instructions on how you verified your changes work. In other words, a test plan is *required*. Bonus points for screenshots and videos! Please read the Contribution Guidelines at https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md to learn more about contributing to React Native. Happy contributing! --> Noticed a lack of spacing in the following error message: ``` In this environment the sources for assign MUST be an object.This error is a performance optimization and not spec compliant. TypeError: In this environment the sources for assign MUST be an object.This error is a performance optimization and not spec compliant. at Object.assign (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:230:15) at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:134559:46 at Array.map (native) at GridComponent._callee$ (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:134554:58) at tryCatch (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7388:40) at Generator.invoke [as _invoke] (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7576:22) at Generator.prototype.(anonymous function) [as next] (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7413:21) at tryCatch (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7388:40) at invoke (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7446:20) at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7476:11 ``` Tested by updating the message locally in `/path/to/rn-project/node_modules/react-native/packager/src/Resolver/polyfills/Object.es6.js`. Closes https://github.com/facebook/react-native/pull/15166 Differential Revision: D5481475 Pulled By: javache fbshipit-source-id: f3e4e482a8ee61d52e8c3e0c5f038b1109bd1113
2017-08-10 10:45:12 +00:00
'In this environment the sources for assign MUST be an object. ' +
'This error is a performance optimization and not spec compliant.',
);
}
}
// 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 ' +
'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.',
);
}
}
target[key] = nextSource[key];
}
}
return target;
};