Skip to content

Commit 33324b8

Browse files
rshestfacebook-github-bot
authored andcommitted
Add uint32_t as accepted data type for bridging communication
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
1 parent 46ffeca commit 33324b8

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

ReactCommon/react/bridging/Number.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,15 @@ struct Bridging<int32_t> {
4444
}
4545
};
4646

47+
template <>
48+
struct Bridging<uint32_t> {
49+
static uint32_t fromJs(jsi::Runtime &, const jsi::Value &value) {
50+
return (uint32_t)value.asNumber();
51+
}
52+
53+
static jsi::Value toJs(jsi::Runtime &, uint32_t value) {
54+
return (double)value;
55+
}
56+
};
57+
4758
} // namespace facebook::react

ReactCommon/react/bridging/tests/BridgingTest.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,21 @@ TEST_F(BridgingTest, numberTest) {
6060
EXPECT_FLOAT_EQ(
6161
1.2f, static_cast<float>(bridging::toJs(rt, 1.2f).asNumber()));
6262
EXPECT_DOUBLE_EQ(1.2, bridging::toJs(rt, 1.2).asNumber());
63+
64+
EXPECT_EQ(
65+
42,
66+
static_cast<uint32_t>(
67+
bridging::toJs(rt, static_cast<uint32_t>(42)).asNumber()));
68+
69+
EXPECT_EQ(
70+
-42,
71+
static_cast<uint32_t>(
72+
bridging::toJs(rt, static_cast<uint32_t>(-42)).asNumber()));
73+
74+
EXPECT_FALSE(
75+
-42 ==
76+
static_cast<int32_t>(
77+
bridging::toJs(rt, static_cast<uint32_t>(-42)).asNumber()));
6378
}
6479

6580
TEST_F(BridgingTest, stringTest) {

0 commit comments

Comments
 (0)