Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/react-native/ReactCommon/jsi/jsi/decorator.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ class RuntimeDecorator : public Base, private jsi::Instrumentation {
BigInt createBigIntFromUint64(uint64_t value) override {
return plain_.createBigIntFromUint64(value);
}
BigInt createBigIntFromBytes(const uint8_t* bytes, size_t length) override {
return plain_.createBigIntFromBytes(bytes, length);
}
bool bigintIsInt64(const BigInt& b) override {
return plain_.bigintIsInt64(b);
}
Expand All @@ -222,6 +225,9 @@ class RuntimeDecorator : public Base, private jsi::Instrumentation {
String bigintToString(const BigInt& bigint, int radix) override {
return plain_.bigintToString(bigint, radix);
}
std::vector<uint8_t> bytes(const BigInt& b) override {
return plain_.bytes(b);
}

String createStringFromAscii(const char* str, size_t length) override {
return plain_.createStringFromAscii(str, length);
Expand Down Expand Up @@ -779,6 +785,10 @@ class WithRuntimeDecorator : public RuntimeDecorator<Plain, Base> {
Around around{with_};
return RD::createBigIntFromUint64(i);
}
BigInt createBigIntFromBytes(const uint8_t* bytes, size_t length) override {
Around around{with_};
return RD::createBigIntFromBytes(bytes, length);
}
bool bigintIsInt64(const BigInt& bi) override {
Around around{with_};
return RD::bigintIsInt64(bi);
Expand All @@ -795,6 +805,10 @@ class WithRuntimeDecorator : public RuntimeDecorator<Plain, Base> {
Around around{with_};
return RD::bigintToString(bi, i);
}
std::vector<uint8_t> bytes(const BigInt& bi) override {
Around around{with_};
return RD::bytes(bi);
}

String createStringFromAscii(const char* str, size_t length) override {
Around around{with_};
Expand Down
11 changes: 11 additions & 0 deletions packages/react-native/ReactCommon/jsi/jsi/jsi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,17 @@ size_t Runtime::length(const String& str) {
return utf16(str).size();
}

BigInt Runtime::createBigIntFromBytes(
const uint8_t* /*bytes*/,
size_t /*length*/) {
throw JSINativeException(
"createBigIntFromBytes is not implemented by this runtime");
}

std::vector<uint8_t> Runtime::bytes(const BigInt& /*bigint*/) {
throw JSINativeException("BigInt.bytes is not implemented by this runtime");
}

bool Runtime::detached(const ArrayBuffer& buffer) {
Value prop = buffer.getProperty(*this, "detached");
if (!prop.isBool()) {
Expand Down
24 changes: 24 additions & 0 deletions packages/react-native/ReactCommon/jsi/jsi/jsi.h
Original file line number Diff line number Diff line change
Expand Up @@ -498,10 +498,17 @@ class JSI_EXPORT IRuntime : public ICast {

virtual BigInt createBigIntFromInt64(int64_t) = 0;
virtual BigInt createBigIntFromUint64(uint64_t) = 0;
/// Create a BigInt from a raw byte sequence \p bytes of \p length, which
/// provides the BigInt data in little-endian, two's complement
/// representation. The data is copied.
virtual BigInt createBigIntFromBytes(const uint8_t* bytes, size_t length) = 0;
virtual bool bigintIsInt64(const BigInt&) = 0;
virtual bool bigintIsUint64(const BigInt&) = 0;
virtual uint64_t truncate(const BigInt&) = 0;
virtual String bigintToString(const BigInt&, int) = 0;
/// Returns the raw byte representation of a BigInt in little-endian, two's
/// complement representation.
virtual std::vector<uint8_t> bytes(const BigInt&) = 0;

virtual String createStringFromAscii(const char* str, size_t length) = 0;
virtual String createStringFromUtf8(const uint8_t* utf8, size_t length) = 0;
Expand Down Expand Up @@ -793,6 +800,9 @@ class JSI_EXPORT Runtime : public IRuntime {

size_t length(const String& str) override;

BigInt createBigIntFromBytes(const uint8_t* bytes, size_t length) override;
std::vector<uint8_t> bytes(const BigInt&) override;

protected:
friend class Pointer;
friend class PropNameID;
Expand Down Expand Up @@ -1004,6 +1014,20 @@ class JSI_EXPORT BigInt : public Pointer {
return runtime.createBigIntFromUint64(value);
}

/// Create a BigInt from a raw byte sequence \p bytes of \p length, which
/// provides the BigInt data in little-endian, two's complement
/// representation. The data is copied.
static BigInt
fromBytes(IRuntime& runtime, const uint8_t* bytes, size_t length) {
return runtime.createBigIntFromBytes(bytes, length);
}

/// Returns the raw byte representation of a BigInt in little-endian, two's
/// complement representation.
std::vector<uint8_t> bytes(IRuntime& runtime) const {
return runtime.bytes(*this);
}

/// \return whether a === b.
static bool
strictEquals(IRuntime& runtime, const BigInt& a, const BigInt& b) {
Expand Down
Loading