Skip to content

Commit

Permalink
Add uint32_t as accepted data type for bridging communication
Browse files Browse the repository at this point in the history
Summary:
Add `uint32_t` as a valid type for communication between C++ and JS via bridging.

Changelog: [Internal]

Reviewed By: christophpurrer

Differential Revision: D42008412

fbshipit-source-id: 2c038e37745782b677d28bcbe4cc030683b74286
  • Loading branch information
rshest authored and facebook-github-bot committed Dec 14, 2022
1 parent 46ffeca commit 33324b8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ReactCommon/react/bridging/Number.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,15 @@ struct Bridging<int32_t> {
}
};

template <>
struct Bridging<uint32_t> {
static uint32_t fromJs(jsi::Runtime &, const jsi::Value &value) {
return (uint32_t)value.asNumber();
}

static jsi::Value toJs(jsi::Runtime &, uint32_t value) {
return (double)value;
}
};

} // namespace facebook::react
15 changes: 15 additions & 0 deletions ReactCommon/react/bridging/tests/BridgingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ TEST_F(BridgingTest, numberTest) {
EXPECT_FLOAT_EQ(
1.2f, static_cast<float>(bridging::toJs(rt, 1.2f).asNumber()));
EXPECT_DOUBLE_EQ(1.2, bridging::toJs(rt, 1.2).asNumber());

EXPECT_EQ(
42,
static_cast<uint32_t>(
bridging::toJs(rt, static_cast<uint32_t>(42)).asNumber()));

EXPECT_EQ(
-42,
static_cast<uint32_t>(
bridging::toJs(rt, static_cast<uint32_t>(-42)).asNumber()));

EXPECT_FALSE(
-42 ==
static_cast<int32_t>(
bridging::toJs(rt, static_cast<uint32_t>(-42)).asNumber()));
}

TEST_F(BridgingTest, stringTest) {
Expand Down

0 comments on commit 33324b8

Please sign in to comment.