mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 21:59:07 +00:00
LibJS: Merge Intl.DurationFormat style and display fields into a struct
This is an editorial change in the ECMA-402 spec. See:
d56d624
This commit is contained in:
parent
00d00b84d3
commit
780de1395b
Notes:
github-actions[bot]
2025-03-18 15:48:15 +00:00
Author: https://github.com/trflynn89
Commit: 780de1395b
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3980
10 changed files with 213 additions and 282 deletions
|
@ -782,6 +782,19 @@ ErrorOr<void> print_intl_segments(JS::PrintContext& print_context, JS::Intl::Seg
|
|||
|
||||
ErrorOr<void> print_intl_duration_format(JS::PrintContext& print_context, JS::Intl::DurationFormat const& duration_format, HashTable<JS::Object*>& seen_objects)
|
||||
{
|
||||
auto print_style_and_display = [&](StringView style_name, StringView display_name, JS::Intl::DurationFormat::DurationUnitOptions options) -> ErrorOr<void> {
|
||||
auto style = JS::Intl::DurationFormat::value_style_to_string(options.style);
|
||||
auto display = JS::Intl::DurationFormat::display_to_string(options.display);
|
||||
|
||||
TRY(js_out(print_context, "\n {}: ", style_name));
|
||||
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), style), seen_objects));
|
||||
|
||||
TRY(js_out(print_context, "\n {}: ", display_name));
|
||||
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), display), seen_objects));
|
||||
|
||||
return {};
|
||||
};
|
||||
|
||||
TRY(print_type(print_context, "Intl.DurationFormat"sv));
|
||||
TRY(js_out(print_context, "\n locale: "));
|
||||
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.locale()), seen_objects));
|
||||
|
@ -789,46 +802,18 @@ ErrorOr<void> print_intl_duration_format(JS::PrintContext& print_context, JS::In
|
|||
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.numbering_system()), seen_objects));
|
||||
TRY(js_out(print_context, "\n style: "));
|
||||
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.style_string()), seen_objects));
|
||||
TRY(js_out(print_context, "\n years: "));
|
||||
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.years_style_string()), seen_objects));
|
||||
TRY(js_out(print_context, "\n yearsDisplay: "));
|
||||
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.years_display_string()), seen_objects));
|
||||
TRY(js_out(print_context, "\n months: "));
|
||||
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.months_style_string()), seen_objects));
|
||||
TRY(js_out(print_context, "\n monthsDisplay: "));
|
||||
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.months_display_string()), seen_objects));
|
||||
TRY(js_out(print_context, "\n weeks: "));
|
||||
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.weeks_style_string()), seen_objects));
|
||||
TRY(js_out(print_context, "\n weeksDisplay: "));
|
||||
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.weeks_display_string()), seen_objects));
|
||||
TRY(js_out(print_context, "\n days: "));
|
||||
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.days_style_string()), seen_objects));
|
||||
TRY(js_out(print_context, "\n daysDisplay: "));
|
||||
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.days_display_string()), seen_objects));
|
||||
TRY(js_out(print_context, "\n hours: "));
|
||||
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.hours_style_string()), seen_objects));
|
||||
TRY(js_out(print_context, "\n hoursDisplay: "));
|
||||
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.hours_display_string()), seen_objects));
|
||||
TRY(js_out(print_context, "\n minutes: "));
|
||||
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.minutes_style_string()), seen_objects));
|
||||
TRY(js_out(print_context, "\n minutesDisplay: "));
|
||||
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.minutes_display_string()), seen_objects));
|
||||
TRY(js_out(print_context, "\n seconds: "));
|
||||
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.seconds_style_string()), seen_objects));
|
||||
TRY(js_out(print_context, "\n secondsDisplay: "));
|
||||
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.seconds_display_string()), seen_objects));
|
||||
TRY(js_out(print_context, "\n milliseconds: "));
|
||||
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.milliseconds_style_string()), seen_objects));
|
||||
TRY(js_out(print_context, "\n millisecondsDisplay: "));
|
||||
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.milliseconds_display_string()), seen_objects));
|
||||
TRY(js_out(print_context, "\n microseconds: "));
|
||||
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.microseconds_style_string()), seen_objects));
|
||||
TRY(js_out(print_context, "\n microsecondsDisplay: "));
|
||||
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.microseconds_display_string()), seen_objects));
|
||||
TRY(js_out(print_context, "\n nanoseconds: "));
|
||||
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.nanoseconds_style_string()), seen_objects));
|
||||
TRY(js_out(print_context, "\n nanosecondsDisplay: "));
|
||||
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.nanoseconds_display_string()), seen_objects));
|
||||
|
||||
TRY(print_style_and_display("years"sv, "yearsDisplay"sv, duration_format.years_options()));
|
||||
TRY(print_style_and_display("months"sv, "monthsDisplay"sv, duration_format.months_options()));
|
||||
TRY(print_style_and_display("weeks"sv, "weeksDisplay"sv, duration_format.weeks_options()));
|
||||
TRY(print_style_and_display("days"sv, "daysDisplay"sv, duration_format.days_options()));
|
||||
TRY(print_style_and_display("hours"sv, "hoursDisplay"sv, duration_format.hours_options()));
|
||||
TRY(print_style_and_display("minutes"sv, "minutesDisplay"sv, duration_format.minutes_options()));
|
||||
TRY(print_style_and_display("seconds"sv, "secondsDisplay"sv, duration_format.seconds_options()));
|
||||
TRY(print_style_and_display("milliseconds"sv, "millisecondsDisplay"sv, duration_format.milliseconds_options()));
|
||||
TRY(print_style_and_display("microseconds"sv, "microsecondsDisplay"sv, duration_format.microseconds_options()));
|
||||
TRY(print_style_and_display("nanoseconds"sv, "nanosecondsDisplay"sv, duration_format.nanoseconds_options()));
|
||||
|
||||
if (duration_format.has_fractional_digits()) {
|
||||
TRY(js_out(print_context, "\n fractionalDigits: "));
|
||||
TRY(print_value(print_context, JS::Value(duration_format.fractional_digits()), seen_objects));
|
||||
|
|
|
@ -208,7 +208,7 @@ static ThrowCompletionOr<void> validate_duration_unit_style(VM& vm, PropertyKey
|
|||
}
|
||||
|
||||
// 13.5.6 GetDurationUnitOptions ( unit, options, baseStyle, stylesList, digitalBase, prevStyle, twoDigitHours ), https://tc39.es/ecma402/#sec-getdurationunitoptions
|
||||
ThrowCompletionOr<DurationUnitOptions> get_duration_unit_options(VM& vm, DurationFormat::Unit unit, Object const& options, DurationFormat::Style base_style, ReadonlySpan<StringView> styles_list, DurationFormat::ValueStyle digital_base, Optional<DurationFormat::ValueStyle> previous_style, bool two_digit_hours)
|
||||
ThrowCompletionOr<DurationFormat::DurationUnitOptions> get_duration_unit_options(VM& vm, DurationFormat::Unit unit, Object const& options, DurationFormat::Style base_style, ReadonlySpan<StringView> styles_list, DurationFormat::ValueStyle digital_base, Optional<DurationFormat::ValueStyle> previous_style, bool two_digit_hours)
|
||||
{
|
||||
auto const& unit_property_key = unit_to_property_key(vm, unit);
|
||||
|
||||
|
@ -251,8 +251,8 @@ ThrowCompletionOr<DurationUnitOptions> get_duration_unit_options(VM& vm, Duratio
|
|||
style = DurationFormat::value_style_from_string(style_value.as_string().utf8_string_view());
|
||||
}
|
||||
|
||||
// 4. If style is "numeric" and unit is one of "milliseconds", "microseconds", or "nanoseconds", then
|
||||
if (style == DurationFormat::ValueStyle::Numeric && first_is_one_of(unit, DurationFormat::Unit::Milliseconds, DurationFormat::Unit::Microseconds, DurationFormat::Unit::Nanoseconds)) {
|
||||
// 4. If style is "numeric" and IsFractionalSecondUnitName(unit) is true, then
|
||||
if (style == DurationFormat::ValueStyle::Numeric && is_fractional_second_unit_name(unit)) {
|
||||
// a. Set style to "fractional".
|
||||
style = DurationFormat::ValueStyle::Fractional;
|
||||
|
||||
|
@ -280,8 +280,8 @@ ThrowCompletionOr<DurationUnitOptions> get_duration_unit_options(VM& vm, Duratio
|
|||
style = DurationFormat::ValueStyle::TwoDigit;
|
||||
}
|
||||
|
||||
// 10. Return the Record { [[Style]]: style, [[Display]]: display }.
|
||||
return DurationUnitOptions { .style = style, .display = display };
|
||||
// 10. Return the Duration Unit Options Record { [[Style]]: style, [[Display]]: display }.
|
||||
return DurationFormat::DurationUnitOptions { .style = style, .display = display };
|
||||
}
|
||||
|
||||
// 13.5.7 ComputeFractionalDigits ( durationFormat, duration ), https://tc39.es/ecma402/#sec-computefractionaldigits
|
||||
|
@ -294,25 +294,25 @@ Crypto::BigFraction compute_fractional_digits(DurationFormat const& duration_for
|
|||
// 2. Let exponent be 3.
|
||||
double exponent = 3;
|
||||
|
||||
// 3. For each row of Table 23, except the header row, in table order, do
|
||||
// 3. For each row of Table 24, except the header row, in table order, do
|
||||
for (auto const& duration_instances_component : duration_instances_components) {
|
||||
// a. Let style be the value of durationFormat's internal slot whose name is the Style Slot value of the current row.
|
||||
auto style = (duration_format.*duration_instances_component.get_style_slot)();
|
||||
|
||||
// b. If style is "fractional", then
|
||||
if (style == DurationFormat::ValueStyle::Fractional) {
|
||||
// i. Assert: The Unit value of the current row is "milliseconds", "microseconds", or "nanoseconds".
|
||||
VERIFY(first_is_one_of(duration_instances_component.unit, DurationFormat::Unit::Milliseconds, DurationFormat::Unit::Microseconds, DurationFormat::Unit::Nanoseconds));
|
||||
// a. Let unitOptions be the value of durationFormat's internal slot whose name is the Internal Slot value of the current row.
|
||||
auto unit_options = (duration_format.*duration_instances_component.get_internal_slot)();
|
||||
|
||||
// ii. Let value be the value of duration's field whose name is the Value Field value of the current row.
|
||||
// iii. Set value to value / 10**exponent.
|
||||
Crypto::BigFraction value {
|
||||
Crypto::SignedBigInteger { (duration.*duration_instances_component.value_slot)() },
|
||||
Crypto::UnsignedBigInteger { pow(10, exponent) }
|
||||
};
|
||||
// b. If unitOptions.[[Style]] is "fractional", then
|
||||
if (unit_options.style == DurationFormat::ValueStyle::Fractional) {
|
||||
// i. Let unit be the Unit value of the current row.
|
||||
auto unit = duration_instances_component.unit;
|
||||
|
||||
// iv. Set result to result + value.
|
||||
result = result + value;
|
||||
// ii. Assert: IsFractionalSecondUnitName(unit) is true.
|
||||
VERIFY(is_fractional_second_unit_name(unit));
|
||||
|
||||
// iii. Let value be the value of duration's field whose name is the Value Field value of the current row.
|
||||
auto value = (duration.*duration_instances_component.value_slot)();
|
||||
|
||||
// iv. Set result to result + (value / 10**exponent).
|
||||
result = result + Crypto::BigFraction { Crypto::SignedBigInteger { value }, Crypto::UnsignedBigInteger { pow(10, exponent) } };
|
||||
|
||||
// v. Set exponent to exponent + 3.
|
||||
exponent += 3;
|
||||
|
@ -326,22 +326,19 @@ Crypto::BigFraction compute_fractional_digits(DurationFormat const& duration_for
|
|||
// 13.5.8 NextUnitFractional ( durationFormat, unit ), https://tc39.es/ecma402/#sec-nextunitfractional
|
||||
bool next_unit_fractional(DurationFormat const& duration_format, DurationFormat::Unit unit)
|
||||
{
|
||||
// 1. Assert: unit is "seconds", "milliseconds", or "microseconds".
|
||||
VERIFY(first_is_one_of(unit, DurationFormat::Unit::Milliseconds, DurationFormat::Unit::Microseconds, DurationFormat::Unit::Nanoseconds));
|
||||
|
||||
// 2. If unit is "seconds" and durationFormat.[[MillisecondsStyle]] is "fractional", return true.
|
||||
if (unit == DurationFormat::Unit::Seconds && duration_format.milliseconds_style() == DurationFormat::ValueStyle::Fractional)
|
||||
// 1. If unit is "seconds" and durationFormat.[[MillisecondsOptions]].[[Style]] is "fractional", return true.
|
||||
if (unit == DurationFormat::Unit::Seconds && duration_format.milliseconds_options().style == DurationFormat::ValueStyle::Fractional)
|
||||
return true;
|
||||
|
||||
// 3. Else if unit is "milliseconds" and durationFormat.[[MicrosecondsStyle]] is "fractional", return true.
|
||||
if (unit == DurationFormat::Unit::Milliseconds && duration_format.microseconds_style() == DurationFormat::ValueStyle::Fractional)
|
||||
// 2. If unit is "milliseconds" and durationFormat.[[MicrosecondsOptions]].[[Style]] is "fractional", return true.
|
||||
if (unit == DurationFormat::Unit::Milliseconds && duration_format.microseconds_options().style == DurationFormat::ValueStyle::Fractional)
|
||||
return true;
|
||||
|
||||
// 4. Else if unit is "microseconds" and durationFormat.[[NanosecondsStyle]] is "fractional", return true.
|
||||
if (unit == DurationFormat::Unit::Microseconds && duration_format.nanoseconds_style() == DurationFormat::ValueStyle::Fractional)
|
||||
// 3. If unit is "microseconds" and durationFormat.[[NanosecondsOptions]].[[Style]] is "fractional", return true.
|
||||
if (unit == DurationFormat::Unit::Microseconds && duration_format.nanoseconds_options().style == DurationFormat::ValueStyle::Fractional)
|
||||
return true;
|
||||
|
||||
// 5. Return false.
|
||||
// 4. Return false.
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -353,8 +350,8 @@ Vector<DurationFormatPart> format_numeric_hours(VM& vm, DurationFormat const& du
|
|||
// 1. Let result be a new empty List.
|
||||
Vector<DurationFormatPart> result;
|
||||
|
||||
// 2. Let hoursStyle be durationFormat.[[HoursStyle]].
|
||||
auto hours_style = duration_format.hours_style();
|
||||
// 2. Let hoursStyle be durationFormat.[[HoursOptions]].[[Style]].
|
||||
auto hours_style = duration_format.hours_options().style;
|
||||
|
||||
// 3. Assert: hoursStyle is "numeric" or hoursStyle is "2-digit".
|
||||
VERIFY(hours_style == DurationFormat::ValueStyle::Numeric || hours_style == DurationFormat::ValueStyle::TwoDigit);
|
||||
|
@ -418,8 +415,8 @@ Vector<DurationFormatPart> format_numeric_minutes(VM& vm, DurationFormat const&
|
|||
result.append({ .type = "literal"sv, .value = move(separator), .unit = {} });
|
||||
}
|
||||
|
||||
// 3. Let minutesStyle be durationFormat.[[MinutesStyle]].
|
||||
auto minutes_style = duration_format.minutes_style();
|
||||
// 3. Let minutesStyle be durationFormat.[[MinutesOptions]].[[Style]].
|
||||
auto minutes_style = duration_format.minutes_options().style;
|
||||
|
||||
// 4. Assert: minutesStyle is "numeric" or minutesStyle is "2-digit".
|
||||
VERIFY(minutes_style == DurationFormat::ValueStyle::Numeric || minutes_style == DurationFormat::ValueStyle::TwoDigit);
|
||||
|
@ -483,8 +480,8 @@ Vector<DurationFormatPart> format_numeric_seconds(VM& vm, DurationFormat const&
|
|||
result.append({ .type = "literal"sv, .value = move(separator), .unit = {} });
|
||||
}
|
||||
|
||||
// 3. Let secondsStyle be durationFormat.[[SecondsStyle]].
|
||||
auto seconds_style = duration_format.seconds_style();
|
||||
// 3. Let secondsStyle be durationFormat.[[SecondsOptions]].[[Style]].
|
||||
auto seconds_style = duration_format.seconds_options().style;
|
||||
|
||||
// 4. Assert: secondsStyle is "numeric" or secondsStyle is "2-digit".
|
||||
VERIFY(seconds_style == DurationFormat::ValueStyle::Numeric || seconds_style == DurationFormat::ValueStyle::TwoDigit);
|
||||
|
@ -567,14 +564,14 @@ Vector<DurationFormatPart> format_numeric_units(VM& vm, DurationFormat const& du
|
|||
// 3. Let hoursValue be duration.[[Hours]].
|
||||
auto hours_value = duration.hours();
|
||||
|
||||
// 4. Let hoursDisplay be durationFormat.[[HoursDisplay]].
|
||||
auto hours_display = duration_format.hours_display();
|
||||
// 4. Let hoursDisplay be durationFormat.[[HoursOptions]].[[Display]].
|
||||
auto hours_display = duration_format.hours_options().display;
|
||||
|
||||
// 5. Let minutesValue be duration.[[Minutes]].
|
||||
// 5. Let minutesDisplay be durationFormat.[[MinutesOptions]].[[Display]].
|
||||
auto minutes_value = duration.minutes();
|
||||
|
||||
// 6. Let minutesDisplay be durationFormat.[[MinutesDisplay]].
|
||||
auto minutes_display = duration_format.minutes_display();
|
||||
auto minutes_display = duration_format.minutes_options().display;
|
||||
|
||||
// 7. Let secondsValue be duration.[[Seconds]].
|
||||
Crypto::BigFraction seconds_value { duration.seconds() };
|
||||
|
@ -585,8 +582,8 @@ Vector<DurationFormatPart> format_numeric_units(VM& vm, DurationFormat const& du
|
|||
seconds_value = seconds_value + compute_fractional_digits(duration_format, duration);
|
||||
}
|
||||
|
||||
// 9. Let secondsDisplay be durationFormat.[[SecondsDisplay]].
|
||||
auto seconds_display = duration_format.seconds_display();
|
||||
// 9. Let secondsDisplay be durationFormat.[[SecondsOptions]].[[Display]].
|
||||
auto seconds_display = duration_format.seconds_options().display;
|
||||
|
||||
// 10. Let hoursFormatted be false.
|
||||
auto hours_formatted = false;
|
||||
|
@ -682,7 +679,15 @@ Vector<DurationFormatPart> format_numeric_units(VM& vm, DurationFormat const& du
|
|||
return numeric_parts_list;
|
||||
}
|
||||
|
||||
// 13.5.13 ListFormatParts ( durationFormat, partitionedPartsList ), https://tc39.es/ecma402/#sec-listformatparts
|
||||
// 13.5.13 IsFractionalSecondUnitName ( unit ), https://tc39.es/ecma402/#sec-isfractionalsecondunitname
|
||||
bool is_fractional_second_unit_name(DurationFormat::Unit unit)
|
||||
{
|
||||
// 1. If unit is one of "milliseconds", "microseconds", or "nanoseconds", return true.
|
||||
// 2. Return false.
|
||||
return first_is_one_of(unit, DurationFormat::Unit::Milliseconds, DurationFormat::Unit::Microseconds, DurationFormat::Unit::Nanoseconds);
|
||||
}
|
||||
|
||||
// 13.5.14 ListFormatParts ( durationFormat, partitionedPartsList ), https://tc39.es/ecma402/#sec-listformatparts
|
||||
Vector<DurationFormatPart> list_format_parts(VM& vm, DurationFormat const& duration_format, Vector<Vector<DurationFormatPart>>& partitioned_parts_list)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
|
@ -773,7 +778,7 @@ Vector<DurationFormatPart> list_format_parts(VM& vm, DurationFormat const& durat
|
|||
return flattened_parts_list;
|
||||
}
|
||||
|
||||
// 13.5.14 PartitionDurationFormatPattern ( durationFormat, duration ), https://tc39.es/ecma402/#sec-partitiondurationformatpattern
|
||||
// 13.5.15 PartitionDurationFormatPattern ( durationFormat, duration ), https://tc39.es/ecma402/#sec-partitiondurationformatpattern
|
||||
// 15.9.8 PartitionDurationFormatPattern ( durationFormat, duration ), https://tc39.es/proposal-temporal/#sec-formatnumericunits
|
||||
Vector<DurationFormatPart> partition_duration_format_pattern(VM& vm, DurationFormat const& duration_format, Temporal::Duration const& duration)
|
||||
{
|
||||
|
@ -788,23 +793,25 @@ Vector<DurationFormatPart> partition_duration_format_pattern(VM& vm, DurationFor
|
|||
// 3. Let numericUnitFound be false.
|
||||
auto numeric_unit_found = false;
|
||||
|
||||
// 4. While numericUnitFound is false, repeat for each row in Table 23 in table order, except the header row:
|
||||
// 4. While numericUnitFound is false, repeat for each row in Table 24 in table order, except the header row:
|
||||
for (size_t i = 0; !numeric_unit_found && i < duration_instances_components.size(); ++i) {
|
||||
auto const& duration_instances_component = duration_instances_components[i];
|
||||
|
||||
// a. Let value be the value of duration's field whose name is the Value Field value of the current row.
|
||||
Crypto::BigFraction value { (duration.*duration_instances_component.value_slot)() };
|
||||
|
||||
// b. Let style be the value of durationFormat's internal slot whose name is the Style Slot value of the current row.
|
||||
auto style = (duration_format.*duration_instances_component.get_style_slot)();
|
||||
// b. Let unitOptions be the value of durationFormat's internal slot whose name is the Internal Slot value of the current row.
|
||||
// c. Let style be unitOptions.[[Style]].
|
||||
// d. Let display be unitOptions.[[Display]].
|
||||
auto [style, display] = (duration_format.*duration_instances_component.get_internal_slot)();
|
||||
|
||||
// c. Let display be the value of durationFormat's internal slot whose name is the Display Slot value of the current row.
|
||||
auto display = (duration_format.*duration_instances_component.get_display_slot)();
|
||||
|
||||
// d. Let unit be the Unit value of the current row.
|
||||
// e. Let unit be the Unit value of the current row.
|
||||
auto unit = duration_instances_component.unit;
|
||||
|
||||
// e. If style is "numeric" or "2-digit", then
|
||||
// f. Let numberFormatUnit be the NumberFormat Unit value of the current row.
|
||||
auto const& number_format_unit = unit_to_number_format_property_key(vm, duration_instances_component.unit);
|
||||
|
||||
// g. If style is "numeric" or "2-digit", then
|
||||
if (style == DurationFormat::ValueStyle::Numeric || style == DurationFormat::ValueStyle::TwoDigit) {
|
||||
// i. Let numericPartsList be FormatNumericUnits(durationFormat, duration, unit, signDisplayed).
|
||||
auto numeric_parts_list = format_numeric_units(vm, duration_format, duration, unit, sign_displayed);
|
||||
|
@ -816,13 +823,13 @@ Vector<DurationFormatPart> partition_duration_format_pattern(VM& vm, DurationFor
|
|||
// iii. Set numericUnitFound to true.
|
||||
numeric_unit_found = true;
|
||||
}
|
||||
// f. Else,
|
||||
// h. Else,
|
||||
else {
|
||||
// i. Let nfOpts be OrdinaryObjectCreate(null).
|
||||
auto number_format_options = Object::create(realm, nullptr);
|
||||
|
||||
// ii. If unit is one of "seconds", "milliseconds", or "microseconds", and NextUnitFractional(durationFormat, unit) is true, then
|
||||
if (first_is_one_of(unit, DurationFormat::Unit::Milliseconds, DurationFormat::Unit::Microseconds, DurationFormat::Unit::Nanoseconds) && next_unit_fractional(duration_format, unit)) {
|
||||
// ii. If NextUnitFractional(durationFormat, unit) is true, then
|
||||
if (next_unit_fractional(duration_format, unit)) {
|
||||
// 1. Set value to value + ComputeFractionalDigits(durationFormat, duration).
|
||||
value = value + compute_fractional_digits(duration_format, duration);
|
||||
|
||||
|
@ -875,29 +882,26 @@ Vector<DurationFormatPart> partition_duration_format_pattern(VM& vm, DurationFor
|
|||
MUST(number_format_options->create_data_property_or_throw(vm.names.signDisplay, PrimitiveString::create(vm, "never"sv)));
|
||||
}
|
||||
|
||||
// 4. Let numberFormatUnit be the NumberFormat Unit value of the current row.
|
||||
auto const& number_format_unit = unit_to_number_format_property_key(vm, duration_instances_component.unit);
|
||||
|
||||
// 5. Perform ! CreateDataPropertyOrThrow(nfOpts, "style", "unit").
|
||||
// 3. Perform ! CreateDataPropertyOrThrow(nfOpts, "style", "unit").
|
||||
MUST(number_format_options->create_data_property_or_throw(vm.names.style, PrimitiveString::create(vm, "unit"sv)));
|
||||
|
||||
// 6. Perform ! CreateDataPropertyOrThrow(nfOpts, "unit", numberFormatUnit).
|
||||
// 4. Perform ! CreateDataPropertyOrThrow(nfOpts, "unit", numberFormatUnit).
|
||||
MUST(number_format_options->create_data_property_or_throw(vm.names.unit, PrimitiveString::create(vm, number_format_unit.as_string())));
|
||||
|
||||
// 7. Perform ! CreateDataPropertyOrThrow(nfOpts, "unitDisplay", style).
|
||||
// 5. Perform ! CreateDataPropertyOrThrow(nfOpts, "unitDisplay", style).
|
||||
auto locale_style = Unicode::style_to_string(static_cast<Unicode::Style>(style));
|
||||
MUST(number_format_options->create_data_property_or_throw(vm.names.unitDisplay, PrimitiveString::create(vm, locale_style)));
|
||||
|
||||
// 8. Let nf be ! Construct(%Intl.NumberFormat%, « durationFormat.[[Locale]], nfOpts »).
|
||||
// 6. Let nf be ! Construct(%Intl.NumberFormat%, « durationFormat.[[Locale]], nfOpts »).
|
||||
auto number_format = construct_number_format(vm, duration_format, number_format_options);
|
||||
|
||||
// 9. Let parts be PartitionNumberPattern(nf, value).
|
||||
// 7. Let parts be PartitionNumberPattern(nf, value).
|
||||
auto parts = partition_number_pattern(number_format, value_mv);
|
||||
|
||||
// 10. Let list be a new empty List.
|
||||
// 8. Let list be a new empty List.
|
||||
Vector<DurationFormatPart> list;
|
||||
|
||||
// 11. For each Record { [[Type]], [[Value]] } part of parts, do
|
||||
// 10. For each Record { [[Type]], [[Value]] } part of parts, do
|
||||
list.ensure_capacity(parts.size());
|
||||
|
||||
for (auto& part : parts) {
|
||||
|
@ -905,7 +909,7 @@ Vector<DurationFormatPart> partition_duration_format_pattern(VM& vm, DurationFor
|
|||
list.unchecked_append({ .type = part.type, .value = move(part.value), .unit = number_format_unit.as_string() });
|
||||
}
|
||||
|
||||
// 12. Append list to result.
|
||||
// 11. Append list to result.
|
||||
result.append(list);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,6 +66,12 @@ public:
|
|||
Nanoseconds,
|
||||
};
|
||||
|
||||
// 13.5.6.1 Duration Unit Options Records, https://tc39.es/ecma402/#sec-durationformat-unit-options-record
|
||||
struct DurationUnitOptions {
|
||||
ValueStyle style { ValueStyle::Long };
|
||||
Display display { Display::Auto };
|
||||
};
|
||||
|
||||
static constexpr auto relevant_extension_keys()
|
||||
{
|
||||
// 13.2.3 Internal slots, https://tc39.es/ecma402/#sec-Intl.DurationFormat-internal-slots
|
||||
|
@ -91,85 +97,35 @@ public:
|
|||
Style style() const { return m_style; }
|
||||
StringView style_string() const { return style_to_string(m_style); }
|
||||
|
||||
void set_years_style(ValueStyle years_style) { m_years_style = years_style; }
|
||||
ValueStyle years_style() const { return m_years_style; }
|
||||
StringView years_style_string() const { return value_style_to_string(m_years_style); }
|
||||
void set_years_options(DurationUnitOptions years_options) { m_years_options = years_options; }
|
||||
DurationUnitOptions years_options() const { return m_years_options; }
|
||||
|
||||
void set_years_display(Display years_display) { m_years_display = years_display; }
|
||||
Display years_display() const { return m_years_display; }
|
||||
StringView years_display_string() const { return display_to_string(m_years_display); }
|
||||
void set_months_options(DurationUnitOptions months_options) { m_months_options = months_options; }
|
||||
DurationUnitOptions months_options() const { return m_months_options; }
|
||||
|
||||
void set_months_style(ValueStyle months_style) { m_months_style = months_style; }
|
||||
ValueStyle months_style() const { return m_months_style; }
|
||||
StringView months_style_string() const { return value_style_to_string(m_months_style); }
|
||||
void set_weeks_options(DurationUnitOptions weeks_options) { m_weeks_options = weeks_options; }
|
||||
DurationUnitOptions weeks_options() const { return m_weeks_options; }
|
||||
|
||||
void set_months_display(Display months_display) { m_months_display = months_display; }
|
||||
Display months_display() const { return m_months_display; }
|
||||
StringView months_display_string() const { return display_to_string(m_months_display); }
|
||||
void set_days_options(DurationUnitOptions days_options) { m_days_options = days_options; }
|
||||
DurationUnitOptions days_options() const { return m_days_options; }
|
||||
|
||||
void set_weeks_style(ValueStyle weeks_style) { m_weeks_style = weeks_style; }
|
||||
ValueStyle weeks_style() const { return m_weeks_style; }
|
||||
StringView weeks_style_string() const { return value_style_to_string(m_weeks_style); }
|
||||
void set_hours_options(DurationUnitOptions hours_options) { m_hours_options = hours_options; }
|
||||
DurationUnitOptions hours_options() const { return m_hours_options; }
|
||||
|
||||
void set_weeks_display(Display weeks_display) { m_weeks_display = weeks_display; }
|
||||
Display weeks_display() const { return m_weeks_display; }
|
||||
StringView weeks_display_string() const { return display_to_string(m_weeks_display); }
|
||||
void set_minutes_options(DurationUnitOptions minutes_options) { m_minutes_options = minutes_options; }
|
||||
DurationUnitOptions minutes_options() const { return m_minutes_options; }
|
||||
|
||||
void set_days_style(ValueStyle days_style) { m_days_style = days_style; }
|
||||
ValueStyle days_style() const { return m_days_style; }
|
||||
StringView days_style_string() const { return value_style_to_string(m_days_style); }
|
||||
void set_seconds_options(DurationUnitOptions seconds_options) { m_seconds_options = seconds_options; }
|
||||
DurationUnitOptions seconds_options() const { return m_seconds_options; }
|
||||
|
||||
void set_days_display(Display days_display) { m_days_display = days_display; }
|
||||
Display days_display() const { return m_days_display; }
|
||||
StringView days_display_string() const { return display_to_string(m_days_display); }
|
||||
void set_milliseconds_options(DurationUnitOptions milliseconds_options) { m_milliseconds_options = milliseconds_options; }
|
||||
DurationUnitOptions milliseconds_options() const { return m_milliseconds_options; }
|
||||
|
||||
void set_hours_style(ValueStyle hours_style) { m_hours_style = hours_style; }
|
||||
ValueStyle hours_style() const { return m_hours_style; }
|
||||
StringView hours_style_string() const { return value_style_to_string(m_hours_style); }
|
||||
void set_microseconds_options(DurationUnitOptions microseconds_options) { m_microseconds_options = microseconds_options; }
|
||||
DurationUnitOptions microseconds_options() const { return m_microseconds_options; }
|
||||
|
||||
void set_hours_display(Display hours_display) { m_hours_display = hours_display; }
|
||||
Display hours_display() const { return m_hours_display; }
|
||||
StringView hours_display_string() const { return display_to_string(m_hours_display); }
|
||||
|
||||
void set_minutes_style(ValueStyle minutes_style) { m_minutes_style = minutes_style; }
|
||||
ValueStyle minutes_style() const { return m_minutes_style; }
|
||||
StringView minutes_style_string() const { return value_style_to_string(m_minutes_style); }
|
||||
|
||||
void set_minutes_display(Display minutes_display) { m_minutes_display = minutes_display; }
|
||||
Display minutes_display() const { return m_minutes_display; }
|
||||
StringView minutes_display_string() const { return display_to_string(m_minutes_display); }
|
||||
|
||||
void set_seconds_style(ValueStyle seconds_style) { m_seconds_style = seconds_style; }
|
||||
ValueStyle seconds_style() const { return m_seconds_style; }
|
||||
StringView seconds_style_string() const { return value_style_to_string(m_seconds_style); }
|
||||
|
||||
void set_seconds_display(Display seconds_display) { m_seconds_display = seconds_display; }
|
||||
Display seconds_display() const { return m_seconds_display; }
|
||||
StringView seconds_display_string() const { return display_to_string(m_seconds_display); }
|
||||
|
||||
void set_milliseconds_style(ValueStyle milliseconds_style) { m_milliseconds_style = milliseconds_style; }
|
||||
ValueStyle milliseconds_style() const { return m_milliseconds_style; }
|
||||
StringView milliseconds_style_string() const { return value_style_to_string(m_milliseconds_style); }
|
||||
|
||||
void set_milliseconds_display(Display milliseconds_display) { m_milliseconds_display = milliseconds_display; }
|
||||
Display milliseconds_display() const { return m_milliseconds_display; }
|
||||
StringView milliseconds_display_string() const { return display_to_string(m_milliseconds_display); }
|
||||
|
||||
void set_microseconds_style(ValueStyle microseconds_style) { m_microseconds_style = microseconds_style; }
|
||||
ValueStyle microseconds_style() const { return m_microseconds_style; }
|
||||
StringView microseconds_style_string() const { return value_style_to_string(m_microseconds_style); }
|
||||
|
||||
void set_microseconds_display(Display microseconds_display) { m_microseconds_display = microseconds_display; }
|
||||
Display microseconds_display() const { return m_microseconds_display; }
|
||||
StringView microseconds_display_string() const { return display_to_string(m_microseconds_display); }
|
||||
|
||||
void set_nanoseconds_style(ValueStyle nanoseconds_style) { m_nanoseconds_style = nanoseconds_style; }
|
||||
ValueStyle nanoseconds_style() const { return m_nanoseconds_style; }
|
||||
StringView nanoseconds_style_string() const { return value_style_to_string(m_nanoseconds_style); }
|
||||
|
||||
void set_nanoseconds_display(Display nanoseconds_display) { m_nanoseconds_display = nanoseconds_display; }
|
||||
Display nanoseconds_display() const { return m_nanoseconds_display; }
|
||||
StringView nanoseconds_display_string() const { return display_to_string(m_nanoseconds_display); }
|
||||
void set_nanoseconds_options(DurationUnitOptions nanoseconds_options) { m_nanoseconds_options = nanoseconds_options; }
|
||||
DurationUnitOptions nanoseconds_options() const { return m_nanoseconds_options; }
|
||||
|
||||
void set_fractional_digits(Optional<u8> fractional_digits) { m_fractional_digits = move(fractional_digits); }
|
||||
bool has_fractional_digits() const { return m_fractional_digits.has_value(); }
|
||||
|
@ -183,78 +139,62 @@ private:
|
|||
String m_hour_minute_separator; // [[HourMinutesSeparator]]
|
||||
String m_minute_second_separator; // [[MinutesSecondsSeparator]]
|
||||
|
||||
Style m_style { Style::Long }; // [[Style]]
|
||||
ValueStyle m_years_style { ValueStyle::Long }; // [[YearsStyle]]
|
||||
Display m_years_display { Display::Auto }; // [[YearsDisplay]]
|
||||
ValueStyle m_months_style { ValueStyle::Long }; // [[MonthsStyle]]
|
||||
Display m_months_display { Display::Auto }; // [[MonthsDisplay]]
|
||||
ValueStyle m_weeks_style { ValueStyle::Long }; // [[WeeksStyle]]
|
||||
Display m_weeks_display { Display::Auto }; // [[WeeksDisplay]]
|
||||
ValueStyle m_days_style { ValueStyle::Long }; // [[DaysStyle]]
|
||||
Display m_days_display { Display::Auto }; // [[DaysDisplay]]
|
||||
ValueStyle m_hours_style { ValueStyle::Long }; // [[HoursStyle]]
|
||||
Display m_hours_display { Display::Auto }; // [[HoursDisplay]]
|
||||
ValueStyle m_minutes_style { ValueStyle::Long }; // [[MinutesStyle]]
|
||||
Display m_minutes_display { Display::Auto }; // [[MinutesDisplay]]
|
||||
ValueStyle m_seconds_style { ValueStyle::Long }; // [[SecondsStyle]]
|
||||
Display m_seconds_display { Display::Auto }; // [[SecondsDisplay]]
|
||||
ValueStyle m_milliseconds_style { ValueStyle::Long }; // [[MillisecondsStyle]]
|
||||
Display m_milliseconds_display { Display::Auto }; // [[MillisecondsDisplay]]
|
||||
ValueStyle m_microseconds_style { ValueStyle::Long }; // [[MicrosecondsStyle]]
|
||||
Display m_microseconds_display { Display::Auto }; // [[MicrosecondsDisplay]]
|
||||
ValueStyle m_nanoseconds_style { ValueStyle::Long }; // [[NanosecondsStyle]]
|
||||
Display m_nanoseconds_display { Display::Auto }; // [[NanosecondsDisplay]]
|
||||
Optional<u8> m_fractional_digits; // [[FractionalDigits]]
|
||||
Style m_style { Style::Long }; // [[Style]]
|
||||
DurationUnitOptions m_years_options; // [[YearsOptions]]
|
||||
DurationUnitOptions m_months_options; // [[MonthsOptions]]
|
||||
DurationUnitOptions m_weeks_options; // [[WeeksOptions]]
|
||||
DurationUnitOptions m_days_options; // [[DaysOptions]]
|
||||
DurationUnitOptions m_hours_options; // [[HoursOptions]]
|
||||
DurationUnitOptions m_minutes_options; // [[MinutesOptions]]
|
||||
DurationUnitOptions m_seconds_options; // [[SecondsOptions]]
|
||||
DurationUnitOptions m_milliseconds_options; // [[MillisecondsOptions]]
|
||||
DurationUnitOptions m_microseconds_options; // [[MicrosecondsOptions]]
|
||||
DurationUnitOptions m_nanoseconds_options; // [[NanosecondsOptions]]
|
||||
Optional<u8> m_fractional_digits; // [[FractionalDigits]]
|
||||
};
|
||||
|
||||
struct DurationInstanceComponent {
|
||||
double (Temporal::Duration::*value_slot)() const;
|
||||
DurationFormat::ValueStyle (DurationFormat::*get_style_slot)() const;
|
||||
void (DurationFormat::*set_style_slot)(DurationFormat::ValueStyle);
|
||||
DurationFormat::Display (DurationFormat::*get_display_slot)() const;
|
||||
void (DurationFormat::*set_display_slot)(DurationFormat::Display);
|
||||
DurationFormat::DurationUnitOptions (DurationFormat::*get_internal_slot)() const;
|
||||
void (DurationFormat::*set_internal_slot)(DurationFormat::DurationUnitOptions);
|
||||
DurationFormat::Unit unit;
|
||||
ReadonlySpan<StringView> values;
|
||||
ReadonlySpan<StringView> styles;
|
||||
DurationFormat::ValueStyle digital_default;
|
||||
};
|
||||
|
||||
// Table 20: Internal slots and property names of DurationFormat instances relevant to Intl.DurationFormat constructor, https://tc39.es/ecma402/#table-durationformat
|
||||
// Table 23: DurationFormat instance internal slots and properties relevant to PartitionDurationFormatPattern, https://tc39.es/ecma402/#table-partition-duration-format-pattern
|
||||
static constexpr auto date_values = AK::Array { "long"sv, "short"sv, "narrow"sv };
|
||||
static constexpr auto time_values = AK::Array { "long"sv, "short"sv, "narrow"sv, "numeric"sv, "2-digit"sv };
|
||||
static constexpr auto sub_second_values = AK::Array { "long"sv, "short"sv, "narrow"sv, "numeric"sv };
|
||||
// Table 24: DurationFormat instance internal slots and properties relevant to PartitionDurationFormatPattern, https://tc39.es/ecma402/#table-partition-duration-format-pattern
|
||||
static constexpr auto date_styles = AK::Array { "long"sv, "short"sv, "narrow"sv };
|
||||
static constexpr auto time_styles = AK::Array { "long"sv, "short"sv, "narrow"sv, "numeric"sv, "2-digit"sv };
|
||||
static constexpr auto sub_second_styles = AK::Array { "long"sv, "short"sv, "narrow"sv, "numeric"sv };
|
||||
|
||||
static constexpr auto duration_instances_components = to_array<DurationInstanceComponent>({
|
||||
{ &Temporal::Duration::years, &DurationFormat::years_style, &DurationFormat::set_years_style, &DurationFormat::years_display, &DurationFormat::set_years_display, DurationFormat::Unit::Years, date_values, DurationFormat::ValueStyle::Short },
|
||||
{ &Temporal::Duration::months, &DurationFormat::months_style, &DurationFormat::set_months_style, &DurationFormat::months_display, &DurationFormat::set_months_display, DurationFormat::Unit::Months, date_values, DurationFormat::ValueStyle::Short },
|
||||
{ &Temporal::Duration::weeks, &DurationFormat::weeks_style, &DurationFormat::set_weeks_style, &DurationFormat::weeks_display, &DurationFormat::set_weeks_display, DurationFormat::Unit::Weeks, date_values, DurationFormat::ValueStyle::Short },
|
||||
{ &Temporal::Duration::days, &DurationFormat::days_style, &DurationFormat::set_days_style, &DurationFormat::days_display, &DurationFormat::set_days_display, DurationFormat::Unit::Days, date_values, DurationFormat::ValueStyle::Short },
|
||||
{ &Temporal::Duration::hours, &DurationFormat::hours_style, &DurationFormat::set_hours_style, &DurationFormat::hours_display, &DurationFormat::set_hours_display, DurationFormat::Unit::Hours, time_values, DurationFormat::ValueStyle::Numeric },
|
||||
{ &Temporal::Duration::minutes, &DurationFormat::minutes_style, &DurationFormat::set_minutes_style, &DurationFormat::minutes_display, &DurationFormat::set_minutes_display, DurationFormat::Unit::Minutes, time_values, DurationFormat::ValueStyle::Numeric },
|
||||
{ &Temporal::Duration::seconds, &DurationFormat::seconds_style, &DurationFormat::set_seconds_style, &DurationFormat::seconds_display, &DurationFormat::set_seconds_display, DurationFormat::Unit::Seconds, time_values, DurationFormat::ValueStyle::Numeric },
|
||||
{ &Temporal::Duration::milliseconds, &DurationFormat::milliseconds_style, &DurationFormat::set_milliseconds_style, &DurationFormat::milliseconds_display, &DurationFormat::set_milliseconds_display, DurationFormat::Unit::Milliseconds, sub_second_values, DurationFormat::ValueStyle::Numeric },
|
||||
{ &Temporal::Duration::microseconds, &DurationFormat::microseconds_style, &DurationFormat::set_microseconds_style, &DurationFormat::microseconds_display, &DurationFormat::set_microseconds_display, DurationFormat::Unit::Microseconds, sub_second_values, DurationFormat::ValueStyle::Numeric },
|
||||
{ &Temporal::Duration::nanoseconds, &DurationFormat::nanoseconds_style, &DurationFormat::set_nanoseconds_style, &DurationFormat::nanoseconds_display, &DurationFormat::set_nanoseconds_display, DurationFormat::Unit::Nanoseconds, sub_second_values, DurationFormat::ValueStyle::Numeric },
|
||||
{ &Temporal::Duration::years, &DurationFormat::years_options, &DurationFormat::set_years_options, DurationFormat::Unit::Years, date_styles, DurationFormat::ValueStyle::Short },
|
||||
{ &Temporal::Duration::months, &DurationFormat::months_options, &DurationFormat::set_months_options, DurationFormat::Unit::Months, date_styles, DurationFormat::ValueStyle::Short },
|
||||
{ &Temporal::Duration::weeks, &DurationFormat::weeks_options, &DurationFormat::set_weeks_options, DurationFormat::Unit::Weeks, date_styles, DurationFormat::ValueStyle::Short },
|
||||
{ &Temporal::Duration::days, &DurationFormat::days_options, &DurationFormat::set_days_options, DurationFormat::Unit::Days, date_styles, DurationFormat::ValueStyle::Short },
|
||||
{ &Temporal::Duration::hours, &DurationFormat::hours_options, &DurationFormat::set_hours_options, DurationFormat::Unit::Hours, time_styles, DurationFormat::ValueStyle::Numeric },
|
||||
{ &Temporal::Duration::minutes, &DurationFormat::minutes_options, &DurationFormat::set_minutes_options, DurationFormat::Unit::Minutes, time_styles, DurationFormat::ValueStyle::Numeric },
|
||||
{ &Temporal::Duration::seconds, &DurationFormat::seconds_options, &DurationFormat::set_seconds_options, DurationFormat::Unit::Seconds, time_styles, DurationFormat::ValueStyle::Numeric },
|
||||
{ &Temporal::Duration::milliseconds, &DurationFormat::milliseconds_options, &DurationFormat::set_milliseconds_options, DurationFormat::Unit::Milliseconds, sub_second_styles, DurationFormat::ValueStyle::Numeric },
|
||||
{ &Temporal::Duration::microseconds, &DurationFormat::microseconds_options, &DurationFormat::set_microseconds_options, DurationFormat::Unit::Microseconds, sub_second_styles, DurationFormat::ValueStyle::Numeric },
|
||||
{ &Temporal::Duration::nanoseconds, &DurationFormat::nanoseconds_options, &DurationFormat::set_nanoseconds_options, DurationFormat::Unit::Nanoseconds, sub_second_styles, DurationFormat::ValueStyle::Numeric },
|
||||
});
|
||||
|
||||
struct DurationUnitOptions {
|
||||
DurationFormat::ValueStyle style;
|
||||
DurationFormat::Display display;
|
||||
};
|
||||
|
||||
struct DurationFormatPart {
|
||||
StringView type;
|
||||
String value;
|
||||
StringView unit;
|
||||
};
|
||||
|
||||
ThrowCompletionOr<DurationUnitOptions> get_duration_unit_options(VM&, DurationFormat::Unit unit, Object const& options, DurationFormat::Style base_style, ReadonlySpan<StringView> styles_list, DurationFormat::ValueStyle digital_base, Optional<DurationFormat::ValueStyle> previous_style, bool two_digit_hours);
|
||||
ThrowCompletionOr<DurationFormat::DurationUnitOptions> get_duration_unit_options(VM&, DurationFormat::Unit unit, Object const& options, DurationFormat::Style base_style, ReadonlySpan<StringView> styles_list, DurationFormat::ValueStyle digital_base, Optional<DurationFormat::ValueStyle> previous_style, bool two_digit_hours);
|
||||
Crypto::BigFraction compute_fractional_digits(DurationFormat const&, Temporal::Duration const&);
|
||||
bool next_unit_fractional(DurationFormat const&, DurationFormat::Unit unit);
|
||||
Vector<DurationFormatPart> format_numeric_hours(VM&, DurationFormat const&, MathematicalValue const& hours_value, bool sign_displayed);
|
||||
Vector<DurationFormatPart> format_numeric_minutes(VM&, DurationFormat const&, MathematicalValue const& minutes_value, bool hours_displayed, bool sign_displayed);
|
||||
Vector<DurationFormatPart> format_numeric_seconds(VM&, DurationFormat const&, MathematicalValue const& seconds_value, bool minutes_displayed, bool sign_displayed);
|
||||
Vector<DurationFormatPart> format_numeric_units(VM&, DurationFormat const&, Temporal::Duration const&, DurationFormat::Unit first_numeric_unit, bool sign_displayed);
|
||||
bool is_fractional_second_unit_name(DurationFormat::Unit);
|
||||
Vector<DurationFormatPart> list_format_parts(VM&, DurationFormat const&, Vector<Vector<DurationFormatPart>>& partitioned_parts_list);
|
||||
Vector<DurationFormatPart> partition_duration_format_pattern(VM&, DurationFormat const&, Temporal::Duration const&);
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ ThrowCompletionOr<GC::Ref<Object>> DurationFormatConstructor::construct(Function
|
|||
auto locales = vm.argument(0);
|
||||
auto options_value = vm.argument(1);
|
||||
|
||||
// 2. Let durationFormat be ? OrdinaryCreateFromConstructor(NewTarget, "%Intl.DurationFormatPrototype%", « [[InitializedDurationFormat]], [[Locale]], [[NumberingSystem]], [[Style]], [[YearsStyle]], [[YearsDisplay]], [[MonthsStyle]], [[MonthsDisplay]], [[WeeksStyle]], [[WeeksDisplay]], [[DaysStyle]], [[DaysDisplay]], [[HoursStyle]], [[HoursDisplay]], [[MinutesStyle]], [[MinutesDisplay]], [[SecondsStyle]], [[SecondsDisplay]], [[MillisecondsStyle]], [[MillisecondsDisplay]], [[MicrosecondsStyle]], [[MicrosecondsDisplay]], [[NanosecondsStyle]], [[NanosecondsDisplay]], [[HourMinuteSeparator]], [[MinuteSecondSeparator]], [[FractionalDigits]] »).
|
||||
// 2. Let durationFormat be ? OrdinaryCreateFromConstructor(NewTarget, "%Intl.DurationFormatPrototype%", « [[InitializedDurationFormat]], [[Locale]], [[NumberingSystem]], [[Style]], [[YearsOptions]], [[MonthsOptions]], [[WeeksOptions]], [[DaysOptions]], [[HoursOptions]], [[MinutesOptions]], [[SecondsOptions]], [[MillisecondsOptions]], [[MicrosecondsOptions]], [[NanosecondsOptions]], [[HourMinuteSeparator]], [[MinuteSecondSeparator]], [[FractionalDigits]] »).
|
||||
auto duration_format = TRY(ordinary_create_from_constructor<DurationFormat>(vm, new_target, &Intrinsics::intl_duration_format_prototype));
|
||||
|
||||
// 3. Let requestedLocales be ? CanonicalizeLocaleList(locales).
|
||||
|
@ -112,31 +112,25 @@ ThrowCompletionOr<GC::Ref<Object>> DurationFormatConstructor::construct(Function
|
|||
|
||||
// 19. For each row of Table 20, except the header row, in table order, do
|
||||
for (auto const& duration_instances_component : duration_instances_components) {
|
||||
// a. Let styleSlot be the Style Slot value of the current row.
|
||||
auto style_slot = duration_instances_component.set_style_slot;
|
||||
// a. Let slot be the Internal Slot value of the current row.
|
||||
auto slot = duration_instances_component.set_internal_slot;
|
||||
|
||||
// b. Let displaySlot be the Display Slot value of the current row.
|
||||
auto display_slot = duration_instances_component.set_display_slot;
|
||||
|
||||
// c. Let unit be the Unit value of the current row.
|
||||
// b. Let unit be the Unit value of the current row.
|
||||
auto unit = duration_instances_component.unit;
|
||||
|
||||
// d. Let valueList be the Values value of the current row.
|
||||
auto value_list = duration_instances_component.values;
|
||||
// c. Let styles be the Styles value of the current row.
|
||||
auto styles = duration_instances_component.styles;
|
||||
|
||||
// e. Let digitalBase be the Digital Default value of the current row.
|
||||
// d. Let digitalBase be the Digital Default value of the current row.
|
||||
auto digital_base = duration_instances_component.digital_default;
|
||||
|
||||
// f. Let unitOptions be ? GetDurationUnitOptions(unit, options, style, valueList, digitalBase, prevStyle, digitalFormat.[[TwoDigitHours]]).
|
||||
auto unit_options = TRY(get_duration_unit_options(vm, unit, *options, duration_format->style(), value_list, digital_base, previous_style, digital_format.uses_two_digit_hours));
|
||||
// e. Let unitOptions be ? GetDurationUnitOptions(unit, options, style, styles, digitalBase, prevStyle, digitalFormat.[[TwoDigitHours]]).
|
||||
auto unit_options = TRY(get_duration_unit_options(vm, unit, *options, duration_format->style(), styles, digital_base, previous_style, digital_format.uses_two_digit_hours));
|
||||
|
||||
// g. Set the value of the styleSlot slot of durationFormat to unitOptions.[[Style]].
|
||||
(duration_format->*style_slot)(unit_options.style);
|
||||
// f. Set the value of durationFormat's internal slot whose name is slot to unitOptions.
|
||||
(duration_format->*slot)(unit_options);
|
||||
|
||||
// h. Set the value of the displaySlot slot of durationFormat to unitOptions.[[Display]].
|
||||
(duration_format->*display_slot)(unit_options.display);
|
||||
|
||||
// i. If unit is one of "hours", "minutes", "seconds", "milliseconds", or "microseconds", then
|
||||
// g. If unit is one of "hours", "minutes", "seconds", "milliseconds", or "microseconds", then
|
||||
if (first_is_one_of(unit, DurationFormat::Unit::Hours, DurationFormat::Unit::Minutes, DurationFormat::Unit::Seconds, DurationFormat::Unit::Milliseconds, DurationFormat::Unit::Microseconds)) {
|
||||
// i. Set prevStyle to unitOptions.[[Style]].
|
||||
previous_style = unit_options.style;
|
||||
|
|
|
@ -50,49 +50,57 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::resolved_options)
|
|||
auto options = Object::create(realm, realm.intrinsics().object_prototype());
|
||||
|
||||
// 4. For each row of Table 21, except the header row, in table order, do
|
||||
auto create_option = [&](PropertyKey const& property, StringView value) {
|
||||
auto create_option = [&]<typename T>(PropertyKey const& property, Optional<PropertyKey const&> display_property, T value) {
|
||||
// a. Let p be the Property value of the current row.
|
||||
// b. Let v be the value of df's internal slot whose name is the Internal Slot value of the current row.
|
||||
|
||||
// c. If p is "fractionalDigits", then
|
||||
// i. If v is not undefined, perform ! CreateDataPropertyOrThrow(options, p, 𝔽(v)).
|
||||
// NOTE: This case is handled separately below.
|
||||
// c. If v is not undefined, then
|
||||
// i. If there is a Conversion value in the current row, let conversion be that value; else let conversion be empty.
|
||||
// ii. If conversion is number, then
|
||||
// 1. Set v to 𝔽(v).
|
||||
// NOTE: This case is for fractionalDigits and is handled separately below.
|
||||
|
||||
// d. Else,
|
||||
// i. Assert: v is not undefined.
|
||||
// ii. If v is "fractional", then
|
||||
if (value == "fractional"sv) {
|
||||
// 1. Assert: The Internal Slot value of the current row is [[MillisecondsStyle]], [[MicrosecondsStyle]], or [[NanosecondsStyle]] .
|
||||
// 2. Set v to "numeric".
|
||||
value = "numeric"sv;
|
||||
// iii. Else if conversion is not empty, then
|
||||
if constexpr (IsSame<T, DurationFormat::DurationUnitOptions>) {
|
||||
// 1. Assert: conversion is STYLE+DISPLAY and v is a Duration Unit Options Record.
|
||||
// 2. NOTE: v.[[Style]] will be represented with a property named p (a plural Temporal unit), then v.[[Display]] will be represented with a property whose name suffixes p with "Display".
|
||||
VERIFY(display_property.has_value());
|
||||
|
||||
// 3. Let style be v.[[Style]].
|
||||
auto style = value.style;
|
||||
|
||||
// 4. If style is "fractional", then
|
||||
if (style == DurationFormat::ValueStyle::Fractional) {
|
||||
// a. Assert: IsFractionalSecondUnitName(p) is true.
|
||||
// b. Set style to "numeric".
|
||||
style = DurationFormat::ValueStyle::Numeric;
|
||||
}
|
||||
|
||||
// 5. Perform ! CreateDataPropertyOrThrow(options, p, style).
|
||||
MUST(options->create_data_property_or_throw(property, PrimitiveString::create(vm, DurationFormat::value_style_to_string(style))));
|
||||
|
||||
// 6. Set p to the string-concatenation of p and "Display".
|
||||
// 7. Set v to v.[[Display]].
|
||||
MUST(options->create_data_property_or_throw(*display_property, PrimitiveString::create(vm, DurationFormat::display_to_string(value.display))));
|
||||
} else {
|
||||
// iv. Perform ! CreateDataPropertyOrThrow(options, p, v).
|
||||
MUST(options->create_data_property_or_throw(property, PrimitiveString::create(vm, move(value))));
|
||||
}
|
||||
// iii. Perform ! CreateDataPropertyOrThrow(options, p, v).
|
||||
MUST(options->create_data_property_or_throw(property, PrimitiveString::create(vm, value)));
|
||||
};
|
||||
|
||||
create_option(vm.names.locale, duration_format->locale());
|
||||
create_option(vm.names.numberingSystem, duration_format->numbering_system());
|
||||
create_option(vm.names.style, duration_format->style_string());
|
||||
create_option(vm.names.years, duration_format->years_style_string());
|
||||
create_option(vm.names.yearsDisplay, duration_format->years_display_string());
|
||||
create_option(vm.names.months, duration_format->months_style_string());
|
||||
create_option(vm.names.monthsDisplay, duration_format->months_display_string());
|
||||
create_option(vm.names.weeks, duration_format->weeks_style_string());
|
||||
create_option(vm.names.weeksDisplay, duration_format->weeks_display_string());
|
||||
create_option(vm.names.days, duration_format->days_style_string());
|
||||
create_option(vm.names.daysDisplay, duration_format->days_display_string());
|
||||
create_option(vm.names.hours, duration_format->hours_style_string());
|
||||
create_option(vm.names.hoursDisplay, duration_format->hours_display_string());
|
||||
create_option(vm.names.minutes, duration_format->minutes_style_string());
|
||||
create_option(vm.names.minutesDisplay, duration_format->minutes_display_string());
|
||||
create_option(vm.names.seconds, duration_format->seconds_style_string());
|
||||
create_option(vm.names.secondsDisplay, duration_format->seconds_display_string());
|
||||
create_option(vm.names.milliseconds, duration_format->milliseconds_style_string());
|
||||
create_option(vm.names.millisecondsDisplay, duration_format->milliseconds_display_string());
|
||||
create_option(vm.names.microseconds, duration_format->microseconds_style_string());
|
||||
create_option(vm.names.microsecondsDisplay, duration_format->microseconds_display_string());
|
||||
create_option(vm.names.nanoseconds, duration_format->nanoseconds_style_string());
|
||||
create_option(vm.names.nanosecondsDisplay, duration_format->nanoseconds_display_string());
|
||||
create_option(vm.names.locale, {}, duration_format->locale());
|
||||
create_option(vm.names.numberingSystem, {}, duration_format->numbering_system());
|
||||
create_option(vm.names.style, {}, duration_format->style_string());
|
||||
create_option(vm.names.years, vm.names.yearsDisplay, duration_format->years_options());
|
||||
create_option(vm.names.months, vm.names.monthsDisplay, duration_format->months_options());
|
||||
create_option(vm.names.weeks, vm.names.weeksDisplay, duration_format->weeks_options());
|
||||
create_option(vm.names.days, vm.names.daysDisplay, duration_format->days_options());
|
||||
create_option(vm.names.hours, vm.names.hoursDisplay, duration_format->hours_options());
|
||||
create_option(vm.names.minutes, vm.names.minutesDisplay, duration_format->minutes_options());
|
||||
create_option(vm.names.seconds, vm.names.secondsDisplay, duration_format->seconds_options());
|
||||
create_option(vm.names.milliseconds, vm.names.millisecondsDisplay, duration_format->milliseconds_options());
|
||||
create_option(vm.names.microseconds, vm.names.microsecondsDisplay, duration_format->microseconds_options());
|
||||
create_option(vm.names.nanoseconds, vm.names.nanosecondsDisplay, duration_format->nanoseconds_options());
|
||||
|
||||
if (duration_format->has_fractional_digits())
|
||||
MUST(options->create_data_property_or_throw(vm.names.fractionalDigits, Value(duration_format->fractional_digits())));
|
||||
|
|
|
@ -47,7 +47,7 @@ JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::resolved_options)
|
|||
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
|
||||
auto options = Object::create(realm, realm.intrinsics().object_prototype());
|
||||
|
||||
// 4. For each row of Table 24, except the header row, in table order, do
|
||||
// 4. For each row of Table 25, except the header row, in table order, do
|
||||
// a. Let p be the Property value of the current row.
|
||||
// b. Let v be the value of lf's internal slot whose name is the Internal Slot value of the current row.
|
||||
// c. Assert: v is not undefined.
|
||||
|
|
|
@ -53,7 +53,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::resolved_options)
|
|||
// 4. Let options be OrdinaryObjectCreate(%Object.prototype%).
|
||||
auto options = Object::create(realm, realm.intrinsics().object_prototype());
|
||||
|
||||
// 5. For each row of Table 25, except the header row, in table order, do
|
||||
// 5. For each row of Table 26, except the header row, in table order, do
|
||||
// a. Let p be the Property value of the current row.
|
||||
// b. Let v be the value of nf's internal slot whose name is the Internal Slot value of the current row.
|
||||
// c. If v is not undefined, then
|
||||
|
|
|
@ -56,7 +56,7 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::resolved_options)
|
|||
return PrimitiveString::create(vm, Unicode::plural_category_to_string(category));
|
||||
});
|
||||
|
||||
// 5. For each row of Table 29, except the header row, in table order, do
|
||||
// 5. For each row of Table 30, except the header row, in table order, do
|
||||
// a. Let p be the Property value of the current row.
|
||||
// b. If p is "pluralCategories", then
|
||||
// i. Let v be CreateArrayFromList(pluralCategories).
|
||||
|
|
|
@ -46,7 +46,7 @@ JS_DEFINE_NATIVE_FUNCTION(RelativeTimeFormatPrototype::resolved_options)
|
|||
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
|
||||
auto options = Object::create(realm, realm.intrinsics().object_prototype());
|
||||
|
||||
// 4. For each row of Table 30, except the header row, in table order, do
|
||||
// 4. For each row of Table 31, except the header row, in table order, do
|
||||
// a. Let p be the Property value of the current row.
|
||||
// b. Let v be the value of relativeTimeFormat's internal slot whose name is the Internal Slot value of the current row.
|
||||
// c. Assert: v is not undefined.
|
||||
|
|
|
@ -45,7 +45,7 @@ JS_DEFINE_NATIVE_FUNCTION(SegmenterPrototype::resolved_options)
|
|||
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
|
||||
auto options = Object::create(realm, realm.intrinsics().object_prototype());
|
||||
|
||||
// 4. For each row of Table 31, except the header row, in table order, do
|
||||
// 4. For each row of Table 32, except the header row, in table order, do
|
||||
// a. Let p be the Property value of the current row.
|
||||
// b. Let v be the value of segmenter's internal slot whose name is the Internal Slot value of the current row.
|
||||
// c. Assert: v is not undefined.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue