1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:07:46 +00:00

LibJS: Stop propagating small OOM errors from Intl.MathematicalValue

This commit is contained in:
Timothy Flynn 2023-08-30 11:55:14 -04:00 committed by Andreas Kling
parent 746ce6f9a1
commit 30a812b77b
3 changed files with 25 additions and 27 deletions

View file

@ -229,18 +229,18 @@ bool MathematicalValue::modulo_is_zero(Checked<i32> mod) const
[](auto) -> bool { VERIFY_NOT_REACHED(); });
}
ThrowCompletionOr<int> MathematicalValue::logarithmic_floor(VM& vm) const
int MathematicalValue::logarithmic_floor() const
{
return m_value.visit(
[](double value) -> ThrowCompletionOr<int> {
[](double value) {
return static_cast<int>(floor(log10(value)));
},
[&](Crypto::SignedBigInteger const& value) -> ThrowCompletionOr<int> {
[&](Crypto::SignedBigInteger const& value) {
// FIXME: Can we do this without string conversion?
auto value_as_string = TRY_OR_THROW_OOM(vm, value.to_base(10));
auto value_as_string = MUST(value.to_base(10));
return static_cast<int>(value_as_string.bytes_as_string_view().length() - 1);
},
[](auto) -> ThrowCompletionOr<int> { VERIFY_NOT_REACHED(); });
[](auto) -> int { VERIFY_NOT_REACHED(); });
}
bool MathematicalValue::is_equal_to(MathematicalValue const& other) const
@ -294,16 +294,16 @@ bool MathematicalValue::is_zero() const
[](auto) { return false; });
}
ThrowCompletionOr<String> MathematicalValue::to_string(VM& vm) const
String MathematicalValue::to_string() const
{
return m_value.visit(
[&](double value) -> ThrowCompletionOr<String> {
[&](double value) {
return number_to_string(value, NumberToStringMode::WithoutExponent);
},
[&](Crypto::SignedBigInteger const& value) -> ThrowCompletionOr<String> {
return TRY_OR_THROW_OOM(vm, value.to_base(10));
[&](Crypto::SignedBigInteger const& value) {
return MUST(value.to_base(10));
},
[&](auto) -> ThrowCompletionOr<String> { VERIFY_NOT_REACHED(); });
[&](auto) -> String { VERIFY_NOT_REACHED(); });
}
Value MathematicalValue::to_value(VM& vm) const