You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now that #510 is completed, there is support for BigInt in hermes and JSI. Unfortunately the JSI support is minimal at best. In particular there is no clear way to create or extract a BigInt value from C++ code. It may be possible to go via strings, but that is much more complicated and presumably less efficient than an int64/uint64_t constructor and accessor. Our use case is losslessly working with a C++ library that uses int64_t and we would like that to be as efficient as possible.
Solution
The NAPI BigInt API (docs) is a reasonable starting point here, obviously modified to fit JSI conventions. Key things are that there is a clear and hopefully efficient way to go to and from u/int64_t. It is also nice that there is a combined operation for extracting and checking that the value fits within the destination type. Of course if that isn't provided, it is possible to roll our own by making static(ish) BigInts at the extreme values and doing the comparisons on every extraction, but I assume there is a more efficient implementation possible.
From a quick glance, it looks like the internal BigIntPrimitive type already has the required functions for creating a BigInt, so that it should mostly just be a matter of plumbing to expose them in JSI. I don't immediately see an extraction API to u/int64_t, but I don't think it would be too complicated to either build one on top of getRawData(), or make a new API working directly from the internal representation for efficiency.
The text was updated successfully, but these errors were encountered:
Thank you for your feedback! We left jsi's BigInt interface lacking by design -- we weren't sure what kind of support the community would want, and we wanted to avoid adding APIs that no one used.
Your asks are fairly reasonable, and the team is already working on this. Hopefully you'll see something shortly.
I was about to ask for an update as we are almost ready to start on our JSI port now that our NAPI binding is wrapping up. Then I noticed, that it looks like this is already done via e8cc573. Is there more work to be done before those are ready to be used, or can this ticket be closed?
Problem
Now that #510 is completed, there is support for BigInt in hermes and JSI. Unfortunately the JSI support is minimal at best. In particular there is no clear way to create or extract a BigInt value from C++ code. It may be possible to go via strings, but that is much more complicated and presumably less efficient than an
int64
/uint64_t
constructor and accessor. Our use case is losslessly working with a C++ library that usesint64_t
and we would like that to be as efficient as possible.Solution
The NAPI BigInt API (docs) is a reasonable starting point here, obviously modified to fit JSI conventions. Key things are that there is a clear and hopefully efficient way to go to and from
u/int64_t
. It is also nice that there is a combined operation for extracting and checking that the value fits within the destination type. Of course if that isn't provided, it is possible to roll our own by making static(ish) BigInts at the extreme values and doing the comparisons on every extraction, but I assume there is a more efficient implementation possible.From a quick glance, it looks like the internal
BigIntPrimitive
type already has the required functions for creating a BigInt, so that it should mostly just be a matter of plumbing to expose them in JSI. I don't immediately see an extraction API tou/int64_t
, but I don't think it would be too complicated to either build one on top ofgetRawData()
, or make a new API working directly from the internal representation for efficiency.The text was updated successfully, but these errors were encountered: