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

LibJS: Update DurationFormat AO text to align with ECMA-402 and Temporal

These are editorial changes in the Intl.DurationFormat proposal. See:
71b291b
d0cc6fa
d4b35bb
This commit is contained in:
Timothy Flynn 2022-08-30 11:24:17 -04:00 committed by Tim Flynn
parent a86b840c64
commit cab1cce522
3 changed files with 21 additions and 22 deletions

View file

@ -145,7 +145,7 @@ ThrowCompletionOr<Temporal::DurationRecord> to_duration_record(VM& vm, Value inp
// 3. Let any be false.
auto any = false;
// 4. For each row in Table 1, except the header row, in table order, do
// 4. For each row of Table 1, except the header row, in table order, do
for (auto const& duration_instances_component : duration_instances_components) {
// a. Let valueSlot be the Value Slot value of the current row.
auto value_slot = duration_instances_component.value_slot;
@ -180,12 +180,12 @@ ThrowCompletionOr<Temporal::DurationRecord> to_duration_record(VM& vm, Value inp
// 1.1.4 DurationRecordSign ( record ), https://tc39.es/proposal-intl-duration-format/#sec-durationrecordsign
i8 duration_record_sign(Temporal::DurationRecord const& record)
{
// 1. For each row in Table 1, except the header row, in table order, do
// 1. For each row of Table 1, except the header row, in table order, do
for (auto const& duration_instances_component : duration_instances_components) {
// a. Let valueSlot be the Value Slot value.
// a. Let valueSlot be the Value Slot value of the current row.
auto value_slot = duration_instances_component.value_slot;
// b. Let v be value of the valueSlot slot of record.
// b. Let v be record.[[<valueSlot>]].
auto value = record.*value_slot;
// c. If v < 0, return -1.
@ -207,17 +207,16 @@ bool is_valid_duration_record(Temporal::DurationRecord const& record)
// 1. Let sign be ! DurationRecordSign(record).
auto sign = duration_record_sign(record);
// 2. For each row in Table 1, except the header row, in table order, do
// 2. For each row of Table 1, except the header row, in table order, do
for (auto const& duration_instances_component : duration_instances_components) {
// a. Let valueSlot be the Value Slot value.
// a. Let valueSlot be the Value Slot value of the current row.
auto value_slot = duration_instances_component.value_slot;
// b. Let v be value of the valueSlot slot of record.
// b. Let v be record.[[<valueSlot>]].
auto value = record.*value_slot;
// c. If 𝔽(v) is not finite, return false.
if (!isfinite(value))
return false;
// c. Assert: 𝔽(v) is finite.
VERIFY(isfinite(value));
// d. If v < 0 and sign > 0, return false.
if (value < 0 && sign > 0)

View file

@ -101,12 +101,12 @@ ThrowCompletionOr<Object*> DurationFormatConstructor::construct(FunctionObject&
// 16. Let prevStyle be the empty String.
auto previous_style = String::empty();
// 17. For each row in Table 1, except the header row, in table order, do
// 17. For each row of Table 1, 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.
// a. Let styleSlot be the Style Slot value of the current row.
auto style_slot = duration_instances_component.set_style_slot;
// b. Let displaySlot be the Display Slot value.
// 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.

View file

@ -46,14 +46,14 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format)
if (!is_valid_duration_record(record))
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidDurationLikeObject);
// 5. Let formatted be ! PartitionDurationFormatPattern(df, record).
auto formatted = partition_duration_format_pattern(vm, *duration_format, record);
// 5. Let parts be ! PartitionDurationFormatPattern(df, record).
auto parts = partition_duration_format_pattern(vm, *duration_format, record);
// 6. Let result be a new empty String.
StringBuilder result;
// 7. For each element part in formatted, in List order, do
for (auto const& part : formatted) {
// 7. For each Record { [[Type]], [[Value]] } part in parts, do
for (auto const& part : parts) {
// a. Set result to the string-concatenation of result and part.[[Value]].
result.append(part.value);
}
@ -78,16 +78,16 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format_to_parts)
if (!is_valid_duration_record(record))
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidDurationLikeObject);
// 5. Let formatted be ! PartitionDurationFormatPattern(df, record).
auto formatted = partition_duration_format_pattern(vm, *duration_format, record);
// 5. Let parts be ! PartitionDurationFormatPattern(df, record).
auto parts = partition_duration_format_pattern(vm, *duration_format, record);
// 6. Let result be ! ArrayCreate(0).
auto* result = MUST(Array::create(realm, 0));
// 7. Let n be 0.
// 8. For each element part in formatted, in List order, do
for (size_t n = 0; n < formatted.size(); ++n) {
auto const& part = formatted[n];
// 8. For each { [[Type]], [[Value]] } part in parts, do
for (size_t n = 0; n < parts.size(); ++n) {
auto const& part = parts[n];
// a. Let obj be ! OrdinaryObjectCreate(%ObjectPrototype%).
auto* object = Object::create(realm, realm.intrinsics().object_prototype());