Skip to content

Commit

Permalink
Migrate Differentiator and RawPropsParser to rn_assert
Browse files Browse the repository at this point in the history
Summary:
This will allow these asserts to crash on Android debug builds.

We will migrate more sites as we confirm this is stable through testing.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D26409354

fbshipit-source-id: fb35cd8de29890f7c2b761435eaa02de377bdd1e
  • Loading branch information
JoshuaGross authored and facebook-github-bot committed Feb 18, 2021
1 parent ec4833f commit 16cf45a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 16 deletions.
1 change: 1 addition & 0 deletions ReactCommon/react/renderer/core/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ rn_xplat_cxx_library(
"//xplat/folly:molly",
"//xplat/jsi:JSIDynamic",
"//xplat/jsi:jsi",
react_native_xplat_target("react/debug:debug"),
react_native_xplat_target("react/utils:utils"),
react_native_xplat_target("react/renderer/debug:debug"),
react_native_xplat_target("react/renderer/graphics:graphics"),
Expand Down
7 changes: 4 additions & 3 deletions ReactCommon/react/renderer/core/RawPropsParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "RawPropsParser.h"

#include <folly/Likely.h>
#include <react/debug/rn_assert.h>
#include <react/renderer/core/RawProps.h>

#include <glog/logging.h>
Expand Down Expand Up @@ -62,14 +63,14 @@ RawValue const *RawPropsParser::at(
// the same order every time. This is trivial if you have a simple Props
// constructor, but difficult or impossible if you have a shared sub-prop
// Struct that is used by multiple parent Props.
#ifndef NDEBUG
#ifdef RN_DEBUG
bool resetLoop = false;
#endif
do {
rawProps.keyIndexCursor_++;

if (UNLIKELY(rawProps.keyIndexCursor_ >= size_)) {
#ifndef NDEBUG
#ifdef RN_DEBUG
if (resetLoop) {
LOG(ERROR) << "Looked up RawProps key that does not exist: "
<< (std::string)key;
Expand Down Expand Up @@ -106,7 +107,7 @@ void RawPropsParser::preparse(RawProps const &rawProps) const noexcept {
if (!rawProps.value_.isObject()) {
LOG(ERROR) << "Preparse props: rawProps value is not object";
}
assert(rawProps.value_.isObject());
rn_assert(rawProps.value_.isObject());
auto object = rawProps.value_.asObject(runtime);

auto names = object.getPropertyNames(runtime);
Expand Down
10 changes: 0 additions & 10 deletions ReactCommon/react/renderer/debug/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,6 @@ rn_xplat_cxx_library(
"-std=c++14",
"-Wall",
],
exported_platform_linker_flags = [
(
"^android.*",
["-llog"],
),
],
fbandroid_linker_flags = [
# for android rn_assert
"-llog",
],
fbobjc_compiler_flags = APPLE_COMPILER_FLAGS,
fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(),
force_static = True,
Expand Down
1 change: 1 addition & 0 deletions ReactCommon/react/renderer/mounting/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ rn_xplat_cxx_library(
"//xplat/folly:memory",
"//xplat/folly:molly",
react_native_xplat_target("better:better"),
react_native_xplat_target("react/debug:debug"),
react_native_xplat_target("react/renderer/components/root:root"),
react_native_xplat_target("react/renderer/components/view:view"),
react_native_xplat_target("react/renderer/core:core"),
Expand Down
7 changes: 4 additions & 3 deletions ReactCommon/react/renderer/mounting/Differentiator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <better/map.h>
#include <better/small_vector.h>
#include <react/debug/rn_assert.h>
#include <react/renderer/core/LayoutableShadowNode.h>
#include <react/renderer/debug/SystraceSection.h>
#include <algorithm>
Expand Down Expand Up @@ -82,7 +83,7 @@ class TinyMap final {
inline Iterator find(KeyT key) {
cleanVector();

assert(key != 0);
rn_assert(key != 0);

if (begin_() == nullptr) {
return end();
Expand All @@ -98,7 +99,7 @@ class TinyMap final {
}

inline void insert(Pair pair) {
assert(pair.first != 0);
rn_assert(pair.first != 0);
vector_.push_back(pair);
}

Expand Down Expand Up @@ -1489,7 +1490,7 @@ ShadowViewMutation::List calculateShadowViewMutations(
SystraceSection s("calculateShadowViewMutations");

// Root shadow nodes must be belong the same family.
assert(ShadowNode::sameFamily(oldRootShadowNode, newRootShadowNode));
rn_assert(ShadowNode::sameFamily(oldRootShadowNode, newRootShadowNode));

auto mutations = ShadowViewMutation::List{};
mutations.reserve(256);
Expand Down

0 comments on commit 16cf45a

Please sign in to comment.