Ensure that all internal instances have consistent properties

Use preventExtensions so that we can't add expando properties to internal
instances. This ensures that the hidden class is kept more consistent.
This commit is contained in:
Sebastian Markbage
2014-11-17 12:54:21 -08:00
parent bc4dd411b0
commit fb17e8ca56
5 changed files with 21 additions and 0 deletions
+2
View File
@@ -147,6 +147,8 @@ function validateDangerousTag(tag) {
function ReactDOMComponent(tag) {
validateDangerousTag(tag);
this._tag = tag;
this._renderedChildren = null;
this._previousStyleCopy = null;
}
ReactDOMComponent.displayName = 'ReactDOMComponent';
+4
View File
@@ -50,6 +50,10 @@ assign(ReactDOMTextComponent.prototype, {
// TODO: This is really a ReactText (ReactNode), not a ReactElement
this._currentElement = text;
this._stringText = '' + text;
// Properties
this._rootNodeID = null;
this._mountIndex = 0;
},
/**
+4
View File
@@ -118,6 +118,10 @@ var ReactComponent = {
// We keep the old element and a reference to the pending element
// to track updates.
this._currentElement = element;
this._rootNodeID = null;
this._mountIndex = 0;
this._mountDepth = 0;
},
/**
+3
View File
@@ -117,8 +117,11 @@ var ReactCompositeComponentMixin = assign({},
this._pendingElement = null;
this._pendingState = null;
this._pendingForceUpdate = false;
this._compositeLifeCycleState = null;
this._renderedComponent = null;
// Children can be either an array or more than one argument
ReactComponent.Mixin.construct.apply(this, arguments);
+8
View File
@@ -118,6 +118,14 @@ function instantiateReactComponent(node, parentCompositeType) {
// Sets up the instance. This can probably just move into the constructor now.
instance.construct(node);
// Internal instances should fully constructed at this point, so they should
// not get any new fields added to them at this point.
if (__DEV__) {
if (Object.preventExtensions) {
Object.preventExtensions(instance);
}
}
return instance;
}