mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
9842e39019
Summary: Our long-term plan is to completely illuminate `jsi::Value`-to-`folly::dynamic` serialization step in prop parsing process improving performance and memory pressure. At the same time, we don't want to introduce a hard dependency in application code to JSI because it exposes direct access to VM and prevents parsing some data that come *NOT* from JSVM. RawValue is an extremely light-weight (hopefully fully optimized-out) abstraction that provides limited JSON-like and C++-idiomatic interface. The current particular implementation is still using `folly::dynamic` inside, but I have fully JSI-powered one which will replace the current one right after we figure out how to deal with folly::dynamic-specific callsites. Or we can implement RawValue in a hybrid manner if a code-size implication of that will be minimal. Reviewed By: JoshuaGross, mdvacca Differential Revision: D13962466 fbshipit-source-id: e848522fd242f21e9e771773f2103f1c1d9d7f21
89 lines
3.4 KiB
C++
89 lines
3.4 KiB
C++
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include "TestComponent.h"
|
|
|
|
using namespace facebook::react;
|
|
|
|
TEST(ComponentDescriptorTest, createShadowNode) {
|
|
SharedComponentDescriptor descriptor =
|
|
std::make_shared<TestComponentDescriptor>(nullptr);
|
|
|
|
ASSERT_EQ(descriptor->getComponentHandle(), TestShadowNode::Handle());
|
|
ASSERT_STREQ(
|
|
descriptor->getComponentName().c_str(), TestShadowNode::Name().c_str());
|
|
ASSERT_STREQ(descriptor->getComponentName().c_str(), "Test");
|
|
|
|
const auto &raw = RawProps(folly::dynamic::object("nativeID", "abc"));
|
|
SharedProps props = descriptor->cloneProps(nullptr, raw);
|
|
SharedShadowNode node = descriptor->createShadowNode(
|
|
ShadowNodeFragment{.tag = 9,
|
|
.rootTag = 1,
|
|
.props = props,
|
|
.eventEmitter = descriptor->createEventEmitter(0, 9)});
|
|
|
|
ASSERT_EQ(node->getComponentHandle(), TestShadowNode::Handle());
|
|
ASSERT_STREQ(
|
|
node->getComponentName().c_str(), TestShadowNode::Name().c_str());
|
|
ASSERT_STREQ(node->getComponentName().c_str(), "Test");
|
|
ASSERT_EQ(node->getTag(), 9);
|
|
ASSERT_EQ(node->getRootTag(), 1);
|
|
ASSERT_STREQ(node->getProps()->nativeId.c_str(), "abc");
|
|
}
|
|
|
|
TEST(ComponentDescriptorTest, cloneShadowNode) {
|
|
SharedComponentDescriptor descriptor =
|
|
std::make_shared<TestComponentDescriptor>(nullptr);
|
|
|
|
const auto &raw = RawProps(folly::dynamic::object("nativeID", "abc"));
|
|
SharedProps props = descriptor->cloneProps(nullptr, raw);
|
|
SharedShadowNode node = descriptor->createShadowNode(
|
|
ShadowNodeFragment{.tag = 9,
|
|
.rootTag = 1,
|
|
.props = props,
|
|
.eventEmitter = descriptor->createEventEmitter(0, 9)});
|
|
SharedShadowNode cloned = descriptor->cloneShadowNode(*node, {});
|
|
|
|
ASSERT_STREQ(cloned->getComponentName().c_str(), "Test");
|
|
ASSERT_EQ(cloned->getTag(), 9);
|
|
ASSERT_EQ(cloned->getRootTag(), 1);
|
|
ASSERT_STREQ(cloned->getProps()->nativeId.c_str(), "abc");
|
|
}
|
|
|
|
TEST(ComponentDescriptorTest, appendChild) {
|
|
SharedComponentDescriptor descriptor =
|
|
std::make_shared<TestComponentDescriptor>(nullptr);
|
|
|
|
const auto &raw = RawProps(folly::dynamic::object("nativeID", "abc"));
|
|
SharedProps props = descriptor->cloneProps(nullptr, raw);
|
|
SharedShadowNode node1 = descriptor->createShadowNode(
|
|
ShadowNodeFragment{.tag = 1,
|
|
.rootTag = 1,
|
|
.props = props,
|
|
.eventEmitter = descriptor->createEventEmitter(0, 1)});
|
|
SharedShadowNode node2 = descriptor->createShadowNode(
|
|
ShadowNodeFragment{.tag = 2,
|
|
.rootTag = 1,
|
|
.props = props,
|
|
.eventEmitter = descriptor->createEventEmitter(0, 2)});
|
|
SharedShadowNode node3 = descriptor->createShadowNode(
|
|
ShadowNodeFragment{.tag = 3,
|
|
.rootTag = 1,
|
|
.props = props,
|
|
.eventEmitter = descriptor->createEventEmitter(0, 3)});
|
|
|
|
descriptor->appendChild(node1, node2);
|
|
descriptor->appendChild(node1, node3);
|
|
|
|
auto node1Children = node1->getChildren();
|
|
ASSERT_EQ(node1Children.size(), 2);
|
|
ASSERT_EQ(node1Children.at(0), node2);
|
|
ASSERT_EQ(node1Children.at(1), node3);
|
|
}
|