From 27009c1031cf6ce4c64bf8e5539a482b9caf08ce Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Wed, 10 Jul 2019 08:44:52 -0700 Subject: [PATCH] Fabric: More precondition asserts in ConcreteShadowNode Summary: That should help to fail early in situations when we lose critical class data members. Reviewed By: sammy-SC Differential Revision: D16179539 fbshipit-source-id: da73b81568c2f3657b9bc2bd1cc7ee6624e75626 --- .../fabric/core/shadownode/ConcreteShadowNode.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ReactCommon/fabric/core/shadownode/ConcreteShadowNode.h b/ReactCommon/fabric/core/shadownode/ConcreteShadowNode.h index 896569200f1..2637e456912 100644 --- a/ReactCommon/fabric/core/shadownode/ConcreteShadowNode.h +++ b/ReactCommon/fabric/core/shadownode/ConcreteShadowNode.h @@ -80,8 +80,11 @@ class ConcreteShadowNode : public ShadowNode { } const SharedConcreteProps getProps() const { - assert(std::dynamic_pointer_cast(props_)); - return std::static_pointer_cast(props_); + assert(props_ && "Props must not be `nullptr`."); + assert( + std::dynamic_pointer_cast(props_) && + "Props must be an instance of ConcreteProps class."); + return std::static_pointer_cast(props_); } /* @@ -89,7 +92,11 @@ class ConcreteShadowNode : public ShadowNode { * Thread-safe after the node is sealed. */ ConcreteStateData const &getStateData() const { - return std::static_pointer_cast(state_)->getData(); + assert(state_ && "State must not be `nullptr`."); + assert( + std::dynamic_pointer_cast(state_) && + "State must be an instance of ConcreteState class."); + return std::static_pointer_cast(state_)->getData(); } /*