Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
Add invariant that an object with modified properties must be valid. (#…
Browse files Browse the repository at this point in the history
…2278)

Summary:
Release notes: None

The uncovered bug is tracked in #2279.
Pull Request resolved: #2278

Differential Revision: D9472482

Pulled By: NTillmann

fbshipit-source-id: 5d6e24abd76fd83e9078c3908fa0be0e7f0b2c51
  • Loading branch information
NTillmann authored and facebook-github-bot committed Aug 31, 2018
1 parent 12ae403 commit b3bcd73
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/serializer/ResidualHeapVisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,7 @@ export class ResidualHeapVisitor {
}

visitValueObject(val: ObjectValue): void {
invariant(val.isValid());
this._registerAdditionalRoot(val);
if (isReactElement(val)) {
this.residualReactElementVisitor.visitReactElement(val);
Expand Down Expand Up @@ -1038,17 +1039,20 @@ export class ResidualHeapVisitor {
this.postProcessValue(equivalentValue);
return (equivalentValue: any);
}
if (val instanceof ObjectValue && isReactElement(val)) {
if (val.temporalAlias !== undefined) {
return this.visitEquivalentValue(val.temporalAlias);
if (val instanceof ObjectValue) {
invariant(val.isValid());
if (isReactElement(val)) {
if (val.temporalAlias !== undefined) {
return this.visitEquivalentValue(val.temporalAlias);
}
let equivalentReactElementValue = this.residualReactElementVisitor.reactElementEquivalenceSet.add(val);
if (this._mark(equivalentReactElementValue)) this.visitValueObject(equivalentReactElementValue);
return (equivalentReactElementValue: any);
} else if (isReactPropsObject(val)) {
let equivalentReactPropsValue = this.residualReactElementVisitor.reactPropsEquivalenceSet.add(val);
if (this._mark(equivalentReactPropsValue)) this.visitValueObject(equivalentReactPropsValue);
return (equivalentReactPropsValue: any);
}
let equivalentReactElementValue = this.residualReactElementVisitor.reactElementEquivalenceSet.add(val);
if (this._mark(equivalentReactElementValue)) this.visitValueObject(equivalentReactElementValue);
return (equivalentReactElementValue: any);
} else if (val instanceof ObjectValue && isReactPropsObject(val)) {
let equivalentReactPropsValue = this.residualReactElementVisitor.reactPropsEquivalenceSet.add(val);
if (this._mark(equivalentReactPropsValue)) this.visitValueObject(equivalentReactPropsValue);
return (equivalentReactPropsValue: any);
}
this.visitValue(val);
return val;
Expand Down
1 change: 1 addition & 0 deletions src/utils/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ export class Generator {

for (let propertyBinding of modifiedProperties.keys()) {
let object = propertyBinding.object;
invariant(object.isValid());
if (createdObjects.has(object)) continue; // Created Object's binding
if (ObjectValue.refuseSerializationOnPropertyBinding(propertyBinding)) continue; // modification to internal state
// modifications to intrinsic objects are tracked in the generator
Expand Down
5 changes: 5 additions & 0 deletions src/values/ObjectValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@ export default class ObjectValue extends ConcreteValue {
// never be serialized.
refuseSerialization: boolean;

// Checks whether effects are properly applied.
isValid(): boolean {
return this._isPartial !== undefined;
}

equals(x: Value): boolean {
return this === x;
}
Expand Down

0 comments on commit b3bcd73

Please sign in to comment.