mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
c2a089fddf
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/36258 This fixes a few instances where YogaLayoutableShadowNode (or general shadownode casting) could offer better memory safety. 1. The reference form of traitCast() now terminates on invalid cast, instead of debug assert, since it is better to crash in production than to corrupt memory (which will crash somewhere later, in a much more confusing way). 2. We use traitCast() in more places where we previously would static_cast. This means needing to formally add a mutable version. 3. We bounds-check yoga children access in a single place by using `std::vector` `at()` instead of `[]`. 4. Removed `Trait::UnreservedTrait1` API, since multiple libraries using it can collide and we lose the memory safety benefits of `traitCast`. This change is in response to a bug where `YogaLayoutableShadowNode` may perform an invalid `static_cast` of `RawTextShadowNode` if a text or number is rendered directly inside of a `<View>` (instead of a `<Text>` element). This does not yet fix the underlying logic of YogaLayoutableShadowNode to act gracefully when a RawTextShadowNode makes its way into children. We just terminate, instead of corrupting memory. Changelog: [General][Breaking] - Better Fabric ShadowNode Memory Safety (Removes `Trait::UnreservedTrait` API) Reviewed By: javache Differential Revision: D43271779 fbshipit-source-id: 727c1230f72664bf4d261871c66ca61ddf0d5ffa
67 lines
1.7 KiB
C++
67 lines
1.7 KiB
C++
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <limits>
|
|
|
|
#include <react/renderer/components/text/BaseTextShadowNode.h>
|
|
#include <react/renderer/components/text/TextProps.h>
|
|
#include <react/renderer/components/view/ViewEventEmitter.h>
|
|
#include <react/renderer/core/ConcreteShadowNode.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
extern const char TextComponentName[];
|
|
|
|
using TextEventEmitter = TouchEventEmitter;
|
|
|
|
class TextShadowNode : public ConcreteShadowNode<
|
|
TextComponentName,
|
|
ShadowNode,
|
|
TextProps,
|
|
TextEventEmitter>,
|
|
public BaseTextShadowNode {
|
|
public:
|
|
static ShadowNodeTraits BaseTraits() {
|
|
auto traits = ConcreteShadowNode::BaseTraits();
|
|
|
|
#ifdef ANDROID
|
|
traits.set(ShadowNodeTraits::Trait::FormsView);
|
|
#endif
|
|
traits.set(IdentifierTrait());
|
|
|
|
return traits;
|
|
}
|
|
|
|
static ShadowNodeTraits::Trait IdentifierTrait() {
|
|
return ShadowNodeTraits::Trait::Text;
|
|
}
|
|
|
|
using ConcreteShadowNode::ConcreteShadowNode;
|
|
|
|
#ifdef ANDROID
|
|
using BaseShadowNode = ConcreteShadowNode<
|
|
TextComponentName,
|
|
ShadowNode,
|
|
TextProps,
|
|
TextEventEmitter>;
|
|
|
|
TextShadowNode(
|
|
ShadowNodeFragment const &fragment,
|
|
ShadowNodeFamily::Shared const &family,
|
|
ShadowNodeTraits traits)
|
|
: BaseShadowNode(fragment, family, traits), BaseTextShadowNode() {
|
|
orderIndex_ = std::numeric_limits<decltype(orderIndex_)>::max();
|
|
}
|
|
#endif
|
|
};
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|