setState within componentWillMount uses internal property update (#2149)

Summary:
Release notes: none

As we're updating state on a final object, in this case `state`, ensure we use `hardModifyReactObjectPropertyBinding`. Unblocks https://github.com/facebook/prepack/pull/2137.
Closes https://github.com/facebook/prepack/pull/2149

Reviewed By: hermanventer

Differential Revision: D8584676

Pulled By: trueadm

fbshipit-source-id: f23c77a5091b7c1023a48a5d29353bf9cdc06d65
This commit is contained in:
Dominic Gannaway 2018-06-21 18:41:25 -07:00 committed by Facebook Github Bot
parent 18e69904d5
commit 93cd9a1d63

View File

@ -23,7 +23,13 @@ import {
} from "../values/index.js";
import * as t from "babel-types";
import type { BabelNodeIdentifier } from "babel-types";
import { flagPropsWithNoPartialKeyOrRef, getProperty, getValueFromFunctionCall, valueIsClassComponent } from "./utils";
import {
flagPropsWithNoPartialKeyOrRef,
getProperty,
getValueFromFunctionCall,
hardModifyReactObjectPropertyBinding,
valueIsClassComponent,
} from "./utils";
import { ExpectedBailOut, SimpleClassBailOut } from "./errors.js";
import { Get, Construct } from "../methods/index.js";
import { Properties } from "../singletons.js";
@ -219,15 +225,15 @@ export function createClassInstanceForFirstRenderOnly(
if (stateToUpdate instanceof ObjectValue) {
let newState = new ObjectValue(realm, realm.intrinsics.ObjectPrototype);
objectAssignCall(realm.intrinsics.undefined, [newState, prevState]);
newState.makeFinal();
for (let [key, binding] of stateToUpdate.properties) {
if (binding && binding.descriptor && binding.descriptor.enumerable) {
let value = getProperty(realm, stateToUpdate, key);
Properties.Set(realm, newState, key, value, true);
hardModifyReactObjectPropertyBinding(realm, newState, key, value);
}
}
newState.makeFinal();
Properties.Set(realm, instance, "state", newState, true);
}
if (callback instanceof ECMAScriptSourceFunctionValue && callback.$Call) {