diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-08-30 11:24:17 -0400 |
---|---|---|
committer | Tim Flynn <trflynn89@pm.me> | 2022-08-30 14:26:11 -0400 |
commit | cab1cce522e2e795135b8e143a4653276c11f4d7 (patch) | |
tree | 87c79d48fcd7f41388132c9e797e5c437e906fcc /Userland/Libraries | |
parent | a86b840c64bf0416e9f756b293e88dc05e8c8d45 (diff) | |
download | serenity-cab1cce522e2e795135b8e143a4653276c11f4d7.zip |
LibJS: Update DurationFormat AO text to align with ECMA-402 and Temporal
These are editorial changes in the Intl.DurationFormat proposal. See:
https://github.com/tc39/proposal-intl-duration-format/commit/71b291b
https://github.com/tc39/proposal-intl-duration-format/commit/d0cc6fa
https://github.com/tc39/proposal-intl-duration-format/commit/d4b35bb
Diffstat (limited to 'Userland/Libraries')
3 files changed, 21 insertions, 22 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp index 120b860aca..b76cc61beb 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp @@ -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) diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatConstructor.cpp index 5419e3b7ae..405d87bc41 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatConstructor.cpp @@ -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. diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatPrototype.cpp index 2acf895745..32eab7fc65 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatPrototype.cpp @@ -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()); |