Skip to content

Add JSI methods for BigInt with data larger than 64-bits#56818

Open
tsaichien wants to merge 1 commit into
facebook:mainfrom
tsaichien:export-D105071004
Open

Add JSI methods for BigInt with data larger than 64-bits#56818
tsaichien wants to merge 1 commit into
facebook:mainfrom
tsaichien:export-D105071004

Conversation

@tsaichien
Copy link
Copy Markdown
Contributor

Summary:
The existing JSI BigInt API can only construct or read back
values that fit in 64 bits (createBigIntFromInt64 /
createBigIntFromUint64 / truncate). This diff adds two new
IRuntime methods so JSI consumers can round-trip arbitrarily
large BigInt values.

  • createBigIntFromBytes(const uint8_t* bytes, size_t length):
    constructs a BigInt from a raw little-endian, two's complement
    byte sequence. The most significant bit of the highest-indexed
    byte is the sign bit.
  • bytes(const BigInt&): returns the BigInt's canonical
    little-endian, two's complement byte representation. The
    result round-trips through createBigIntFromBytes.

Pieces in this diff:

  • jsi.h: new pure-virtual IRuntime methods, matching Runtime
    override declarations, and BigInt::fromBytes /
    BigInt::bytes convenience helpers with detailed docs
    describing the byte format.
  • jsi.cpp: default Runtime implementations throw
    JSINativeException so runtimes that have not opted in surface
    a clear error rather than silently misbehaving.
  • decorator.h: forwarding overrides on RuntimeDecorator and
    WithRuntimeDecorator.
  • React Native fork (xplat/js/react-native-github/.../jsi):
    mirrored changes to keep the two trees in sync.

Differential Revision: D105071004

Summary:
The existing JSI BigInt API can only construct or read back
values that fit in 64 bits (createBigIntFromInt64 /
createBigIntFromUint64 / truncate). This diff adds two new
IRuntime methods so JSI consumers can round-trip arbitrarily
large BigInt values.

- `createBigIntFromBytes(const uint8_t* bytes, size_t length)`:
  constructs a BigInt from a raw little-endian, two's complement
  byte sequence. The most significant bit of the highest-indexed
  byte is the sign bit.
- `bytes(const BigInt&)`: returns the BigInt's canonical
  little-endian, two's complement byte representation. The
  result round-trips through createBigIntFromBytes.

Pieces in this diff:
- jsi.h: new pure-virtual IRuntime methods, matching Runtime
  override declarations, and `BigInt::fromBytes` /
  `BigInt::bytes` convenience helpers with detailed docs
  describing the byte format.
- jsi.cpp: default Runtime implementations throw
  JSINativeException so runtimes that have not opted in surface
  a clear error rather than silently misbehaving.
- decorator.h: forwarding overrides on RuntimeDecorator and
  WithRuntimeDecorator.
- React Native fork (xplat/js/react-native-github/.../jsi):
  mirrored changes to keep the two trees in sync.

Differential Revision: D105071004
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 13, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync Bot commented May 13, 2026

@tsaichien has exported this pull request. If you are a Meta employee, you can view the originating Diff in D105071004.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant