LibJS: Publicly expose double_to_string and rename it number_to_string

Rename it to match the name used by the spec.

Add an override mode to skip formatting numbers with an exponential sign
(e.g. 1e23). This mode is needed by Number and Intl.NumberFormat, who
don't call out a specific number-to-string method to use (they just say
to make "the String consisting of the digits of n").
This commit is contained in:
Timothy Flynn 2022-11-04 11:33:26 -04:00 committed by Linus Groh
commit 9620a092de
Notes: sideshowbarker 2024-07-17 04:47:43 +09:00
2 changed files with 13 additions and 4 deletions

View file

@ -564,6 +564,11 @@ ThrowCompletionOr<TriState> is_less_than(VM&, Value lhs, Value rhs, bool left_fi
double to_integer_or_infinity(double);
enum class NumberToStringMode {
WithExponent,
WithoutExponent,
};
String number_to_string(double, NumberToStringMode = NumberToStringMode::WithExponent);
Optional<Value> string_to_number(StringView);
inline bool Value::operator==(Value const& value) const { return same_value(*this, value); }