Skip to content

Commit

Permalink
fix(ios): move static maps to heap for checking static overflow crash
Browse files Browse the repository at this point in the history
  • Loading branch information
etkmao committed Sep 10, 2024
1 parent 7c6d556 commit 602e3c0
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 66 deletions.
1 change: 1 addition & 0 deletions dom/include/dom/layout_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class LayoutNode {
const std::vector<std::string>& style_delete) = 0;
};

void InitLayoutConsts();
std::shared_ptr<LayoutNode> CreateLayoutNode();

} // namespace dom
Expand Down
1 change: 1 addition & 0 deletions dom/src/dom/root_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ bool DomNodeStyleDiffer::Calculate(const std::shared_ptr<hippy::dom::RootNode>&
}

RootNode::RootNode(uint32_t id) : DomNode(id, 0, 0, "", "", nullptr, nullptr, {}) {
InitLayoutConsts();
SetRenderInfo({id, 0, 0});
animation_manager_ = std::make_shared<AnimationManager>();
interceptors_.push_back(animation_manager_);
Expand Down
145 changes: 79 additions & 66 deletions dom/src/dom/taitank_layout_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,75 +30,82 @@
namespace hippy {
inline namespace dom {

const std::map<std::string, OverflowType> kOverflowMap = {{"visible", OverflowType::OVERFLOW_VISIBLE},
{"hidden", OverflowType::OVERFLOW_HIDDEN},
{"scroll", OverflowType::OVERFLOW_SCROLL}};

const std::map<std::string, FlexDirection> kFlexDirectionMap = {
{"row", FlexDirection::FLEX_DIRECTION_ROW},
{"row-reverse", FlexDirection::FLEX_DIRECTION_ROW_REVERSE},
{"column", FlexDirection::FLEX_DIRECTION_COLUMN},
{"column-reverse", FlexDirection::FLEX_DIRECTION_COLUNM_REVERSE}};

const std::map<std::string, FlexWrapMode> kWrapModeMap = {{"nowrap", FlexWrapMode::FLEX_NO_WRAP},
{"wrap", FlexWrapMode::FLEX_WRAP},
{"wrap-reverse", FlexWrapMode::FLEX_WRAP_REVERSE}};

const std::map<std::string, FlexAlign> kJustifyMap = {{"flex-start", FlexAlign::FLEX_ALIGN_START},
{"center", FlexAlign::FLEX_ALIGN_CENTER},
{"flex-end", FlexAlign::FLEX_ALIGN_END},
{"space-between", FlexAlign::FLEX_ALIGN_SPACE_BETWEEN},
{"space-around", FlexAlign::FLEX_ALIGN_SPACE_AROUND},
{"space-evenly", FlexAlign::FLEX_ALIGN_SPACE_EVENLY}};

const std::map<std::string, FlexAlign> kAlignMap = {{"auto", FlexAlign::FLEX_ALIGN_AUTO},
{"flex-start", FlexAlign::FLEX_ALIGN_START},
{"center", FlexAlign::FLEX_ALIGN_CENTER},
{"flex-end", FlexAlign::FLEX_ALIGN_END},
{"stretch", FlexAlign::FLEX_ALIGN_STRETCH},
{"baseline", FlexAlign::FLEX_ALIGN_BASE_LINE},
{"space-between", FlexAlign::FLEX_ALIGN_SPACE_BETWEEN},
{"space-around", FlexAlign::FLEX_ALIGN_SPACE_AROUND}};

const std::map<std::string, CSSDirection> kMarginMap = {{kMargin, CSSDirection::CSS_ALL},
{kMarginVertical, CSSDirection::CSS_VERTICAL},
{kMarginHorizontal, CSSDirection::CSS_HORIZONTAL},
{kMarginLeft, CSSDirection::CSS_LEFT},
{kMarginRight, CSSDirection::CSS_RIGHT},
{kMarginTop, CSSDirection::CSS_TOP},
{kMarginBottom, CSSDirection::CSS_BOTTOM}};

const std::map<std::string, CSSDirection> kPaddingMap = {{kPadding, CSSDirection::CSS_ALL},
{kPaddingVertical, CSSDirection::CSS_VERTICAL},
{kPaddingHorizontal, CSSDirection::CSS_HORIZONTAL},
{kPaddingLeft, CSSDirection::CSS_LEFT},
{kPaddingRight, CSSDirection::CSS_RIGHT},
{kPaddingTop, CSSDirection::CSS_TOP},
{kPaddingBottom, CSSDirection::CSS_BOTTOM}};

const std::map<std::string, CSSDirection> kPositionMap = {{kLeft, CSSDirection::CSS_LEFT},
{kRight, CSSDirection::CSS_RIGHT},
{kTop, CSSDirection::CSS_TOP},
{kBottom, CSSDirection::CSS_BOTTOM}};

const std::map<std::string, CSSDirection> kBorderMap = {{kBorderWidth, CSSDirection::CSS_ALL},
{kBorderLeftWidth, CSSDirection::CSS_LEFT},
{kBorderTopWidth, CSSDirection::CSS_TOP},
{kBorderRightWidth, CSSDirection::CSS_RIGHT},
{kBorderBottomWidth, CSSDirection::CSS_BOTTOM}};

const std::map<std::string, PositionType> kPositionTypeMap = {{"relative", PositionType::POSITION_TYPE_RELATIVE},
{"absolute", PositionType::POSITION_TYPE_ABSOLUTE}};

const std::map<std::string, DisplayType> kDisplayTypeMap = {{"none", DisplayType::DISPLAY_TYPE_NONE}};

const std::map<std::string, TaitankDirection> kDirectionMap = {
{"inherit", DIRECTION_INHERIT}, {"ltr", DIRECTION_LTR}, {"rtl", DIRECTION_RTL}};
class TaitankLayoutConsts {
public:
const std::map<std::string, OverflowType> kOverflowMap = {{"visible", OverflowType::OVERFLOW_VISIBLE},
{"hidden", OverflowType::OVERFLOW_HIDDEN},
{"scroll", OverflowType::OVERFLOW_SCROLL}};

const std::map<std::string, FlexDirection> kFlexDirectionMap = {
{"row", FlexDirection::FLEX_DIRECTION_ROW},
{"row-reverse", FlexDirection::FLEX_DIRECTION_ROW_REVERSE},
{"column", FlexDirection::FLEX_DIRECTION_COLUMN},
{"column-reverse", FlexDirection::FLEX_DIRECTION_COLUNM_REVERSE}};

const std::map<std::string, FlexWrapMode> kWrapModeMap = {{"nowrap", FlexWrapMode::FLEX_NO_WRAP},
{"wrap", FlexWrapMode::FLEX_WRAP},
{"wrap-reverse", FlexWrapMode::FLEX_WRAP_REVERSE}};

const std::map<std::string, FlexAlign> kJustifyMap = {{"flex-start", FlexAlign::FLEX_ALIGN_START},
{"center", FlexAlign::FLEX_ALIGN_CENTER},
{"flex-end", FlexAlign::FLEX_ALIGN_END},
{"space-between", FlexAlign::FLEX_ALIGN_SPACE_BETWEEN},
{"space-around", FlexAlign::FLEX_ALIGN_SPACE_AROUND},
{"space-evenly", FlexAlign::FLEX_ALIGN_SPACE_EVENLY}};

const std::map<std::string, FlexAlign> kAlignMap = {{"auto", FlexAlign::FLEX_ALIGN_AUTO},
{"flex-start", FlexAlign::FLEX_ALIGN_START},
{"center", FlexAlign::FLEX_ALIGN_CENTER},
{"flex-end", FlexAlign::FLEX_ALIGN_END},
{"stretch", FlexAlign::FLEX_ALIGN_STRETCH},
{"baseline", FlexAlign::FLEX_ALIGN_BASE_LINE},
{"space-between", FlexAlign::FLEX_ALIGN_SPACE_BETWEEN},
{"space-around", FlexAlign::FLEX_ALIGN_SPACE_AROUND}};

const std::map<std::string, CSSDirection> kMarginMap = {{kMargin, CSSDirection::CSS_ALL},
{kMarginVertical, CSSDirection::CSS_VERTICAL},
{kMarginHorizontal, CSSDirection::CSS_HORIZONTAL},
{kMarginLeft, CSSDirection::CSS_LEFT},
{kMarginRight, CSSDirection::CSS_RIGHT},
{kMarginTop, CSSDirection::CSS_TOP},
{kMarginBottom, CSSDirection::CSS_BOTTOM}};

const std::map<std::string, CSSDirection> kPaddingMap = {{kPadding, CSSDirection::CSS_ALL},
{kPaddingVertical, CSSDirection::CSS_VERTICAL},
{kPaddingHorizontal, CSSDirection::CSS_HORIZONTAL},
{kPaddingLeft, CSSDirection::CSS_LEFT},
{kPaddingRight, CSSDirection::CSS_RIGHT},
{kPaddingTop, CSSDirection::CSS_TOP},
{kPaddingBottom, CSSDirection::CSS_BOTTOM}};

const std::map<std::string, CSSDirection> kPositionMap = {{kLeft, CSSDirection::CSS_LEFT},
{kRight, CSSDirection::CSS_RIGHT},
{kTop, CSSDirection::CSS_TOP},
{kBottom, CSSDirection::CSS_BOTTOM}};

const std::map<std::string, CSSDirection> kBorderMap = {{kBorderWidth, CSSDirection::CSS_ALL},
{kBorderLeftWidth, CSSDirection::CSS_LEFT},
{kBorderTopWidth, CSSDirection::CSS_TOP},
{kBorderRightWidth, CSSDirection::CSS_RIGHT},
{kBorderBottomWidth, CSSDirection::CSS_BOTTOM}};

const std::map<std::string, PositionType> kPositionTypeMap = {{"relative", PositionType::POSITION_TYPE_RELATIVE},
{"absolute", PositionType::POSITION_TYPE_ABSOLUTE}};

const std::map<std::string, DisplayType> kDisplayTypeMap = {{"none", DisplayType::DISPLAY_TYPE_NONE}};

const std::map<std::string, TaitankDirection> kDirectionMap = {
{"inherit", DIRECTION_INHERIT}, {"ltr", DIRECTION_LTR}, {"rtl", DIRECTION_RTL}};
};

static std::shared_ptr<TaitankLayoutConsts> global_layout_consts = nullptr;

#define TAITANK_GET_STYLE_DECL(NAME, TYPE, DEFAULT) \
static TYPE GetStyle##NAME(const std::string& key) { \
auto iter = k##NAME##Map.find(key); \
if (iter != k##NAME##Map.end()) return iter->second; \
if (global_layout_consts == nullptr) return DEFAULT; \
auto &map = global_layout_consts->k##NAME##Map; \
auto iter = map.find(key); \
if (iter != map.end()) return iter->second; \
return DEFAULT; \
}

Expand Down Expand Up @@ -814,6 +821,12 @@ void TaitankLayoutNode::Deallocate() {
engine_node_ = nullptr;
}

void InitLayoutConsts() {
if (global_layout_consts == nullptr) {
global_layout_consts = std::make_shared<TaitankLayoutConsts>();
}
}

std::shared_ptr<LayoutNode> CreateLayoutNode() { return std::make_shared<TaitankLayoutNode>(); }

} // namespace dom
Expand Down
1 change: 1 addition & 0 deletions dom/src/dom/yoga_layout_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,7 @@ void YogaLayoutNode::Deallocate() {
YGConfigFree(yoga_config_);
}

void InitLayoutConsts() {}
std::shared_ptr<LayoutNode> CreateLayoutNode() { return std::make_shared<YogaLayoutNode>(); }

} // namespace dom
Expand Down

0 comments on commit 602e3c0

Please sign in to comment.