From dc4207323b479810e32c3e6b0392bd0cd0868b2a Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sun, 12 Feb 2023 21:05:42 -0500 Subject: [PATCH] LibJS: Remove the VM parameter from the NumberToString AO This will be needed by Value::to_string_without_side_effects, which can be called in contexts without a VM (e.g. in AK::Format specializations). So to_string_without_side_effects will need to be callable without a VM, thus NumberToString must be as well. --- .../Libraries/LibJS/Runtime/Intl/MathematicalValue.cpp | 4 ++-- Userland/Libraries/LibJS/Runtime/Value.cpp | 8 ++++---- Userland/Libraries/LibJS/Runtime/Value.h | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Intl/MathematicalValue.cpp b/Userland/Libraries/LibJS/Runtime/Intl/MathematicalValue.cpp index 6f51e894cd..b14859ceee 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/MathematicalValue.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/MathematicalValue.cpp @@ -297,8 +297,8 @@ bool MathematicalValue::is_zero() const ThrowCompletionOr MathematicalValue::to_string(VM& vm) const { return m_value.visit( - [&](double value) { - return number_to_string(vm, value, NumberToStringMode::WithoutExponent); + [&](double value) -> ThrowCompletionOr { + return TRY_OR_THROW_OOM(vm, number_to_string(value, NumberToStringMode::WithoutExponent)); }, [&](Crypto::SignedBigInteger const& value) -> ThrowCompletionOr { return TRY_OR_THROW_OOM(vm, value.to_base(10)); diff --git a/Userland/Libraries/LibJS/Runtime/Value.cpp b/Userland/Libraries/LibJS/Runtime/Value.cpp index aa7bf20383..5ed6a184dd 100644 --- a/Userland/Libraries/LibJS/Runtime/Value.cpp +++ b/Userland/Libraries/LibJS/Runtime/Value.cpp @@ -206,11 +206,11 @@ static ErrorOr number_to_string_impl(StringBuilder& builder, double d, Num return {}; } -ThrowCompletionOr number_to_string(VM& vm, double d, NumberToStringMode mode) +ErrorOr number_to_string(double d, NumberToStringMode mode) { StringBuilder builder; - TRY_OR_THROW_OOM(vm, number_to_string_impl(builder, d, mode)); - return TRY_OR_THROW_OOM(vm, builder.to_string()); + TRY(number_to_string_impl(builder, d, mode)); + return builder.to_string(); } DeprecatedString number_to_deprecated_string(double d, NumberToStringMode mode) @@ -396,7 +396,7 @@ ThrowCompletionOr Value::to_primitive_string(VM& vm) ThrowCompletionOr Value::to_string(VM& vm) const { if (is_double()) - return number_to_string(vm, m_value.as_double); + return TRY_OR_THROW_OOM(vm, number_to_string(m_value.as_double)); switch (m_value.tag) { // 1. If argument is a String, return argument. diff --git a/Userland/Libraries/LibJS/Runtime/Value.h b/Userland/Libraries/LibJS/Runtime/Value.h index 7516a40cbf..d1349dbe7b 100644 --- a/Userland/Libraries/LibJS/Runtime/Value.h +++ b/Userland/Libraries/LibJS/Runtime/Value.h @@ -561,7 +561,7 @@ enum class NumberToStringMode { WithExponent, WithoutExponent, }; -ThrowCompletionOr number_to_string(VM& vm, double, NumberToStringMode = NumberToStringMode::WithExponent); +ErrorOr number_to_string(double, NumberToStringMode = NumberToStringMode::WithExponent); DeprecatedString number_to_deprecated_string(double, NumberToStringMode = NumberToStringMode::WithExponent); Optional string_to_number(StringView);