mirror of
https://github.com/SerenityOS/serenity
synced 2026-05-05 14:42:50 +02: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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user