diff options
Diffstat (limited to 'Userland')
3 files changed, 20 insertions, 18 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp index 1683d7f237..cb352b007a 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp @@ -661,7 +661,7 @@ ThrowCompletionOr<Value> get_option(GlobalObject& global_object, Object const& o } // 9.2.14 DefaultNumberOption ( value, minimum, maximum, fallback ), https://tc39.es/ecma402/#sec-defaultnumberoption -Optional<int> default_number_option(GlobalObject& global_object, Value value, int minimum, int maximum, Optional<int> fallback) +ThrowCompletionOr<Optional<int>> default_number_option(GlobalObject& global_object, Value value, int minimum, int maximum, Optional<int> fallback) { auto& vm = global_object.vm(); @@ -671,17 +671,15 @@ Optional<int> default_number_option(GlobalObject& global_object, Value value, in // 2. Let value be ? ToNumber(value). value = value.to_number(global_object); - if (vm.exception()) - return {}; + if (auto* exception = vm.exception()) + return throw_completion(exception->value()); // 3. If value is NaN or less than minimum or greater than maximum, throw a RangeError exception. - if (value.is_nan() || (value.as_double() < minimum) || (value.as_double() > maximum)) { - vm.throw_exception<RangeError>(global_object, ErrorType::IntlNumberIsNaNOrOutOfRange, value, minimum, maximum); - return {}; - } + if (value.is_nan() || (value.as_double() < minimum) || (value.as_double() > maximum)) + return vm.throw_completion<RangeError>(global_object, ErrorType::IntlNumberIsNaNOrOutOfRange, value, minimum, maximum); // 4. Return floor(value). - return floor(value.as_double()); + return { floor(value.as_double()) }; } // 9.2.15 GetNumberOption ( options, property, minimum, maximum, fallback ), https://tc39.es/ecma402/#sec-getnumberoption @@ -696,7 +694,7 @@ Optional<int> get_number_option(GlobalObject& global_object, Object const& optio return {}; // 3. Return ? DefaultNumberOption(value, minimum, maximum, fallback). - return default_number_option(global_object, value, minimum, maximum, fallback); + return TRY_OR_DISCARD(default_number_option(global_object, value, minimum, maximum, move(fallback))); } // 9.2.16 PartitionPattern ( pattern ), https://tc39.es/ecma402/#sec-partitionpattern diff --git a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.h index fd5b949d4c..5bc3bc3904 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.h +++ b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.h @@ -47,7 +47,7 @@ Vector<String> best_fit_supported_locales(Vector<String> const& requested_locale ThrowCompletionOr<Array*> supported_locales(GlobalObject&, Vector<String> const& requested_locales, Value options); ThrowCompletionOr<Object*> coerce_options_to_object(GlobalObject& global_object, Value options); ThrowCompletionOr<Value> get_option(GlobalObject& global_object, Object const& options, PropertyName const& property, Value::Type type, Vector<StringView> const& values, Fallback fallback); -Optional<int> default_number_option(GlobalObject& global_object, Value value, int minimum, int maximum, Optional<int> fallback); +ThrowCompletionOr<Optional<int>> default_number_option(GlobalObject& global_object, Value value, int minimum, int maximum, Optional<int> fallback); Optional<int> get_number_option(GlobalObject& global_object, Object const& options, PropertyName const& property, int minimum, int maximum, Optional<int> fallback); Vector<PatternPartition> partition_pattern(StringView pattern); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp index a36e360bbc..cd498bb62b 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp @@ -282,14 +282,16 @@ void set_number_format_digit_options(GlobalObject& global_object, NumberFormat& intl_object.set_rounding_type(NumberFormat::RoundingType::SignificantDigits); // b. Let mnsd be ? DefaultNumberOption(mnsd, 1, 21, 1). - auto min_digits = default_number_option(global_object, min_significant_digits, 1, 21, 1); - if (vm.exception()) + auto min_digits_or_error = default_number_option(global_object, min_significant_digits, 1, 21, 1); + if (min_digits_or_error.is_error()) return; + auto min_digits = min_digits_or_error.release_value(); // c. Let mxsd be ? DefaultNumberOption(mxsd, mnsd, 21, 21). - auto max_digits = default_number_option(global_object, max_significant_digits, *min_digits, 21, 21); - if (vm.exception()) + auto max_digits_or_error = default_number_option(global_object, max_significant_digits, *min_digits, 21, 21); + if (max_digits_or_error.is_error()) return; + auto max_digits = max_digits_or_error.release_value(); // d. Set intlObj.[[MinimumSignificantDigits]] to mnsd. intl_object.set_min_significant_digits(*min_digits); @@ -303,14 +305,16 @@ void set_number_format_digit_options(GlobalObject& global_object, NumberFormat& intl_object.set_rounding_type(NumberFormat::RoundingType::FractionDigits); // b. Let mnfd be ? DefaultNumberOption(mnfd, 0, 20, undefined). - auto min_digits = default_number_option(global_object, min_fraction_digits, 0, 20, {}); - if (vm.exception()) + auto min_digits_or_error = default_number_option(global_object, min_fraction_digits, 0, 20, {}); + if (min_digits_or_error.is_error()) return; + auto min_digits = min_digits_or_error.release_value(); // c. Let mxfd be ? DefaultNumberOption(mxfd, 0, 20, undefined). - auto max_digits = default_number_option(global_object, max_fraction_digits, 0, 20, {}); - if (vm.exception()) + auto max_digits_or_error = default_number_option(global_object, max_fraction_digits, 0, 20, {}); + if (max_digits_or_error.is_error()) return; + auto max_digits = max_digits_or_error.release_value(); // d. If mnfd is undefined, set mnfd to min(mnfdDefault, mxfd). if (!min_digits.has_value()) { |