mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Avoid directly calling hasOwnProperty (#6855)
* Avoid directly calling hasOwnProperty * Fix failing test case
This commit is contained in:
1 parent
fe2002c3d8
commit
c313baa0ca
2 files changed
+10
-3
No files matched your search
@@ -15,6 +15,7 @@ var ReactCurrentOwner = require('ReactCurrentOwner');
|
||||
|
||||
var warning = require('warning');
|
||||
var canDefineProperty = require('canDefineProperty');
|
||||
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||
|
||||
// The Symbol used to tag the ReactElement type. If there is no native Symbol
|
||||
// nor polyfill, then a plain number is used for performance.
|
||||
@@ -137,9 +138,9 @@ ReactElement.createElement = function(type, config, children) {
|
||||
'React.createElement(...): Expected props argument to be a plain object. ' +
|
||||
'Properties defined in its prototype chain will be ignored.'
|
||||
);
|
||||
ref = !config.hasOwnProperty('ref') ||
|
||||
ref = !hasOwnProperty.call(config, 'ref') ||
|
||||
Object.getOwnPropertyDescriptor(config, 'ref').get ? null : config.ref;
|
||||
key = !config.hasOwnProperty('key') ||
|
||||
key = !hasOwnProperty.call(config, 'key') ||
|
||||
Object.getOwnPropertyDescriptor(config, 'key').get ? null : '' + config.key;
|
||||
} else {
|
||||
ref = config.ref === undefined ? null : config.ref;
|
||||
@@ -149,7 +150,7 @@ ReactElement.createElement = function(type, config, children) {
|
||||
source = config.__source === undefined ? null : config.__source;
|
||||
// Remaining properties are added to a new props object
|
||||
for (propName in config) {
|
||||
if (config.hasOwnProperty(propName) &&
|
||||
if (hasOwnProperty.call(config, propName) &&
|
||||
!RESERVED_PROPS.hasOwnProperty(propName)) {
|
||||
props[propName] = config[propName];
|
||||
}
|
||||
|
||||
@@ -138,6 +138,12 @@ describe('ReactElement', function() {
|
||||
expect(element.props.foo).toBe(1);
|
||||
});
|
||||
|
||||
it('does not fail if config has no prototype', function() {
|
||||
var config = Object.create(null, {foo: {value: 1, enumerable: true}});
|
||||
var element = React.createFactory(ComponentClass)(config);
|
||||
expect(element.props.foo).toBe(1);
|
||||
});
|
||||
|
||||
it('warns if the config object inherits from any type other than Object', function() {
|
||||
spyOn(console, 'error');
|
||||
React.createElement('div', {foo: 1});
|
||||
|
||||
Reference in new issue
Block a user