diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-12-14 15:04:59 -0500 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-12-15 09:40:09 +0000 |
commit | 85f079dc6b0e448bb4433237767a92d8ed976877 (patch) | |
tree | 043b9e1feb8d86b775812016b5ceb2df0a22bee9 /Userland/Libraries/LibJS/Runtime/Intl | |
parent | 0086a3acdbe2af06bae4c45523b20c7bbb19ab90 (diff) | |
download | serenity-85f079dc6b0e448bb4433237767a92d8ed976877.zip |
LibJS: Move IsValidDurationRecord check to ToDurationRecord
This is an editorial change in the Intl.DurationFormat proposal. See:
https://github.com/tc39/proposal-intl-duration-format/commit/fb21723
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/Intl')
-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; } |