summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/Intl
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2023-01-27 15:45:50 -0500
committerLinus Groh <mail@linusgroh.de>2023-01-28 00:13:59 +0000
commita824e1ac6af9086825989cb5d093b645239d48ef (patch)
tree07debce5cad277e954e07d6f676532c81bf8526a /Userland/Libraries/LibJS/Runtime/Intl
parenta65bf16cd542a67dc29b70d4d095b456451417be (diff)
downloadserenity-a824e1ac6af9086825989cb5d093b645239d48ef.zip
LibJS: Remove last use of DeprecatedString from Intl.MathematicalValue
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/Intl')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/MathematicalValue.cpp11
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/MathematicalValue.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp6
3 files changed, 10 insertions, 9 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/MathematicalValue.cpp b/Userland/Libraries/LibJS/Runtime/Intl/MathematicalValue.cpp
index 34e2e8e9e7..6f51e894cd 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/MathematicalValue.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/MathematicalValue.cpp
@@ -229,17 +229,18 @@ bool MathematicalValue::modulo_is_zero(Checked<i32> mod) const
[](auto) -> bool { VERIFY_NOT_REACHED(); });
}
-int MathematicalValue::logarithmic_floor() const
+ThrowCompletionOr<int> MathematicalValue::logarithmic_floor(VM& vm) const
{
return m_value.visit(
- [](double value) {
+ [](double value) -> ThrowCompletionOr<int> {
return static_cast<int>(floor(log10(value)));
},
- [](Crypto::SignedBigInteger const& value) {
+ [&](Crypto::SignedBigInteger const& value) -> ThrowCompletionOr<int> {
// FIXME: Can we do this without string conversion?
- return static_cast<int>(value.to_base_deprecated(10).length() - 1);
+ auto value_as_string = TRY_OR_THROW_OOM(vm, value.to_base(10));
+ return static_cast<int>(value_as_string.bytes_as_string_view().length() - 1);
},
- [](auto) -> int { VERIFY_NOT_REACHED(); });
+ [](auto) -> ThrowCompletionOr<int> { VERIFY_NOT_REACHED(); });
}
bool MathematicalValue::is_equal_to(MathematicalValue const& other) const
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/MathematicalValue.h b/Userland/Libraries/LibJS/Runtime/Intl/MathematicalValue.h
index 2bb6e53501..e9d0ea131c 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/MathematicalValue.h
+++ b/Userland/Libraries/LibJS/Runtime/Intl/MathematicalValue.h
@@ -79,7 +79,7 @@ public:
bool modulo_is_zero(Checked<i32> mod) const;
- int logarithmic_floor() const;
+ ThrowCompletionOr<int> logarithmic_floor(VM&) const;
bool is_equal_to(MathematicalValue const&) const;
bool is_less_than(MathematicalValue const&) const;
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp
index a8d5ba6348..a908ce55b8 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp
@@ -995,7 +995,7 @@ struct RawPrecisionResult {
static ThrowCompletionOr<RawPrecisionResult> to_raw_precision_function(VM& vm, MathematicalValue const& number, int precision, PreferredResult mode)
{
RawPrecisionResult result {};
- result.exponent = number.logarithmic_floor();
+ result.exponent = MUST_OR_THROW_OOM(number.logarithmic_floor(vm));
if (number.is_number()) {
result.number = number.divided_by_power(result.exponent - precision + 1);
@@ -1506,7 +1506,7 @@ ThrowCompletionOr<int> compute_exponent(VM& vm, NumberFormat& number_format, Mat
}
// 3. Let magnitude be the base 10 logarithm of x rounded down to the nearest integer.
- int magnitude = number.logarithmic_floor();
+ int magnitude = MUST_OR_THROW_OOM(number.logarithmic_floor(vm));
// 4. Let exponent be ComputeExponentForMagnitude(numberFormat, magnitude).
int exponent = MUST_OR_THROW_OOM(compute_exponent_for_magnitude(vm, number_format, magnitude));
@@ -1524,7 +1524,7 @@ ThrowCompletionOr<int> compute_exponent(VM& vm, NumberFormat& number_format, Mat
}
// 8. Let newMagnitude be the base 10 logarithm of formatNumberResult.[[RoundedNumber]] rounded down to the nearest integer.
- int new_magnitude = format_number_result.rounded_number.logarithmic_floor();
+ int new_magnitude = MUST_OR_THROW_OOM(format_number_result.rounded_number.logarithmic_floor(vm));
// 9. If newMagnitude is magnitude - exponent, then
if (new_magnitude == magnitude - exponent) {