Add BigInt bridging support for Turbo Modules (#56008)#56008
Open
christophpurrer wants to merge 1 commit intofacebook:mainfrom
Open
Add BigInt bridging support for Turbo Modules (#56008)#56008christophpurrer wants to merge 1 commit intofacebook:mainfrom
christophpurrer wants to merge 1 commit intofacebook:mainfrom
Conversation
|
@christophpurrer has exported this pull request. If you are a Meta employee, you can view the originating Diff in D95706781. |
christophpurrer
added a commit
to christophpurrer/react-native-macos
that referenced
this pull request
Mar 9, 2026
Summary:
This diff adds native BigInt bridging support to React Native's C++ bridging layer.
BigInt is a JavaScript primitive that represents integers with arbitrary precision,
enabling safe handling of 64-bit integers that exceed JavaScript's Number.MAX_SAFE_INTEGER (2^53-1).
This implementation introduces a `facebook::react::BigInt` C++ wrapper class that
internally stores values as `std::variant<int64_t, uint64_t>`, preserving signedness.
The wrapper is constructed from `jsi::BigInt` (checking `isInt64()`/`isUint64()` for
lossless conversion) and provides `toJSBigInt()` for the reverse direction.
A `Bridging<BigInt>` template specialization converts between `jsi::Value` and
`facebook::react::BigInt`, enabling seamless use in Turbo Module method signatures.
Example usage:
```cpp
// In your Turbo Module
BigInt getBigInt(jsi::Runtime &rt, BigInt arg) {
return arg; // Receives BigInt from JS, returns BigInt to JS
}
```
```javascript
// In JavaScript
const result = nativeModule.getBigInt(BigInt('9223372036854775807'));
```
## Hey, wait a moment ....
Why are we not simply bridging like this:
```
struct Bridging<int64_t> {
```
or
```
struct Bridging<uint64_t> {
```
??????
Reason: It is very likely that custom implementations are already present in many RN apps > See: https://reactnative.dev/docs/the-new-architecture/custom-cxx-types
```
template <>
struct Bridging<int64_t> {
// Converts from the JS representation to the C++ representation
static int64_t fromJs(jsi::Runtime &rt, const jsi::String &value) {
try {
size_t pos;
auto str = value.utf8(rt);
auto num = std::stoll(str, &pos);
if (pos != str.size()) {
throw std::invalid_argument("Invalid number"); // don't support alphanumeric strings
}
return num;
} catch (const std::logic_error &e) {
throw jsi::JSError(rt, e.what());
}
}
// Converts from the C++ representation to the JS representation
static jsi::String toJs(jsi::Runtime &rt, int64_t value) {
return bridging::toJs(rt, std::to_string(value));
}
};
```
Changelog: [General][Added] - Add BigInt bridging support for Turbo Modules
Differential Revision: D95706781
7b29e3f to
9ef26ec
Compare
christophpurrer
added a commit
to christophpurrer/react-native-macos
that referenced
this pull request
Mar 9, 2026
Summary:
This diff adds native BigInt bridging support to React Native's C++ bridging layer.
BigInt is a JavaScript primitive that represents integers with arbitrary precision,
enabling safe handling of 64-bit integers that exceed JavaScript's Number.MAX_SAFE_INTEGER (2^53-1).
This implementation introduces a `facebook::react::BigInt` C++ wrapper class that
internally stores values as `std::variant<int64_t, uint64_t>`, preserving signedness.
The wrapper is constructed from `jsi::BigInt` (checking `isInt64()`/`isUint64()` for
lossless conversion) and provides `toJSBigInt()` for the reverse direction.
A `Bridging<BigInt>` template specialization converts between `jsi::Value` and
`facebook::react::BigInt`, enabling seamless use in Turbo Module method signatures.
Example usage:
```cpp
// In your Turbo Module
BigInt getBigInt(jsi::Runtime &rt, BigInt arg) {
return arg; // Receives BigInt from JS, returns BigInt to JS
}
```
```javascript
// In JavaScript
const result = nativeModule.getBigInt(BigInt('9223372036854775807'));
```
## Hey, wait a moment ....
Why are we not simply bridging like this:
```
struct Bridging<int64_t> {
```
or
```
struct Bridging<uint64_t> {
```
??????
Reason: It is very likely that custom implementations are already present in many RN apps > See: https://reactnative.dev/docs/the-new-architecture/custom-cxx-types
```
template <>
struct Bridging<int64_t> {
// Converts from the JS representation to the C++ representation
static int64_t fromJs(jsi::Runtime &rt, const jsi::String &value) {
try {
size_t pos;
auto str = value.utf8(rt);
auto num = std::stoll(str, &pos);
if (pos != str.size()) {
throw std::invalid_argument("Invalid number"); // don't support alphanumeric strings
}
return num;
} catch (const std::logic_error &e) {
throw jsi::JSError(rt, e.what());
}
}
// Converts from the C++ representation to the JS representation
static jsi::String toJs(jsi::Runtime &rt, int64_t value) {
return bridging::toJs(rt, std::to_string(value));
}
};
```
Changelog: [General][Added] - Add BigInt bridging support for Turbo Modules
Differential Revision: D95706781
christophpurrer
added a commit
to christophpurrer/react-native-macos
that referenced
this pull request
Mar 9, 2026
Summary:
This diff adds native BigInt bridging support to React Native's C++ bridging layer.
BigInt is a JavaScript primitive that represents integers with arbitrary precision,
enabling safe handling of 64-bit integers that exceed JavaScript's Number.MAX_SAFE_INTEGER (2^53-1).
This implementation introduces a `facebook::react::BigInt` C++ wrapper class that
internally stores values as `std::variant<int64_t, uint64_t>`, preserving signedness.
The wrapper is constructed from `jsi::BigInt` (checking `isInt64()`/`isUint64()` for
lossless conversion) and provides `toJSBigInt()` for the reverse direction.
A `Bridging<BigInt>` template specialization converts between `jsi::Value` and
`facebook::react::BigInt`, enabling seamless use in Turbo Module method signatures.
Example usage:
```cpp
// In your Turbo Module
BigInt getBigInt(jsi::Runtime &rt, BigInt arg) {
return arg; // Receives BigInt from JS, returns BigInt to JS
}
```
```javascript
// In JavaScript
const result = nativeModule.getBigInt(BigInt('9223372036854775807'));
```
## Hey, wait a moment ....
Why are we not simply bridging like this:
```
struct Bridging<int64_t> {
```
or
```
struct Bridging<uint64_t> {
```
??????
Reason: It is very likely that custom implementations are already present in many RN apps > See: https://reactnative.dev/docs/the-new-architecture/custom-cxx-types
```
template <>
struct Bridging<int64_t> {
// Converts from the JS representation to the C++ representation
static int64_t fromJs(jsi::Runtime &rt, const jsi::String &value) {
try {
size_t pos;
auto str = value.utf8(rt);
auto num = std::stoll(str, &pos);
if (pos != str.size()) {
throw std::invalid_argument("Invalid number"); // don't support alphanumeric strings
}
return num;
} catch (const std::logic_error &e) {
throw jsi::JSError(rt, e.what());
}
}
// Converts from the C++ representation to the JS representation
static jsi::String toJs(jsi::Runtime &rt, int64_t value) {
return bridging::toJs(rt, std::to_string(value));
}
};
```
Changelog: [General][Added] - Add BigInt bridging support for Turbo Modules
Differential Revision: D95706781
christophpurrer
added a commit
to christophpurrer/react-native-macos
that referenced
this pull request
Mar 9, 2026
Summary: Pull Request resolved: facebook#56008 This diff adds native BigInt bridging support to React Native's C++ bridging layer. BigInt is a JavaScript primitive that represents integers with arbitrary precision, enabling safe handling of 64-bit integers that exceed JavaScript's Number.MAX_SAFE_INTEGER (2^53-1). This implementation introduces a `facebook::react::BigInt` C++ wrapper class that internally stores values as `std::variant<int64_t, uint64_t>`, preserving signedness. The wrapper is constructed from `jsi::BigInt` (checking `isInt64()`/`isUint64()` for lossless conversion) and provides `toJSBigInt()` for the reverse direction. A `Bridging<BigInt>` template specialization converts between `jsi::Value` and `facebook::react::BigInt`, enabling seamless use in Turbo Module method signatures. Example usage: ```cpp // In your Turbo Module BigInt getBigInt(jsi::Runtime &rt, BigInt arg) { return arg; // Receives BigInt from JS, returns BigInt to JS } ``` ```javascript // In JavaScript const result = nativeModule.getBigInt(BigInt('9223372036854775807')); ``` ## Hey, wait a moment .... Why are we not simply bridging like this: ``` struct Bridging<int64_t> { ``` or ``` struct Bridging<uint64_t> { ``` ?????? Reason: It is very likely that custom implementations are already present in many RN apps > See: https://reactnative.dev/docs/the-new-architecture/custom-cxx-types ``` template <> struct Bridging<int64_t> { // Converts from the JS representation to the C++ representation static int64_t fromJs(jsi::Runtime &rt, const jsi::String &value) { try { size_t pos; auto str = value.utf8(rt); auto num = std::stoll(str, &pos); if (pos != str.size()) { throw std::invalid_argument("Invalid number"); // don't support alphanumeric strings } return num; } catch (const std::logic_error &e) { throw jsi::JSError(rt, e.what()); } } // Converts from the C++ representation to the JS representation static jsi::String toJs(jsi::Runtime &rt, int64_t value) { return bridging::toJs(rt, std::to_string(value)); } }; ``` Changelog: [General][Added] - Add BigInt bridging support for Turbo Modules Differential Revision: D95706781
christophpurrer
added a commit
to christophpurrer/react-native-macos
that referenced
this pull request
Mar 10, 2026
Summary: Pull Request resolved: facebook#56008 This diff adds native BigInt bridging support to React Native's C++ bridging layer. BigInt is a JavaScript primitive that represents integers with arbitrary precision, enabling safe handling of 64-bit integers that exceed JavaScript's Number.MAX_SAFE_INTEGER (2^53-1). This implementation introduces a `facebook::react::BigInt` C++ wrapper class that internally stores values as `std::variant<int64_t, uint64_t>`, preserving signedness. The wrapper is constructed from `jsi::BigInt` (checking `isInt64()`/`isUint64()` for lossless conversion) and provides `toJSBigInt()` for the reverse direction. A `Bridging<BigInt>` template specialization converts between `jsi::Value` and `facebook::react::BigInt`, enabling seamless use in Turbo Module method signatures. Example usage: ```cpp // In your Turbo Module BigInt getBigInt(jsi::Runtime &rt, BigInt arg) { return arg; // Receives BigInt from JS, returns BigInt to JS } ``` ```javascript // In JavaScript const result = nativeModule.getBigInt(BigInt('9223372036854775807')); ``` ## Hey, wait a moment .... Why are we not simply bridging like this: ``` struct Bridging<int64_t> { ``` or ``` struct Bridging<uint64_t> { ``` ?????? Reason: It is very likely that custom implementations are already present in many RN apps > See: https://reactnative.dev/docs/the-new-architecture/custom-cxx-types ``` template <> struct Bridging<int64_t> { // Converts from the JS representation to the C++ representation static int64_t fromJs(jsi::Runtime &rt, const jsi::String &value) { try { size_t pos; auto str = value.utf8(rt); auto num = std::stoll(str, &pos); if (pos != str.size()) { throw std::invalid_argument("Invalid number"); // don't support alphanumeric strings } return num; } catch (const std::logic_error &e) { throw jsi::JSError(rt, e.what()); } } // Converts from the C++ representation to the JS representation static jsi::String toJs(jsi::Runtime &rt, int64_t value) { return bridging::toJs(rt, std::to_string(value)); } }; ``` Changelog: [General][Added] - Add BigInt bridging support for Turbo Modules Differential Revision: D95706781
9ef26ec to
c89f279
Compare
christophpurrer
added a commit
to christophpurrer/react-native-macos
that referenced
this pull request
Mar 10, 2026
Summary:
This diff adds native BigInt bridging support to React Native's C++ bridging layer.
BigInt is a JavaScript primitive that represents integers with arbitrary precision,
enabling safe handling of 64-bit integers that exceed JavaScript's Number.MAX_SAFE_INTEGER (2^53-1).
This implementation introduces a `facebook::react::BigInt` C++ wrapper class that
internally stores values as `std::variant<int64_t, uint64_t>`, preserving signedness.
The wrapper is constructed from `jsi::BigInt` (checking `isInt64()`/`isUint64()` for
lossless conversion) and provides `toJSBigInt()` for the reverse direction.
A `Bridging<BigInt>` template specialization converts between `jsi::Value` and
`facebook::react::BigInt`, enabling seamless use in Turbo Module method signatures.
Example usage:
```cpp
// In your Turbo Module
BigInt getBigInt(jsi::Runtime &rt, BigInt arg) {
return arg; // Receives BigInt from JS, returns BigInt to JS
}
```
```javascript
// In JavaScript
const result = nativeModule.getBigInt(BigInt('9223372036854775807'));
```
## Hey, wait a moment ....
Why are we not simply bridging like this:
```
struct Bridging<int64_t> {
```
or
```
struct Bridging<uint64_t> {
```
??????
Reason: It is very likely that custom implementations are already present in many RN apps > See: https://reactnative.dev/docs/the-new-architecture/custom-cxx-types
```
template <>
struct Bridging<int64_t> {
// Converts from the JS representation to the C++ representation
static int64_t fromJs(jsi::Runtime &rt, const jsi::String &value) {
try {
size_t pos;
auto str = value.utf8(rt);
auto num = std::stoll(str, &pos);
if (pos != str.size()) {
throw std::invalid_argument("Invalid number"); // don't support alphanumeric strings
}
return num;
} catch (const std::logic_error &e) {
throw jsi::JSError(rt, e.what());
}
}
// Converts from the C++ representation to the JS representation
static jsi::String toJs(jsi::Runtime &rt, int64_t value) {
return bridging::toJs(rt, std::to_string(value));
}
};
```
Changelog: [General][Added] - Add BigInt bridging support for Turbo Modules
Differential Revision: D95706781
christophpurrer
added a commit
to christophpurrer/react-native-macos
that referenced
this pull request
Mar 10, 2026
Summary:
This diff adds native BigInt bridging support to React Native's C++ bridging layer.
BigInt is a JavaScript primitive that represents integers with arbitrary precision,
enabling safe handling of 64-bit integers that exceed JavaScript's Number.MAX_SAFE_INTEGER (2^53-1).
This implementation introduces a `facebook::react::BigInt` C++ wrapper class that
internally stores values as `std::variant<int64_t, uint64_t>`, preserving signedness.
The wrapper is constructed from `jsi::BigInt` (checking `isInt64()`/`isUint64()` for
lossless conversion) and provides `toJSBigInt()` for the reverse direction.
A `Bridging<BigInt>` template specialization converts between `jsi::Value` and
`facebook::react::BigInt`, enabling seamless use in Turbo Module method signatures.
Example usage:
```cpp
// In your Turbo Module
BigInt getBigInt(jsi::Runtime &rt, BigInt arg) {
return arg; // Receives BigInt from JS, returns BigInt to JS
}
```
```javascript
// In JavaScript
const result = nativeModule.getBigInt(BigInt('9223372036854775807'));
```
## Hey, wait a moment ....
Why are we not simply bridging like this:
```
struct Bridging<int64_t> {
```
or
```
struct Bridging<uint64_t> {
```
??????
Reason: It is very likely that custom implementations are already present in many RN apps > See: https://reactnative.dev/docs/the-new-architecture/custom-cxx-types
```
template <>
struct Bridging<int64_t> {
// Converts from the JS representation to the C++ representation
static int64_t fromJs(jsi::Runtime &rt, const jsi::String &value) {
try {
size_t pos;
auto str = value.utf8(rt);
auto num = std::stoll(str, &pos);
if (pos != str.size()) {
throw std::invalid_argument("Invalid number"); // don't support alphanumeric strings
}
return num;
} catch (const std::logic_error &e) {
throw jsi::JSError(rt, e.what());
}
}
// Converts from the C++ representation to the JS representation
static jsi::String toJs(jsi::Runtime &rt, int64_t value) {
return bridging::toJs(rt, std::to_string(value));
}
};
```
Changelog: [General][Added] - Add BigInt bridging support for Turbo Modules
Differential Revision: D95706781
christophpurrer
added a commit
to christophpurrer/react-native-macos
that referenced
this pull request
Mar 10, 2026
Summary:
This diff adds native BigInt bridging support to React Native's C++ bridging layer.
BigInt is a JavaScript primitive that represents integers with arbitrary precision,
enabling safe handling of 64-bit integers that exceed JavaScript's Number.MAX_SAFE_INTEGER (2^53-1).
This implementation introduces a `facebook::react::BigInt` C++ wrapper class that
internally stores values as `std::variant<int64_t, uint64_t>`, preserving signedness.
The wrapper is constructed from `jsi::BigInt` (checking `isInt64()`/`isUint64()` for
lossless conversion) and provides `toJSBigInt()` for the reverse direction.
A `Bridging<BigInt>` template specialization converts between `jsi::Value` and
`facebook::react::BigInt`, enabling seamless use in Turbo Module method signatures.
Example usage:
```cpp
// In your Turbo Module
BigInt getBigInt(jsi::Runtime &rt, BigInt arg) {
return arg; // Receives BigInt from JS, returns BigInt to JS
}
```
```javascript
// In JavaScript
const result = nativeModule.getBigInt(BigInt('9223372036854775807'));
```
## Hey, wait a moment ....
Why are we not simply bridging like this:
```
struct Bridging<int64_t> {
```
or
```
struct Bridging<uint64_t> {
```
??????
Reason: It is very likely that custom implementations are already present in many RN apps > See: https://reactnative.dev/docs/the-new-architecture/custom-cxx-types
```
template <>
struct Bridging<int64_t> {
// Converts from the JS representation to the C++ representation
static int64_t fromJs(jsi::Runtime &rt, const jsi::String &value) {
try {
size_t pos;
auto str = value.utf8(rt);
auto num = std::stoll(str, &pos);
if (pos != str.size()) {
throw std::invalid_argument("Invalid number"); // don't support alphanumeric strings
}
return num;
} catch (const std::logic_error &e) {
throw jsi::JSError(rt, e.what());
}
}
// Converts from the C++ representation to the JS representation
static jsi::String toJs(jsi::Runtime &rt, int64_t value) {
return bridging::toJs(rt, std::to_string(value));
}
};
```
Changelog: [General][Added] - Add BigInt bridging support for Turbo Modules
Differential Revision: D95706781
christophpurrer
added a commit
to christophpurrer/react-native-macos
that referenced
this pull request
Mar 10, 2026
Summary: Pull Request resolved: facebook#56008 This diff adds native BigInt bridging support to React Native's C++ bridging layer. BigInt is a JavaScript primitive that represents integers with arbitrary precision, enabling safe handling of 64-bit integers that exceed JavaScript's Number.MAX_SAFE_INTEGER (2^53-1). This implementation introduces a `facebook::react::BigInt` C++ wrapper class that internally stores values as `std::variant<int64_t, uint64_t>`, preserving signedness. The wrapper is constructed from `jsi::BigInt` (checking `isInt64()`/`isUint64()` for lossless conversion) and provides `toJSBigInt()` for the reverse direction. A `Bridging<BigInt>` template specialization converts between `jsi::Value` and `facebook::react::BigInt`, enabling seamless use in Turbo Module method signatures. Example usage: ```cpp // In your Turbo Module BigInt getBigInt(jsi::Runtime &rt, BigInt arg) { return arg; // Receives BigInt from JS, returns BigInt to JS } ``` ```javascript // In JavaScript const result = nativeModule.getBigInt(BigInt('9223372036854775807')); ``` ## Hey, wait a moment .... Why are we not simply bridging like this: ``` struct Bridging<int64_t> { ``` or ``` struct Bridging<uint64_t> { ``` ?????? Reason: It is very likely that custom implementations are already present in many RN apps > See: https://reactnative.dev/docs/the-new-architecture/custom-cxx-types ``` template <> struct Bridging<int64_t> { // Converts from the JS representation to the C++ representation static int64_t fromJs(jsi::Runtime &rt, const jsi::String &value) { try { size_t pos; auto str = value.utf8(rt); auto num = std::stoll(str, &pos); if (pos != str.size()) { throw std::invalid_argument("Invalid number"); // don't support alphanumeric strings } return num; } catch (const std::logic_error &e) { throw jsi::JSError(rt, e.what()); } } // Converts from the C++ representation to the JS representation static jsi::String toJs(jsi::Runtime &rt, int64_t value) { return bridging::toJs(rt, std::to_string(value)); } }; ``` Changelog: [General][Added] - Add BigInt bridging support for Turbo Modules Differential Revision: D95706781
c89f279 to
9bd160e
Compare
christophpurrer
added a commit
to christophpurrer/react-native-macos
that referenced
this pull request
Mar 10, 2026
Summary: Pull Request resolved: facebook#56008 This diff adds native BigInt bridging support to React Native's C++ bridging layer. BigInt is a JavaScript primitive that represents integers with arbitrary precision, enabling safe handling of 64-bit integers that exceed JavaScript's Number.MAX_SAFE_INTEGER (2^53-1). This implementation introduces a `facebook::react::BigInt` C++ wrapper class that internally stores values as `std::variant<int64_t, uint64_t>`, preserving signedness. The wrapper is constructed from `jsi::BigInt` (checking `isInt64()`/`isUint64()` for lossless conversion) and provides `toJSBigInt()` for the reverse direction. A `Bridging<BigInt>` template specialization converts between `jsi::Value` and `facebook::react::BigInt`, enabling seamless use in Turbo Module method signatures. Example usage: ```cpp // In your Turbo Module BigInt getBigInt(jsi::Runtime &rt, BigInt arg) { return arg; // Receives BigInt from JS, returns BigInt to JS } ``` ```javascript // In JavaScript const result = nativeModule.getBigInt(BigInt('9223372036854775807')); ``` ## Hey, wait a moment .... Why are we not simply bridging like this: ``` struct Bridging<int64_t> { ``` or ``` struct Bridging<uint64_t> { ``` ?????? Reason: It is very likely that custom implementations are already present in many RN apps > See: https://reactnative.dev/docs/the-new-architecture/custom-cxx-types ``` template <> struct Bridging<int64_t> { // Converts from the JS representation to the C++ representation static int64_t fromJs(jsi::Runtime &rt, const jsi::String &value) { try { size_t pos; auto str = value.utf8(rt); auto num = std::stoll(str, &pos); if (pos != str.size()) { throw std::invalid_argument("Invalid number"); // don't support alphanumeric strings } return num; } catch (const std::logic_error &e) { throw jsi::JSError(rt, e.what()); } } // Converts from the C++ representation to the JS representation static jsi::String toJs(jsi::Runtime &rt, int64_t value) { return bridging::toJs(rt, std::to_string(value)); } }; ``` Changelog: [General][Added] - Add BigInt bridging support for Turbo Modules Differential Revision: D95706781
christophpurrer
added a commit
to christophpurrer/react-native-macos
that referenced
this pull request
Mar 17, 2026
Summary:
This diff adds native BigInt bridging support to React Native's C++ bridging layer.
BigInt is a JavaScript primitive that represents integers with arbitrary precision,
enabling safe handling of 64-bit integers that exceed JavaScript's Number.MAX_SAFE_INTEGER (2^53-1).
This implementation introduces a `facebook::react::BigInt` C++ wrapper class that
internally stores values as `std::variant<int64_t, uint64_t>`, preserving signedness.
The wrapper is constructed from `jsi::BigInt` (checking `isInt64()`/`isUint64()` for
lossless conversion) and provides `toJSBigInt()` for the reverse direction.
A `Bridging<BigInt>` template specialization converts between `jsi::Value` and
`facebook::react::BigInt`, enabling seamless use in Turbo Module method signatures.
Example usage:
```cpp
// In your Turbo Module
BigInt getBigInt(jsi::Runtime &rt, BigInt arg) {
return arg; // Receives BigInt from JS, returns BigInt to JS
}
```
```javascript
// In JavaScript
const result = nativeModule.getBigInt(BigInt('9223372036854775807'));
```
## Hey, wait a moment ....
Why are we not simply bridging like this:
```
struct Bridging<int64_t> {
```
or
```
struct Bridging<uint64_t> {
```
??????
Reason: It is very likely that custom implementations are already present in many RN apps > See: https://reactnative.dev/docs/the-new-architecture/custom-cxx-types
```
template <>
struct Bridging<int64_t> {
// Converts from the JS representation to the C++ representation
static int64_t fromJs(jsi::Runtime &rt, const jsi::String &value) {
try {
size_t pos;
auto str = value.utf8(rt);
auto num = std::stoll(str, &pos);
if (pos != str.size()) {
throw std::invalid_argument("Invalid number"); // don't support alphanumeric strings
}
return num;
} catch (const std::logic_error &e) {
throw jsi::JSError(rt, e.what());
}
}
// Converts from the C++ representation to the JS representation
static jsi::String toJs(jsi::Runtime &rt, int64_t value) {
return bridging::toJs(rt, std::to_string(value));
}
};
```
Changelog: [General][Added] - Add BigInt bridging support for Turbo Modules
Differential Revision: D95706781
9bd160e to
37ff45f
Compare
christophpurrer
added a commit
to christophpurrer/react-native-macos
that referenced
this pull request
Mar 17, 2026
Summary:
This diff adds native BigInt bridging support to React Native's C++ bridging layer.
BigInt is a JavaScript primitive that represents integers with arbitrary precision,
enabling safe handling of 64-bit integers that exceed JavaScript's Number.MAX_SAFE_INTEGER (2^53-1).
This implementation introduces a `facebook::react::BigInt` C++ wrapper class that
internally stores values as `std::variant<int64_t, uint64_t>`, preserving signedness.
The wrapper is constructed from `jsi::BigInt` (checking `isInt64()`/`isUint64()` for
lossless conversion) and provides `toJSBigInt()` for the reverse direction.
A `Bridging<BigInt>` template specialization converts between `jsi::Value` and
`facebook::react::BigInt`, enabling seamless use in Turbo Module method signatures.
Example usage:
```cpp
// In your Turbo Module
BigInt getBigInt(jsi::Runtime &rt, BigInt arg) {
return arg; // Receives BigInt from JS, returns BigInt to JS
}
```
```javascript
// In JavaScript
const result = nativeModule.getBigInt(BigInt('9223372036854775807'));
```
## Hey, wait a moment ....
Why are we not simply bridging like this:
```
struct Bridging<int64_t> {
```
or
```
struct Bridging<uint64_t> {
```
??????
Reason: It is very likely that custom implementations are already present in many RN apps > See: https://reactnative.dev/docs/the-new-architecture/custom-cxx-types
```
template <>
struct Bridging<int64_t> {
// Converts from the JS representation to the C++ representation
static int64_t fromJs(jsi::Runtime &rt, const jsi::String &value) {
try {
size_t pos;
auto str = value.utf8(rt);
auto num = std::stoll(str, &pos);
if (pos != str.size()) {
throw std::invalid_argument("Invalid number"); // don't support alphanumeric strings
}
return num;
} catch (const std::logic_error &e) {
throw jsi::JSError(rt, e.what());
}
}
// Converts from the C++ representation to the JS representation
static jsi::String toJs(jsi::Runtime &rt, int64_t value) {
return bridging::toJs(rt, std::to_string(value));
}
};
```
Changelog: [General][Added] - Add BigInt bridging support for Turbo Modules
Differential Revision: D95706781
christophpurrer
added a commit
to christophpurrer/react-native-macos
that referenced
this pull request
Mar 17, 2026
Summary:
This diff adds native BigInt bridging support to React Native's C++ bridging layer.
BigInt is a JavaScript primitive that represents integers with arbitrary precision,
enabling safe handling of 64-bit integers that exceed JavaScript's Number.MAX_SAFE_INTEGER (2^53-1).
This implementation introduces a `facebook::react::BigInt` C++ wrapper class that
internally stores values as `std::variant<int64_t, uint64_t>`, preserving signedness.
The wrapper is constructed from `jsi::BigInt` (checking `isInt64()`/`isUint64()` for
lossless conversion) and provides `toJSBigInt()` for the reverse direction.
A `Bridging<BigInt>` template specialization converts between `jsi::Value` and
`facebook::react::BigInt`, enabling seamless use in Turbo Module method signatures.
Example usage:
```cpp
// In your Turbo Module
BigInt getBigInt(jsi::Runtime &rt, BigInt arg) {
return arg; // Receives BigInt from JS, returns BigInt to JS
}
```
```javascript
// In JavaScript
const result = nativeModule.getBigInt(BigInt('9223372036854775807'));
```
## Hey, wait a moment ....
Why are we not simply bridging like this:
```
struct Bridging<int64_t> {
```
or
```
struct Bridging<uint64_t> {
```
??????
Reason: It is very likely that custom implementations are already present in many RN apps > See: https://reactnative.dev/docs/the-new-architecture/custom-cxx-types
```
template <>
struct Bridging<int64_t> {
// Converts from the JS representation to the C++ representation
static int64_t fromJs(jsi::Runtime &rt, const jsi::String &value) {
try {
size_t pos;
auto str = value.utf8(rt);
auto num = std::stoll(str, &pos);
if (pos != str.size()) {
throw std::invalid_argument("Invalid number"); // don't support alphanumeric strings
}
return num;
} catch (const std::logic_error &e) {
throw jsi::JSError(rt, e.what());
}
}
// Converts from the C++ representation to the JS representation
static jsi::String toJs(jsi::Runtime &rt, int64_t value) {
return bridging::toJs(rt, std::to_string(value));
}
};
```
Changelog: [General][Added] - Add BigInt bridging support for Turbo Modules
Differential Revision: D95706781
Summary: Pull Request resolved: facebook#56008 This diff adds native BigInt bridging support to React Native's C++ bridging layer. BigInt is a JavaScript primitive that represents integers with arbitrary precision, enabling safe handling of 64-bit integers that exceed JavaScript's Number.MAX_SAFE_INTEGER (2^53-1). This implementation introduces a `facebook::react::BigInt` C++ wrapper class that internally stores values as `std::variant<int64_t, uint64_t>`, preserving signedness. The wrapper is constructed from `jsi::BigInt` (checking `isInt64()`/`isUint64()` for lossless conversion) and provides `toJSBigInt()` for the reverse direction. A `Bridging<BigInt>` template specialization converts between `jsi::Value` and `facebook::react::BigInt`, enabling seamless use in Turbo Module method signatures. Example usage: ```cpp // In your Turbo Module BigInt getBigInt(jsi::Runtime &rt, BigInt arg) { return arg; // Receives BigInt from JS, returns BigInt to JS } ``` ```javascript // In JavaScript const result = nativeModule.getBigInt(BigInt('9223372036854775807')); ``` ## Hey, wait a moment .... Why are we not simply bridging like this: ``` struct Bridging<int64_t> { ``` or ``` struct Bridging<uint64_t> { ``` ?????? Reason: It is very likely that custom implementations are already present in many RN apps > See: https://reactnative.dev/docs/the-new-architecture/custom-cxx-types ``` template <> struct Bridging<int64_t> { // Converts from the JS representation to the C++ representation static int64_t fromJs(jsi::Runtime &rt, const jsi::String &value) { try { size_t pos; auto str = value.utf8(rt); auto num = std::stoll(str, &pos); if (pos != str.size()) { throw std::invalid_argument("Invalid number"); // don't support alphanumeric strings } return num; } catch (const std::logic_error &e) { throw jsi::JSError(rt, e.what()); } } // Converts from the C++ representation to the JS representation static jsi::String toJs(jsi::Runtime &rt, int64_t value) { return bridging::toJs(rt, std::to_string(value)); } }; ``` Changelog: [General][Added] - Add BigInt bridging support for Turbo Modules Differential Revision: D95706781
37ff45f to
13aa922
Compare
christophpurrer
added a commit
to christophpurrer/react-native-macos
that referenced
this pull request
Mar 17, 2026
Summary: Pull Request resolved: facebook#56008 This diff adds native BigInt bridging support to React Native's C++ bridging layer. BigInt is a JavaScript primitive that represents integers with arbitrary precision, enabling safe handling of 64-bit integers that exceed JavaScript's Number.MAX_SAFE_INTEGER (2^53-1). This implementation introduces a `facebook::react::BigInt` C++ wrapper class that internally stores values as `std::variant<int64_t, uint64_t>`, preserving signedness. The wrapper is constructed from `jsi::BigInt` (checking `isInt64()`/`isUint64()` for lossless conversion) and provides `toJSBigInt()` for the reverse direction. A `Bridging<BigInt>` template specialization converts between `jsi::Value` and `facebook::react::BigInt`, enabling seamless use in Turbo Module method signatures. Example usage: ```cpp // In your Turbo Module BigInt getBigInt(jsi::Runtime &rt, BigInt arg) { return arg; // Receives BigInt from JS, returns BigInt to JS } ``` ```javascript // In JavaScript const result = nativeModule.getBigInt(BigInt('9223372036854775807')); ``` ## Hey, wait a moment .... Why are we not simply bridging like this: ``` struct Bridging<int64_t> { ``` or ``` struct Bridging<uint64_t> { ``` ?????? Reason: It is very likely that custom implementations are already present in many RN apps > See: https://reactnative.dev/docs/the-new-architecture/custom-cxx-types ``` template <> struct Bridging<int64_t> { // Converts from the JS representation to the C++ representation static int64_t fromJs(jsi::Runtime &rt, const jsi::String &value) { try { size_t pos; auto str = value.utf8(rt); auto num = std::stoll(str, &pos); if (pos != str.size()) { throw std::invalid_argument("Invalid number"); // don't support alphanumeric strings } return num; } catch (const std::logic_error &e) { throw jsi::JSError(rt, e.what()); } } // Converts from the C++ representation to the JS representation static jsi::String toJs(jsi::Runtime &rt, int64_t value) { return bridging::toJs(rt, std::to_string(value)); } }; ``` Changelog: [General][Added] - Add BigInt bridging support for Turbo Modules Differential Revision: D95706781
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
This diff adds native BigInt bridging support to React Native's C++ bridging layer.
BigInt is a JavaScript primitive that represents integers with arbitrary precision,
enabling safe handling of 64-bit integers that exceed JavaScript's Number.MAX_SAFE_INTEGER (2^53-1).
This implementation introduces a
facebook::react::BigIntC++ wrapper class thatinternally stores values as
std::variant<int64_t, uint64_t>, preserving signedness.The wrapper is constructed from
jsi::BigInt(checkingisInt64()/isUint64()forlossless conversion) and provides
toJSBigInt()for the reverse direction.A
Bridging<BigInt>template specialization converts betweenjsi::Valueandfacebook::react::BigInt, enabling seamless use in Turbo Module method signatures.Example usage:
Hey, wait a moment ....
Why are we not simply bridging like this:
or
??????
Reason: It is very likely that custom implementations are already present in many RN apps > See: https://reactnative.dev/docs/the-new-architecture/custom-cxx-types
Changelog: [General][Added] - Add BigInt bridging support for Turbo Modules
Differential Revision: D95706781