mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-28 02:27:19 +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:
Notes:
sideshowbarker
2024-07-17 07:42:40 +09:00
Author: https://github.com/davidot Commit: https://github.com/SerenityOS/serenity/commit/791855deab Pull-request: https://github.com/SerenityOS/serenity/pull/15029 Reviewed-by: https://github.com/linusg ✅ Reviewed-by: https://github.com/trflynn89
@@ -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