Fix invariant failure in serializer

Summary:
For global let bindings, the serializer ignored the CSE value provided by the visitor. This led to an invariant failure when looking up the scope of a value that had been replaced by an equivalent value during CSE analysis in the visitor.
Closes https://github.com/facebook/prepack/pull/1149

Differential Revision: D6325186

Pulled By: hermanventer

fbshipit-source-id: 421d5bfc3f4e0c9ec7730af6ff3a38d4b926bcae
This commit is contained in:
Herman Venter 2017-11-14 10:43:51 -08:00 committed by Facebook Github Bot
parent 03750d1b3b
commit fdc2787c1a
2 changed files with 16 additions and 2 deletions

View File

@ -1273,10 +1273,12 @@ export class ResidualHeapSerializer {
let value = this.realm.getGlobalLetBinding(boundName);
// Check for let binding vs global property
if (value) {
let id = this.serializeValue(value, true, "let");
let rval = residualFunctionBinding.value;
invariant(rval !== undefined && value.equals(rval));
let id = this.serializeValue(rval, true, "let");
// increment ref count one more time as the value has been
// referentialized (stored in a variable) by serializeValue
this.residualHeapValueIdentifiers.incrementReferenceCount(value);
this.residualHeapValueIdentifiers.incrementReferenceCount(rval);
residualFunctionBinding.serializedValue = id;
} else {
residualFunctionBinding.serializedValue = this.preludeGenerator.globalReference(boundName);

View File

@ -0,0 +1,12 @@
this.glob = 123;
let b = global.__abstract ? __abstract("boolean", "true"): true;
let y;
if (b) {
y = glob;
}
let z;
if (b) {
z = glob;
}
inspect = function () { return y + " " + z; }