Add assertion to ensure copied shadow nodes are of the same type as the original

Reviewed By: mdvacca

Differential Revision: D7664638

fbshipit-source-id: e1b7acbafd8a8fd9d6301d8afbb3e5959dc15b7a
This commit is contained in:
Andrew Chen (Eng)
2018-05-07 14:53:28 -07:00
committed by Facebook Github Bot
parent 3145b1e62a
commit 1be2541ce2
2 changed files with 26 additions and 0 deletions

View File

@@ -166,6 +166,9 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
@Override
public ReactShadowNodeImpl mutableCopy() {
ReactShadowNodeImpl copy = copy();
Assertions.assertCondition(
getClass() == copy.getClass(),
"Copied shadow node must use the same class");
if (mYogaNode != null) {
copy.mYogaNode = mYogaNode.clone();
copy.mYogaNode.setData(copy);
@@ -182,6 +185,9 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
@Override
public ReactShadowNodeImpl mutableCopyWithNewChildren() {
ReactShadowNodeImpl copy = copy();
Assertions.assertCondition(
getClass() == copy.getClass(),
"Copied shadow node must use the same class");
if (mYogaNode != null) {
copy.mYogaNode = mYogaNode.cloneWithNewChildren();
copy.mYogaNode.setData(copy);