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:
Родитель
3145b1e62a
Коммит
1be2541ce2
|
@ -166,6 +166,9 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
|
||||||
@Override
|
@Override
|
||||||
public ReactShadowNodeImpl mutableCopy() {
|
public ReactShadowNodeImpl mutableCopy() {
|
||||||
ReactShadowNodeImpl copy = copy();
|
ReactShadowNodeImpl copy = copy();
|
||||||
|
Assertions.assertCondition(
|
||||||
|
getClass() == copy.getClass(),
|
||||||
|
"Copied shadow node must use the same class");
|
||||||
if (mYogaNode != null) {
|
if (mYogaNode != null) {
|
||||||
copy.mYogaNode = mYogaNode.clone();
|
copy.mYogaNode = mYogaNode.clone();
|
||||||
copy.mYogaNode.setData(copy);
|
copy.mYogaNode.setData(copy);
|
||||||
|
@ -182,6 +185,9 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
|
||||||
@Override
|
@Override
|
||||||
public ReactShadowNodeImpl mutableCopyWithNewChildren() {
|
public ReactShadowNodeImpl mutableCopyWithNewChildren() {
|
||||||
ReactShadowNodeImpl copy = copy();
|
ReactShadowNodeImpl copy = copy();
|
||||||
|
Assertions.assertCondition(
|
||||||
|
getClass() == copy.getClass(),
|
||||||
|
"Copied shadow node must use the same class");
|
||||||
if (mYogaNode != null) {
|
if (mYogaNode != null) {
|
||||||
copy.mYogaNode = mYogaNode.cloneWithNewChildren();
|
copy.mYogaNode = mYogaNode.cloneWithNewChildren();
|
||||||
copy.mYogaNode.setData(copy);
|
copy.mYogaNode.setData(copy);
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||||
|
package com.facebook.react.fabric;
|
||||||
|
|
||||||
|
import com.facebook.react.uimanager.ReactShadowNodeImpl;
|
||||||
|
import com.facebook.testing.robolectric.v3.WithTestDefaultsRunner;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
/** Tests {@link ReactShadowNode} */
|
||||||
|
@RunWith(WithTestDefaultsRunner.class)
|
||||||
|
public class ReactShadowNodeTest {
|
||||||
|
|
||||||
|
@Test(expected = AssertionError.class)
|
||||||
|
public void testClonedInstance() {
|
||||||
|
TestReactShadowNode node = new TestReactShadowNode();
|
||||||
|
node.mutableCopy();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class TestReactShadowNode extends ReactShadowNodeImpl {}
|
||||||
|
}
|
Загрузка…
Ссылка в новой задаче