1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 08:07:44 +00:00

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.
This commit is contained in:
Timothy Flynn 2023-02-12 21:05:42 -05:00 committed by Linus Groh
parent 7a7a649f5b
commit dc4207323b
3 changed files with 7 additions and 7 deletions

View file

@ -297,8 +297,8 @@ bool MathematicalValue::is_zero() const
ThrowCompletionOr<String> MathematicalValue::to_string(VM& vm) const ThrowCompletionOr<String> MathematicalValue::to_string(VM& vm) const
{ {
return m_value.visit( return m_value.visit(
[&](double value) { [&](double value) -> ThrowCompletionOr<String> {
return number_to_string(vm, value, NumberToStringMode::WithoutExponent); return TRY_OR_THROW_OOM(vm, number_to_string(value, NumberToStringMode::WithoutExponent));
}, },
[&](Crypto::SignedBigInteger const& value) -> ThrowCompletionOr<String> { [&](Crypto::SignedBigInteger const& value) -> ThrowCompletionOr<String> {
return TRY_OR_THROW_OOM(vm, value.to_base(10)); return TRY_OR_THROW_OOM(vm, value.to_base(10));

View file

@ -206,11 +206,11 @@ static ErrorOr<void> number_to_string_impl(StringBuilder& builder, double d, Num
return {}; return {};
} }
ThrowCompletionOr<String> number_to_string(VM& vm, double d, NumberToStringMode mode) ErrorOr<String> number_to_string(double d, NumberToStringMode mode)
{ {
StringBuilder builder; StringBuilder builder;
TRY_OR_THROW_OOM(vm, number_to_string_impl(builder, d, mode)); TRY(number_to_string_impl(builder, d, mode));
return TRY_OR_THROW_OOM(vm, builder.to_string()); return builder.to_string();
} }
DeprecatedString number_to_deprecated_string(double d, NumberToStringMode mode) DeprecatedString number_to_deprecated_string(double d, NumberToStringMode mode)
@ -396,7 +396,7 @@ ThrowCompletionOr<PrimitiveString*> Value::to_primitive_string(VM& vm)
ThrowCompletionOr<String> Value::to_string(VM& vm) const ThrowCompletionOr<String> Value::to_string(VM& vm) const
{ {
if (is_double()) 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) { switch (m_value.tag) {
// 1. If argument is a String, return argument. // 1. If argument is a String, return argument.

View file

@ -561,7 +561,7 @@ enum class NumberToStringMode {
WithExponent, WithExponent,
WithoutExponent, WithoutExponent,
}; };
ThrowCompletionOr<String> number_to_string(VM& vm, double, NumberToStringMode = NumberToStringMode::WithExponent); ErrorOr<String> number_to_string(double, NumberToStringMode = NumberToStringMode::WithExponent);
DeprecatedString number_to_deprecated_string(double, NumberToStringMode = NumberToStringMode::WithExponent); DeprecatedString number_to_deprecated_string(double, NumberToStringMode = NumberToStringMode::WithExponent);
Optional<Value> string_to_number(StringView); Optional<Value> string_to_number(StringView);