diff options
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Intl/DurationFormatPrototype.cpp | 26 |
2 files changed, 14 insertions, 18 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp index 076cc5e786..eb9a667207 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp @@ -173,7 +173,11 @@ ThrowCompletionOr<Temporal::DurationRecord> to_duration_record(VM& vm, Value inp if (!any) return vm.throw_completion<TypeError>(ErrorType::TemporalInvalidDurationLikeObject); - // 6. Return result. + // 6. If IsValidDurationRecord(result) is false, throw a RangeError exception. + if (!is_valid_duration_record(result)) + return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidDurationLikeObject); + + // 7. Return result. return result; } diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatPrototype.cpp index d3435c8958..127d9db050 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatPrototype.cpp @@ -42,23 +42,19 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format) // 3. Let record be ? ToDurationRecord(duration). auto record = TRY(to_duration_record(vm, vm.argument(0))); - // 4. If IsValidDurationRecord(record) is false, throw a RangeError exception. - if (!is_valid_duration_record(record)) - return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidDurationLikeObject); - - // 5. Let parts be PartitionDurationFormatPattern(df, record). + // 4. Let parts be PartitionDurationFormatPattern(df, record). auto parts = partition_duration_format_pattern(vm, *duration_format, record); - // 6. Let result be a new empty String. + // 5. Let result be a new empty String. StringBuilder result; - // 7. For each Record { [[Type]], [[Value]] } part in parts, do + // 6. 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); } - // 8. Return result. + // 7. Return result. return PrimitiveString::create(vm, result.build()); } @@ -74,18 +70,14 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format_to_parts) // 3. Let record be ? ToDurationRecord(duration). auto record = TRY(to_duration_record(vm, vm.argument(0))); - // 4. If IsValidDurationRecord(record) is false, throw a RangeError exception. - if (!is_valid_duration_record(record)) - return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidDurationLikeObject); - - // 5. Let parts be PartitionDurationFormatPattern(df, record). + // 4. Let parts be PartitionDurationFormatPattern(df, record). auto parts = partition_duration_format_pattern(vm, *duration_format, record); - // 6. Let result be ! ArrayCreate(0). + // 5. Let result be ! ArrayCreate(0). auto result = MUST(Array::create(realm, 0)); - // 7. Let n be 0. - // 8. For each { [[Type]], [[Value]] } part in parts, do + // 6. Let n be 0. + // 7. For each { [[Type]], [[Value]] } part in parts, do for (size_t n = 0; n < parts.size(); ++n) { auto const& part = parts[n]; @@ -104,7 +96,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format_to_parts) // e. Increment n by 1. } - // 9. Return result. + // 8. Return result. return result; } |