diff --git a/ReactCommon/react/renderer/attributedstring/conversions.h b/ReactCommon/react/renderer/attributedstring/conversions.h index f1bce4debe1844..34fe3dbab47acf 100644 --- a/ReactCommon/react/renderer/attributedstring/conversions.h +++ b/ReactCommon/react/renderer/attributedstring/conversions.h @@ -44,28 +44,40 @@ inline std::string toString(const EllipsizeMode &ellipsisMode) { case EllipsizeMode::Middle: return "middle"; } - abort(); + + LOG(ERROR) << "Unsupported EllipsizeMode value"; + react_native_assert(false); + + // Sane default in case of parsing errors + return "tail"; } inline void fromRawValue(const RawValue &value, EllipsizeMode &result) { - auto string = (std::string)value; - if (string == "clip") { - result = EllipsizeMode::Clip; - return; - } - if (string == "head") { - result = EllipsizeMode::Head; - return; - } - if (string == "tail") { - result = EllipsizeMode::Tail; - return; - } - if (string == "middle") { - result = EllipsizeMode::Middle; + react_native_assert(value.hasType()); + if (value.hasType()) { + auto string = (std::string)value; + if (string == "clip") { + result = EllipsizeMode::Clip; + } else if (string == "head") { + result = EllipsizeMode::Head; + } else if (string == "tail") { + result = EllipsizeMode::Tail; + } else if (string == "middle") { + result = EllipsizeMode::Middle; + } else { + // sane default + LOG(ERROR) << "Unsupported EllipsizeMode value: " << string; + react_native_assert(false); + result = EllipsizeMode::Tail; + } return; } - abort(); + + LOG(ERROR) << "Unsupported EllipsizeMode type"; + react_native_assert(false); + + // Sane default in case of parsing errors + result = EllipsizeMode::Tail; } inline std::string toString(const TextBreakStrategy &textBreakStrategy) { @@ -77,77 +89,76 @@ inline std::string toString(const TextBreakStrategy &textBreakStrategy) { case TextBreakStrategy::Balanced: return "balanced"; } - abort(); + + LOG(ERROR) << "Unsupported TextBreakStrategy value"; + react_native_assert(false); + return "simple"; } inline void fromRawValue(const RawValue &value, TextBreakStrategy &result) { - auto string = (std::string)value; - if (string == "simple") { - result = TextBreakStrategy::Simple; - return; - } - if (string == "highQuality") { - result = TextBreakStrategy::HighQuality; - return; - } - if (string == "balanced") { - result = TextBreakStrategy::Balanced; + react_native_assert(value.hasType()); + if (value.hasType()) { + auto string = (std::string)value; + if (string == "simple") { + result = TextBreakStrategy::Simple; + } else if (string == "highQuality") { + result = TextBreakStrategy::HighQuality; + } else if (string == "balanced") { + result = TextBreakStrategy::Balanced; + } else { + // sane default + LOG(ERROR) << "Unsupported TextBreakStrategy value: " << string; + react_native_assert(false); + result = TextBreakStrategy::Simple; + } return; } - abort(); + + LOG(ERROR) << "Unsupported TextBreakStrategy type"; + react_native_assert(false); + result = TextBreakStrategy::Simple; } inline void fromRawValue(const RawValue &value, FontWeight &result) { - auto string = (std::string)value; - if (string == "normal") { - result = FontWeight::Regular; - return; - } - if (string == "regular") { - result = FontWeight::Regular; - return; - } - if (string == "bold") { - result = FontWeight::Bold; - return; - } - if (string == "100") { - result = FontWeight::Weight100; - return; - } - if (string == "200") { - result = FontWeight::Weight200; - return; - } - if (string == "300") { - result = FontWeight::Weight300; - return; - } - if (string == "400") { - result = FontWeight::Weight400; - return; - } - if (string == "500") { - result = FontWeight::Weight500; - return; - } - if (string == "600") { - result = FontWeight::Weight600; - return; - } - if (string == "700") { - result = FontWeight::Weight700; - return; - } - if (string == "800") { - result = FontWeight::Weight800; - return; - } - if (string == "900") { - result = FontWeight::Weight900; + react_native_assert(value.hasType()); + if (value.hasType()) { + auto string = (std::string)value; + if (string == "normal") { + result = FontWeight::Regular; + } else if (string == "regular") { + result = FontWeight::Regular; + } else if (string == "bold") { + result = FontWeight::Bold; + } else if (string == "100") { + result = FontWeight::Weight100; + } else if (string == "200") { + result = FontWeight::Weight200; + } else if (string == "300") { + result = FontWeight::Weight300; + } else if (string == "400") { + result = FontWeight::Weight400; + } else if (string == "500") { + result = FontWeight::Weight500; + } else if (string == "600") { + result = FontWeight::Weight600; + } else if (string == "700") { + result = FontWeight::Weight700; + } else if (string == "800") { + result = FontWeight::Weight800; + } else if (string == "900") { + result = FontWeight::Weight900; + } else { + LOG(ERROR) << "Unsupported FontWeight value: " << string; + react_native_assert(false); + // sane default for prod + result = FontWeight::Regular; + } return; } - abort(); + + LOG(ERROR) << "Unsupported FontWeight type"; + react_native_assert(false); + result = FontWeight::Regular; } inline std::string toString(const FontWeight &fontWeight) { @@ -155,20 +166,28 @@ inline std::string toString(const FontWeight &fontWeight) { } inline void fromRawValue(const RawValue &value, FontStyle &result) { - auto string = (std::string)value; - if (string == "normal") { - result = FontStyle::Normal; - return; - } - if (string == "italic") { - result = FontStyle::Italic; - return; - } - if (string == "oblique") { - result = FontStyle::Oblique; + react_native_assert(value.hasType()); + if (value.hasType()) { + auto string = (std::string)value; + if (string == "normal") { + result = FontStyle::Normal; + } else if (string == "italic") { + result = FontStyle::Italic; + } else if (string == "oblique") { + result = FontStyle::Oblique; + } else { + LOG(ERROR) << "Unsupported FontStyle value: " << string; + react_native_assert(false); + // sane default for prod + result = FontStyle::Normal; + } return; } - abort(); + + LOG(ERROR) << "Unsupported FontStyle type"; + react_native_assert(false); + // sane default for prod + result = FontStyle::Normal; } inline std::string toString(const FontStyle &fontStyle) { @@ -180,34 +199,38 @@ inline std::string toString(const FontStyle &fontStyle) { case FontStyle::Oblique: return "oblique"; } - abort(); + + LOG(ERROR) << "Unsupported FontStyle value"; + react_native_assert(false); + // sane default for prod + return "normal"; } inline void fromRawValue(const RawValue &value, FontVariant &result) { react_native_assert(value.hasType>()); result = FontVariant::Default; - auto items = std::vector{value}; - for (const auto &item : items) { - if (item == "small-caps") { - result = (FontVariant)((int)result | (int)FontVariant::SmallCaps); - continue; - } - if (item == "oldstyle-nums") { - result = (FontVariant)((int)result | (int)FontVariant::OldstyleNums); - continue; - } - if (item == "lining-nums") { - result = (FontVariant)((int)result | (int)FontVariant::LiningNums); - continue; - } - if (item == "tabular-nums") { - result = (FontVariant)((int)result | (int)FontVariant::TabularNums); - continue; - } - if (item == "proportional-nums") { - result = (FontVariant)((int)result | (int)FontVariant::ProportionalNums); + if (value.hasType>()) { + auto items = std::vector{value}; + for (const auto &item : items) { + if (item == "small-caps") { + result = (FontVariant)((int)result | (int)FontVariant::SmallCaps); + } else if (item == "oldstyle-nums") { + result = (FontVariant)((int)result | (int)FontVariant::OldstyleNums); + } else if (item == "lining-nums") { + result = (FontVariant)((int)result | (int)FontVariant::LiningNums); + } else if (item == "tabular-nums") { + result = (FontVariant)((int)result | (int)FontVariant::TabularNums); + } else if (item == "proportional-nums") { + result = + (FontVariant)((int)result | (int)FontVariant::ProportionalNums); + } else { + LOG(ERROR) << "Unsupported FontVariant value: " << item; + react_native_assert(false); + } continue; } + } else { + LOG(ERROR) << "Unsupported FontVariant type"; } } @@ -238,34 +261,37 @@ inline std::string toString(const FontVariant &fontVariant) { } inline void fromRawValue(const RawValue &value, TextAlignment &result) { - auto string = (std::string)value; - if (string == "auto") { - result = TextAlignment::Natural; - return; - } - if (string == "left") { - result = TextAlignment::Left; - return; - } - if (string == "center") { - result = TextAlignment::Center; - return; - } - if (string == "right") { - result = TextAlignment::Right; - return; - } - if (string == "justify") { - result = TextAlignment::Justified; + react_native_assert(value.hasType()); + if (value.hasType()) { + auto string = (std::string)value; + if (string == "auto") { + result = TextAlignment::Natural; + } else if (string == "left") { + result = TextAlignment::Left; + } else if (string == "center") { + result = TextAlignment::Center; + } else if (string == "right") { + result = TextAlignment::Right; + } else if (string == "justify") { + result = TextAlignment::Justified; + } else { + LOG(ERROR) << "Unsupported TextAlignment value: " << string; + react_native_assert(false); + // sane default for prod + result = TextAlignment::Natural; + } return; } - abort(); + + LOG(ERROR) << "Unsupported TextAlignment type"; + // sane default for prod + result = TextAlignment::Natural; } inline std::string toString(const TextAlignment &textAlignment) { switch (textAlignment) { case TextAlignment::Natural: - return "natural"; + return "auto"; case TextAlignment::Left: return "left"; case TextAlignment::Center: @@ -275,64 +301,81 @@ inline std::string toString(const TextAlignment &textAlignment) { case TextAlignment::Justified: return "justified"; } - abort(); + + LOG(ERROR) << "Unsupported TextAlignment value"; + // sane default for prod + return "auto"; } inline void fromRawValue(const RawValue &value, WritingDirection &result) { - auto string = (std::string)value; - if (string == "natural") { - result = WritingDirection::Natural; - return; - } - if (string == "ltr") { - result = WritingDirection::LeftToRight; - return; - } - if (string == "rtl") { - result = WritingDirection::RightToLeft; + react_native_assert(value.hasType()); + if (value.hasType()) { + auto string = (std::string)value; + if (string == "natural" || string == "auto") { + result = WritingDirection::Natural; + } else if (string == "ltr") { + result = WritingDirection::LeftToRight; + } else if (string == "rtl") { + result = WritingDirection::RightToLeft; + } else { + LOG(ERROR) << "Unsupported WritingDirection value: " << string; + react_native_assert(false); + // sane default for prod + result = WritingDirection::Natural; + } return; } - abort(); + + LOG(ERROR) << "Unsupported WritingDirection type"; + // sane default for prod + result = WritingDirection::Natural; } inline std::string toString(const WritingDirection &writingDirection) { switch (writingDirection) { case WritingDirection::Natural: - return "natural"; + return "auto"; case WritingDirection::LeftToRight: return "ltr"; case WritingDirection::RightToLeft: return "rtl"; } - abort(); + + LOG(ERROR) << "Unsupported WritingDirection value"; + // sane default for prod + return "auto"; } inline void fromRawValue( const RawValue &value, TextDecorationLineType &result) { - auto string = (std::string)value; - if (string == "none") { - result = TextDecorationLineType::None; - return; - } - if (string == "underline") { - result = TextDecorationLineType::Underline; - return; - } - - // TODO: remove "line-through" after deprecation - if (string == "strikethrough" || string == "line-through") { - result = TextDecorationLineType::Strikethrough; + react_native_assert(value.hasType()); + if (value.hasType()) { + auto string = (std::string)value; + if (string == "none") { + result = TextDecorationLineType::None; + } else if (string == "underline") { + result = TextDecorationLineType::Underline; + } else if (string == "strikethrough" || string == "line-through") { + // TODO: remove "line-through" after deprecation + result = TextDecorationLineType::Strikethrough; + } else if ( + string == "underline-strikethrough" || + string == "underline line-through") { + // TODO: remove "underline line-through" after "line-through" deprecation + result = TextDecorationLineType::UnderlineStrikethrough; + } else { + LOG(ERROR) << "Unsupported TextDecorationLineType value: " << string; + react_native_assert(false); + // sane default for prod + result = TextDecorationLineType::None; + } return; } - // TODO: remove "underline line-through" after "line-through" deprecation - if (string == "underline-strikethrough" || - string == "underline line-through") { - result = TextDecorationLineType::UnderlineStrikethrough; - return; - } - abort(); + LOG(ERROR) << "Unsupported TextDecorationLineType type"; + // sane default for prod + result = TextDecorationLineType::None; } inline std::string toString( @@ -347,26 +390,37 @@ inline std::string toString( case TextDecorationLineType::UnderlineStrikethrough: return "underline-strikethrough"; } - abort(); + + LOG(ERROR) << "Unsupported TextDecorationLineType value"; + react_native_assert(false); + // sane default for prod + return "none"; } inline void fromRawValue( const RawValue &value, TextDecorationLineStyle &result) { - auto string = (std::string)value; - if (string == "single") { - result = TextDecorationLineStyle::Single; - return; - } - if (string == "thick") { - result = TextDecorationLineStyle::Thick; - return; - } - if (string == "double") { - result = TextDecorationLineStyle::Double; + react_native_assert(value.hasType()); + if (value.hasType()) { + auto string = (std::string)value; + if (string == "single") { + result = TextDecorationLineStyle::Single; + } else if (string == "thick") { + result = TextDecorationLineStyle::Thick; + } else if (string == "double") { + result = TextDecorationLineStyle::Double; + } else { + LOG(ERROR) << "Unsupported TextDecorationLineStyle value: " << string; + react_native_assert(false); + // sane default for prod + result = TextDecorationLineStyle::Single; + } return; } - abort(); + + LOG(ERROR) << "Unsupported TextDecorationLineStyle type"; + // sane default for prod + result = TextDecorationLineStyle::Single; } inline std::string toString( @@ -379,34 +433,41 @@ inline std::string toString( case TextDecorationLineStyle::Double: return "double"; } - abort(); + + LOG(ERROR) << "Unsupported TextDecorationLineStyle value"; + react_native_assert(false); + // sane default for prod + return "single"; } inline void fromRawValue( const RawValue &value, TextDecorationLinePattern &result) { - auto string = (std::string)value; - if (string == "solid") { - result = TextDecorationLinePattern::Solid; - return; - } - if (string == "dot") { - result = TextDecorationLinePattern::Dot; - return; - } - if (string == "dash") { - result = TextDecorationLinePattern::Dash; - return; - } - if (string == "dash-dot") { - result = TextDecorationLinePattern::DashDot; - return; - } - if (string == "dash-dot-dot") { - result = TextDecorationLinePattern::DashDotDot; + react_native_assert(value.hasType()); + if (value.hasType()) { + auto string = (std::string)value; + if (string == "solid") { + result = TextDecorationLinePattern::Solid; + } else if (string == "dot") { + result = TextDecorationLinePattern::Dot; + } else if (string == "dash") { + result = TextDecorationLinePattern::Dash; + } else if (string == "dash-dot") { + result = TextDecorationLinePattern::DashDot; + } else if (string == "dash-dot-dot") { + result = TextDecorationLinePattern::DashDotDot; + } else { + LOG(ERROR) << "Unsupported TextDecorationLinePattern value: " << string; + react_native_assert(false); + // sane default for prod + result = TextDecorationLinePattern::Solid; + } return; } - abort(); + + LOG(ERROR) << "Unsupported TextDecorationLineStyle type"; + // sane default for prod + result = TextDecorationLinePattern::Solid; } inline std::string toString( @@ -423,7 +484,11 @@ inline std::string toString( case TextDecorationLinePattern::DashDotDot: return "dash-dot-dot"; } - abort(); + + LOG(ERROR) << "Unsupported TextDecorationLinePattern value"; + react_native_assert(false); + // sane default for prod + return "solid"; } inline std::string toString(const AccessibilityRole &accessibilityRole) { @@ -483,120 +548,84 @@ inline std::string toString(const AccessibilityRole &accessibilityRole) { case AccessibilityRole::Toolbar: return "toolbar"; } - abort(); + + LOG(ERROR) << "Unsupported AccessibilityRole value"; + react_native_assert(false); + // sane default for prod + return "none"; } inline void fromRawValue(const RawValue &value, AccessibilityRole &result) { - auto string = (std::string)value; - if (string == "none") { - result = AccessibilityRole::None; - return; - } - if (string == "button") { - result = AccessibilityRole::Button; - return; - } - if (string == "link") { - result = AccessibilityRole::Link; - return; - } - if (string == "search") { - result = AccessibilityRole::Search; - return; - } - if (string == "image") { - result = AccessibilityRole::Image; - return; - } - if (string == "imagebutton") { - result = AccessibilityRole::Imagebutton; - return; - } - if (string == "keyboardkey") { - result = AccessibilityRole::Keyboardkey; - return; - } - if (string == "text") { - result = AccessibilityRole::Text; - return; - } - if (string == "adjustable") { - result = AccessibilityRole::Adjustable; - return; - } - if (string == "summary") { - result = AccessibilityRole::Summary; - return; - } - if (string == "header") { - result = AccessibilityRole::Header; - return; - } - if (string == "alert") { - result = AccessibilityRole::Alert; - return; - } - if (string == "checkbox") { - result = AccessibilityRole::Checkbox; - return; - } - if (string == "combobox") { - result = AccessibilityRole::Combobox; - return; - } - if (string == "menu") { - result = AccessibilityRole::Menu; - return; - } - if (string == "menubar") { - result = AccessibilityRole::Menubar; - return; - } - if (string == "menuitem") { - result = AccessibilityRole::Menuitem; - return; - } - if (string == "progressbar") { - result = AccessibilityRole::Progressbar; - return; - } - if (string == "radio") { - result = AccessibilityRole::Radio; - return; - } - if (string == "radiogroup") { - result = AccessibilityRole::Radiogroup; - return; - } - if (string == "scrollbar") { - result = AccessibilityRole::Scrollbar; - return; - } - if (string == "spinbutton") { - result = AccessibilityRole::Spinbutton; - return; - } - if (string == "switch") { - result = AccessibilityRole::Switch; - return; - } - if (string == "tab") { - result = AccessibilityRole::Tab; - return; - } - if (string == "tablist") { - result = AccessibilityRole::Tablist; - return; - } - if (string == "timer") { - result = AccessibilityRole::Timer; - return; - } - if (string == "toolbar") { - result = AccessibilityRole::Toolbar; + react_native_assert(value.hasType()); + if (value.hasType()) { + auto string = (std::string)value; + if (string == "none") { + result = AccessibilityRole::None; + } else if (string == "button") { + result = AccessibilityRole::Button; + } else if (string == "link") { + result = AccessibilityRole::Link; + } else if (string == "search") { + result = AccessibilityRole::Search; + } else if (string == "image") { + result = AccessibilityRole::Image; + } else if (string == "imagebutton") { + result = AccessibilityRole::Imagebutton; + } else if (string == "keyboardkey") { + result = AccessibilityRole::Keyboardkey; + } else if (string == "text") { + result = AccessibilityRole::Text; + } else if (string == "adjustable") { + result = AccessibilityRole::Adjustable; + } else if (string == "summary") { + result = AccessibilityRole::Summary; + } else if (string == "header") { + result = AccessibilityRole::Header; + } else if (string == "alert") { + result = AccessibilityRole::Alert; + } else if (string == "checkbox") { + result = AccessibilityRole::Checkbox; + } else if (string == "combobox") { + result = AccessibilityRole::Combobox; + } else if (string == "menu") { + result = AccessibilityRole::Menu; + } else if (string == "menubar") { + result = AccessibilityRole::Menubar; + } else if (string == "menuitem") { + result = AccessibilityRole::Menuitem; + } else if (string == "progressbar") { + result = AccessibilityRole::Progressbar; + } else if (string == "radio") { + result = AccessibilityRole::Radio; + } else if (string == "radiogroup") { + result = AccessibilityRole::Radiogroup; + } else if (string == "scrollbar") { + result = AccessibilityRole::Scrollbar; + } else if (string == "spinbutton") { + result = AccessibilityRole::Spinbutton; + } else if (string == "switch") { + result = AccessibilityRole::Switch; + } else if (string == "tab") { + result = AccessibilityRole::Tab; + } else if (string == "tablist") { + result = AccessibilityRole::Tablist; + } else if (string == "timer") { + result = AccessibilityRole::Timer; + } else if (string == "toolbar") { + result = AccessibilityRole::Toolbar; + } else { + LOG(ERROR) << "Unsupported AccessibilityRole value: " << string; + react_native_assert(false); + // sane default for prod + result = AccessibilityRole::None; + } return; } - abort(); + + LOG(ERROR) << "Unsupported AccessibilityRole type"; + react_native_assert(false); + // sane default for prod + result = AccessibilityRole::None; } inline ParagraphAttributes convertRawProp( diff --git a/ReactCommon/react/renderer/components/image/conversions.h b/ReactCommon/react/renderer/components/image/conversions.h index f0cf1dc1481071..9b74086e4acfbe 100644 --- a/ReactCommon/react/renderer/components/image/conversions.h +++ b/ReactCommon/react/renderer/components/image/conversions.h @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -90,28 +91,30 @@ inline std::string toString(const ImageSource &value) { inline void fromRawValue(const RawValue &value, ImageResizeMode &result) { react_native_assert(value.hasType()); - auto stringValue = (std::string)value; - if (stringValue == "cover") { + if (!value.hasType()) { + LOG(ERROR) << "Unsupported ImageResizeMode type"; + // "cover" is default in non-Fabric web and iOS result = ImageResizeMode::Cover; return; } - if (stringValue == "contain") { + + auto stringValue = (std::string)value; + if (stringValue == "cover") { + result = ImageResizeMode::Cover; + } else if (stringValue == "contain") { result = ImageResizeMode::Contain; - return; - } - if (stringValue == "stretch") { + } else if (stringValue == "stretch") { result = ImageResizeMode::Stretch; - return; - } - if (stringValue == "center") { + } else if (stringValue == "center") { result = ImageResizeMode::Center; - return; - } - if (stringValue == "repeat") { + } else if (stringValue == "repeat") { result = ImageResizeMode::Repeat; - return; + } else { + LOG(ERROR) << "Unsupported ImageResizeMode value: " << stringValue; + react_native_assert(false); + // "cover" is default in non-Fabric web and iOS + result = ImageResizeMode::Cover; } - abort(); } inline std::string toString(const ImageResizeMode &value) { diff --git a/ReactCommon/react/renderer/components/view/accessibilityPropsConversions.h b/ReactCommon/react/renderer/components/view/accessibilityPropsConversions.h index 35a92168e99e64..a2ed220ce990cb 100644 --- a/ReactCommon/react/renderer/components/view/accessibilityPropsConversions.h +++ b/ReactCommon/react/renderer/components/view/accessibilityPropsConversions.h @@ -8,6 +8,8 @@ #pragma once #include +#include +#include #include #include @@ -100,17 +102,19 @@ inline void fromRawValue(const RawValue &value, AccessibilityTraits &result) { return; } + result = {}; + + react_native_assert(value.hasType>()); if (value.hasType>()) { - result = {}; auto items = (std::vector)value; for (auto &item : items) { AccessibilityTraits itemAccessibilityTraits; fromString(item, itemAccessibilityTraits); result = result | itemAccessibilityTraits; } + } else { + LOG(ERROR) << "AccessibilityTraits parsing: unsupported type"; } - - abort(); } inline void fromRawValue(const RawValue &value, AccessibilityState &result) { @@ -168,24 +172,24 @@ inline std::string toString( inline void fromRawValue( const RawValue &value, ImportantForAccessibility &result) { - auto string = (std::string)value; - if (string == "auto") { - result = ImportantForAccessibility::Auto; - return; - } - if (string == "yes") { - result = ImportantForAccessibility::Yes; - return; - } - if (string == "no") { - result = ImportantForAccessibility::No; - return; - } - if (string == "no-hide-descendants") { - result = ImportantForAccessibility::NoHideDescendants; - return; + react_native_assert(value.hasType()); + if (value.hasType()) { + auto string = (std::string)value; + if (string == "auto") { + result = ImportantForAccessibility::Auto; + } else if (string == "yes") { + result = ImportantForAccessibility::Yes; + } else if (string == "no") { + result = ImportantForAccessibility::No; + } else if (string == "no-hide-descendants") { + result = ImportantForAccessibility::NoHideDescendants; + } else { + LOG(ERROR) << "Unsupported ImportantForAccessiblity value: " << string; + react_native_assert(false); + } + } else { + LOG(ERROR) << "Unsupported ImportantForAccessiblity type"; } - abort(); } } // namespace react diff --git a/ReactCommon/react/renderer/graphics/conversions.h b/ReactCommon/react/renderer/graphics/conversions.h index a80eda0b63e4bb..8818e3fff05f84 100644 --- a/ReactCommon/react/renderer/graphics/conversions.h +++ b/ReactCommon/react/renderer/graphics/conversions.h @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -93,14 +94,19 @@ inline void fromRawValue(const RawValue &value, Point &result) { return; } + react_native_assert(value.hasType>()); if (value.hasType>()) { auto array = (std::vector)value; react_native_assert(array.size() == 2); - result = {array.at(0), array.at(1)}; - return; + if (array.size() >= 2) { + result = {array.at(0), array.at(1)}; + } else { + result = {0, 0}; + LOG(ERROR) << "Unsupported Point vector size: " << array.size(); + } + } else { + LOG(ERROR) << "Unsupported Point type"; } - - abort(); } inline void fromRawValue(const RawValue &value, Size &result) { @@ -111,19 +117,27 @@ inline void fromRawValue(const RawValue &value, Size &result) { result.width = pair.second; } else if (pair.first == "height") { result.height = pair.second; + } else { + LOG(ERROR) << "Unsupported Size map key: " << pair.first; + react_native_assert(false); } } return; } + react_native_assert(value.hasType>()); if (value.hasType>()) { auto array = (std::vector)value; react_native_assert(array.size() == 2); - result = {array.at(0), array.at(1)}; - return; + if (array.size() >= 2) { + result = {array.at(0), array.at(1)}; + } else { + result = {0, 0}; + LOG(ERROR) << "Unsupported Size vector size: " << array.size(); + } + } else { + LOG(ERROR) << "Unsupported Size type"; } - - abort(); } inline void fromRawValue(const RawValue &value, EdgeInsets &result) { @@ -143,25 +157,34 @@ inline void fromRawValue(const RawValue &value, EdgeInsets &result) { result.bottom = pair.second; } else if (pair.first == "right") { result.right = pair.second; + } else { + LOG(ERROR) << "Unsupported EdgeInsets map key: " << pair.first; + react_native_assert(false); } } return; } + react_native_assert(value.hasType>()); if (value.hasType>()) { auto array = (std::vector)value; react_native_assert(array.size() == 4); - result = {array.at(0), array.at(1), array.at(2), array.at(3)}; - return; + if (array.size() >= 4) { + result = {array.at(0), array.at(1), array.at(2), array.at(3)}; + } else { + result = {0, 0, 0, 0}; + LOG(ERROR) << "Unsupported EdgeInsets vector size: " << array.size(); + } + } else { + LOG(ERROR) << "Unsupported EdgeInsets type"; } - - abort(); } inline void fromRawValue(const RawValue &value, CornerInsets &result) { if (value.hasType()) { auto number = (Float)value; result = {number, number, number, number}; + return; } if (value.hasType>()) { @@ -175,19 +198,29 @@ inline void fromRawValue(const RawValue &value, CornerInsets &result) { result.bottomLeft = pair.second; } else if (pair.first == "bottomRight") { result.bottomRight = pair.second; + } else { + LOG(ERROR) << "Unsupported CornerInsets map key: " << pair.first; + react_native_assert(false); } } return; } + react_native_assert(value.hasType>()); if (value.hasType>()) { auto array = (std::vector)value; react_native_assert(array.size() == 4); - result = {array.at(0), array.at(1), array.at(2), array.at(3)}; - return; + if (array.size() >= 4) { + result = {array.at(0), array.at(1), array.at(2), array.at(3)}; + } else { + LOG(ERROR) << "Unsupported CornerInsets vector size: " << array.size(); + } } - abort(); + // Error case - we should only here if all other supported cases fail + // In dev we would crash on assert before this point + result = {0, 0, 0, 0}; + LOG(ERROR) << "Unsupported CornerInsets type"; } inline std::string toString(const Point &point) { diff --git a/ReactCommon/react/renderer/textlayoutmanager/Android.mk b/ReactCommon/react/renderer/textlayoutmanager/Android.mk index b4303fb2efe67f..0d216e572762ba 100644 --- a/ReactCommon/react/renderer/textlayoutmanager/Android.mk +++ b/ReactCommon/react/renderer/textlayoutmanager/Android.mk @@ -11,7 +11,7 @@ LOCAL_MODULE := react_render_textlayoutmanager LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp $(LOCAL_PATH)/platform/android/react/renderer/textlayoutmanager/*.cpp) -LOCAL_SHARED_LIBRARIES := libfolly_futures libreactnativeutilsjni libreact_utils libfb libfbjni libreact_render_uimanager libreact_render_componentregistry libreact_render_attributedstring libreact_render_mounting libfolly_json libyoga libfolly_json libreact_render_core libreact_render_debug libreact_render_graphics libreact_debug libreact_render_mapbuffer libmapbufferjni libreact_render_telemetry +LOCAL_SHARED_LIBRARIES := libfolly_futures libreactnativeutilsjni libreact_utils libfb libfbjni libreact_render_uimanager libreact_render_componentregistry libreact_render_attributedstring libreact_render_mounting glog libfolly_json libglog_init libyoga libreact_render_core libreact_render_debug libreact_render_graphics libreact_debug libreact_render_mapbuffer libmapbufferjni libreact_render_telemetry LOCAL_STATIC_LIBRARIES :=