diff options
author | Linus Groh <mail@linusgroh.de> | 2021-09-16 14:00:39 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-09-16 22:34:24 +0100 |
commit | 8dd45a1ba2ba3d4c112dd92517030e88b45be872 (patch) | |
tree | ae6aae2af027e4113497a8e50aac7d08c1547f7f /Userland/Libraries/LibJS | |
parent | 448a3642102620470a677719c08bd8ef28636c76 (diff) | |
download | serenity-8dd45a1ba2ba3d4c112dd92517030e88b45be872.zip |
LibJS: Convert validate_temporal_unit_range() to ThrowCompletionOr
Diffstat (limited to 'Userland/Libraries/LibJS')
3 files changed, 15 insertions, 26 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp index a44b732c54..e9d6370b12 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp @@ -447,64 +447,57 @@ ThrowCompletionOr<Optional<String>> to_smallest_temporal_unit(GlobalObject& glob } // 13.22 ValidateTemporalUnitRange ( largestUnit, smallestUnit ), https://tc39.es/proposal-temporal/#sec-temporal-validatetemporalunitrange -void validate_temporal_unit_range(GlobalObject& global_object, StringView largest_unit, StringView smallest_unit) +ThrowCompletionOr<void> validate_temporal_unit_range(GlobalObject& global_object, StringView largest_unit, StringView smallest_unit) { auto& vm = global_object.vm(); // 1. If smallestUnit is "year" and largestUnit is not "year", then if (smallest_unit == "year"sv && largest_unit != "year"sv) { // a. Throw a RangeError exception. - vm.throw_exception<RangeError>(global_object, ErrorType::TemporalInvalidUnitRange, smallest_unit, largest_unit); - return; + return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidUnitRange, smallest_unit, largest_unit); } // 2. If smallestUnit is "month" and largestUnit is not "year" or "month", then if (smallest_unit == "month"sv && !largest_unit.is_one_of("year"sv, "month"sv)) { // a. Throw a RangeError exception. - vm.throw_exception<RangeError>(global_object, ErrorType::TemporalInvalidUnitRange, smallest_unit, largest_unit); - return; + return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidUnitRange, smallest_unit, largest_unit); } // 3. If smallestUnit is "week" and largestUnit is not one of "year", "month", or "week", then if (smallest_unit == "week"sv && !largest_unit.is_one_of("year"sv, "month"sv, "week"sv)) { // a. Throw a RangeError exception. - vm.throw_exception<RangeError>(global_object, ErrorType::TemporalInvalidUnitRange, smallest_unit, largest_unit); - return; + return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidUnitRange, smallest_unit, largest_unit); } // 4. If smallestUnit is "day" and largestUnit is not one of "year", "month", "week", or "day", then if (smallest_unit == "day"sv && !largest_unit.is_one_of("year"sv, "month"sv, "week"sv, "day"sv)) { // a. Throw a RangeError exception. - vm.throw_exception<RangeError>(global_object, ErrorType::TemporalInvalidUnitRange, smallest_unit, largest_unit); - return; + return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidUnitRange, smallest_unit, largest_unit); } // 5. If smallestUnit is "hour" and largestUnit is not one of "year", "month", "week", "day", or "hour", then if (smallest_unit == "hour"sv && !largest_unit.is_one_of("year"sv, "month"sv, "week"sv, "day"sv, "hour"sv)) { // a. Throw a RangeError exception. - vm.throw_exception<RangeError>(global_object, ErrorType::TemporalInvalidUnitRange, smallest_unit, largest_unit); - return; + return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidUnitRange, smallest_unit, largest_unit); } // 6. If smallestUnit is "minute" and largestUnit is "second", "millisecond", "microsecond", or "nanosecond", then if (smallest_unit == "minute"sv && largest_unit.is_one_of("second"sv, "millisecond"sv, "microsecond"sv, "nanosecond"sv)) { // a. Throw a RangeError exception. - vm.throw_exception<RangeError>(global_object, ErrorType::TemporalInvalidUnitRange, smallest_unit, largest_unit); - return; + return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidUnitRange, smallest_unit, largest_unit); } // 7. If smallestUnit is "second" and largestUnit is "millisecond", "microsecond", or "nanosecond", then if (smallest_unit == "second"sv && largest_unit.is_one_of("millisecond"sv, "microsecond"sv, "nanosecond"sv)) { // a. Throw a RangeError exception. - vm.throw_exception<RangeError>(global_object, ErrorType::TemporalInvalidUnitRange, smallest_unit, largest_unit); - return; + return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidUnitRange, smallest_unit, largest_unit); } // 8. If smallestUnit is "millisecond" and largestUnit is "microsecond" or "nanosecond", then if (smallest_unit == "millisecond"sv && largest_unit.is_one_of("microsecond"sv, "nanosecond"sv)) { // a. Throw a RangeError exception. - vm.throw_exception<RangeError>(global_object, ErrorType::TemporalInvalidUnitRange, smallest_unit, largest_unit); - return; + return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidUnitRange, smallest_unit, largest_unit); } // 9. If smallestUnit is "microsecond" and largestUnit is "nanosecond", then if (smallest_unit == "microsecond"sv && largest_unit == "nanosecond"sv) { // a. Throw a RangeError exception. - vm.throw_exception<RangeError>(global_object, ErrorType::TemporalInvalidUnitRange, smallest_unit, largest_unit); - return; + return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidUnitRange, smallest_unit, largest_unit); } + + return {}; } // 13.23 LargerOfTwoTemporalUnits ( u1, u2 ), https://tc39.es/proposal-temporal/#sec-temporal-largeroftwotemporalunits diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h index 36f9f2ffec..e753d9a828 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h +++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h @@ -96,7 +96,7 @@ ThrowCompletionOr<u64> to_temporal_rounding_increment(GlobalObject&, Object cons ThrowCompletionOr<SecondsStringPrecision> to_seconds_string_precision(GlobalObject&, Object const& normalized_options); ThrowCompletionOr<String> to_largest_temporal_unit(GlobalObject&, Object const& normalized_options, Vector<StringView> const& disallowed_units, String const& fallback, Optional<String> auto_value); ThrowCompletionOr<Optional<String>> to_smallest_temporal_unit(GlobalObject&, Object const& normalized_options, Vector<StringView> const& disallowed_units, Optional<String> fallback); -void validate_temporal_unit_range(GlobalObject&, StringView largest_unit, StringView smallest_unit); +ThrowCompletionOr<void> validate_temporal_unit_range(GlobalObject&, StringView largest_unit, StringView smallest_unit); String larger_of_two_temporal_units(StringView, StringView); Optional<u16> maximum_temporal_duration_rounding_increment(StringView unit); void reject_temporal_calendar_type(GlobalObject&, Object&); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp index 9c9fb377a7..a8eb96ca26 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp @@ -202,9 +202,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::until) auto largest_unit = TRY_OR_DISCARD(to_largest_temporal_unit(global_object, *options, { "year"sv, "month"sv, "week"sv, "day"sv }, "auto"sv, move(default_largest_unit))); // 8. Perform ? ValidateTemporalUnitRange(largestUnit, smallestUnit). - validate_temporal_unit_range(global_object, largest_unit, *smallest_unit); - if (vm.exception()) - return {}; + TRY_OR_DISCARD(validate_temporal_unit_range(global_object, largest_unit, *smallest_unit)); // 9. Let roundingMode be ? ToTemporalRoundingMode(options, "trunc"). auto rounding_mode = TRY_OR_DISCARD(to_temporal_rounding_mode(global_object, *options, "trunc"sv)); @@ -252,9 +250,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::since) auto largest_unit = TRY_OR_DISCARD(to_largest_temporal_unit(global_object, *options, { "year"sv, "month"sv, "week"sv, "day"sv }, "auto"sv, move(default_largest_unit))); // 8. Perform ? ValidateTemporalUnitRange(largestUnit, smallestUnit). - validate_temporal_unit_range(global_object, largest_unit, *smallest_unit); - if (vm.exception()) - return {}; + TRY_OR_DISCARD(validate_temporal_unit_range(global_object, largest_unit, *smallest_unit)); // 9. Let roundingMode be ? ToTemporalRoundingMode(options, "trunc"). auto rounding_mode = TRY_OR_DISCARD(to_temporal_rounding_mode(global_object, *options, "trunc"sv)); |