Add JSI methods for BigInt with data larger than 64-bits#56818
Open
tsaichien wants to merge 1 commit into
Open
Add JSI methods for BigInt with data larger than 64-bits#56818tsaichien wants to merge 1 commit into
tsaichien wants to merge 1 commit into
Conversation
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
|
@tsaichien has exported this pull request. If you are a Meta employee, you can view the originating Diff in D105071004. |
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:
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 canonicallittle-endian, two's complement byte representation. The
result round-trips through createBigIntFromBytes.
Pieces in this diff:
override declarations, and
BigInt::fromBytes/BigInt::bytesconvenience helpers with detailed docsdescribing the byte format.
JSINativeException so runtimes that have not opted in surface
a clear error rather than silently misbehaving.
WithRuntimeDecorator.
mirrored changes to keep the two trees in sync.
Differential Revision: D105071004