1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-02 23:22:07 +00:00

LibJS: Hook the Intl mathematical value into Intl.NumberFormat

This commit is contained in:
Timothy Flynn 2022-07-19 12:11:34 -04:00 committed by Linus Groh
parent 0026e9a4c8
commit 292b8908b5
10 changed files with 201 additions and 305 deletions

View file

@ -11,6 +11,7 @@
namespace JS::Intl {
// 15.5.2 Number Format Functions, https://tc39.es/ecma402/#sec-number-format-functions
// 1.1.4 Number Format Functions, https://tc39.es/proposal-intl-numberformat-v3/out/numberformat/proposed.html#sec-number-format-functions
NumberFormatFunction* NumberFormatFunction::create(GlobalObject& global_object, NumberFormat& number_format)
{
return global_object.heap().allocate<NumberFormatFunction>(global_object, number_format, *global_object.function_prototype());
@ -41,12 +42,12 @@ ThrowCompletionOr<Value> NumberFormatFunction::call()
// 3. If value is not provided, let value be undefined.
auto value = vm.argument(0);
// 4. Let x be ? ToNumeric(value).
value = TRY(value.to_numeric(global_object));
// 4. Let x be ? ToIntlMathematicalValue(value).
auto mathematical_value = TRY(to_intl_mathematical_value(global_object, value));
// 5. Return ? FormatNumeric(nf, x).
// Note: Our implementation of FormatNumeric does not throw.
auto formatted = format_numeric(global_object, m_number_format, value);
auto formatted = format_numeric(global_object, m_number_format, move(mathematical_value));
return js_string(vm, move(formatted));
}