mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 22:48:11 +00:00
LibCrypto+LibJS: Remove the create_from methods from BigInteger
Instead we just use a specific constructor. With this set of constructors using curly braces for constructing is highly recommended. As then it will not do too many implicit conversions which could lead to unexpected loss of data or calling the much slower double constructor. Also to ensure we don't feed (Un)SignedBigInteger infinities we throw RangeError earlier for Durations.
This commit is contained in:
parent
528891bf69
commit
791855deab
19 changed files with 77 additions and 82 deletions
|
@ -108,10 +108,13 @@ static Value raw_bytes_to_numeric(VM& vm, ByteBuffer raw_value, bool is_little_e
|
|||
UnderlyingBufferDataType int_value = 0;
|
||||
raw_value.span().copy_to({ &int_value, sizeof(UnderlyingBufferDataType) });
|
||||
if constexpr (sizeof(UnderlyingBufferDataType) == 8) {
|
||||
if constexpr (IsSigned<UnderlyingBufferDataType>)
|
||||
return js_bigint(vm, Crypto::SignedBigInteger::create_from(int_value));
|
||||
else
|
||||
return js_bigint(vm, Crypto::SignedBigInteger { Crypto::UnsignedBigInteger::create_from(int_value) });
|
||||
if constexpr (IsSigned<UnderlyingBufferDataType>) {
|
||||
static_assert(IsSame<UnderlyingBufferDataType, i64>);
|
||||
return js_bigint(vm, Crypto::SignedBigInteger { int_value });
|
||||
} else {
|
||||
static_assert(IsOneOf<UnderlyingBufferDataType, u64, double>);
|
||||
return js_bigint(vm, Crypto::SignedBigInteger { Crypto::UnsignedBigInteger { int_value } });
|
||||
}
|
||||
} else {
|
||||
return Value(int_value);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue