mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 18:20:43 +09:00
LibJS: Convert coerce_options_to_object() to ThrowCompletionOr
This commit is contained in:
parent
d0e5fc4576
commit
b9c7a629f8
Notes:
sideshowbarker
2024-07-19 01:59:31 +09:00
Author: https://github.com/IdanHo
Commit: b9c7a629f8
Pull-request: https://github.com/SerenityOS/serenity/pull/10121
Reviewed-by: https://github.com/linusg ✅
4 changed files with 11 additions and 12 deletions
|
@ -573,9 +573,7 @@ ThrowCompletionOr<Array*> supported_locales(GlobalObject& global_object, Vector<
|
|||
auto& vm = global_object.vm();
|
||||
|
||||
// 1. Set options to ? CoerceOptionsToObject(options).
|
||||
auto* options_object = coerce_options_to_object(global_object, options);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
auto* options_object = TRY(coerce_options_to_object(global_object, options));
|
||||
|
||||
// 2. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
|
||||
auto matcher = TRY(get_option(global_object, *options_object, vm.names.localeMatcher, Value::Type::String, { "lookup"sv, "best fit"sv }, "best fit"sv));
|
||||
|
@ -598,8 +596,10 @@ ThrowCompletionOr<Array*> supported_locales(GlobalObject& global_object, Vector<
|
|||
}
|
||||
|
||||
// 9.2.12 CoerceOptionsToObject ( options ), https://tc39.es/ecma402/#sec-coerceoptionstoobject
|
||||
Object* coerce_options_to_object(GlobalObject& global_object, Value options)
|
||||
ThrowCompletionOr<Object*> coerce_options_to_object(GlobalObject& global_object, Value options)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
// 1. If options is undefined, then
|
||||
if (options.is_undefined()) {
|
||||
// a. Return ! OrdinaryObjectCreate(null).
|
||||
|
@ -607,7 +607,10 @@ Object* coerce_options_to_object(GlobalObject& global_object, Value options)
|
|||
}
|
||||
|
||||
// 2. Return ? ToObject(options).
|
||||
return options.to_object(global_object);
|
||||
auto result = options.to_object(global_object);
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
return result;
|
||||
}
|
||||
|
||||
// 9.2.13 GetOption ( options, property, type, values, fallback ), https://tc39.es/ecma402/#sec-getoption
|
||||
|
|
|
@ -45,7 +45,7 @@ LocaleResult resolve_locale(Vector<String> const& requested_locales, LocaleOptio
|
|||
Vector<String> lookup_supported_locales(Vector<String> const& requested_locales);
|
||||
Vector<String> best_fit_supported_locales(Vector<String> const& requested_locales);
|
||||
ThrowCompletionOr<Array*> supported_locales(GlobalObject&, Vector<String> const& requested_locales, Value options);
|
||||
Object* coerce_options_to_object(GlobalObject& global_object, 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);
|
||||
Optional<int> get_number_option(GlobalObject& global_object, Object const& options, PropertyName const& property, int minimum, int maximum, Optional<int> fallback);
|
||||
|
|
|
@ -298,9 +298,7 @@ Value LocaleConstructor::construct(FunctionObject& new_target)
|
|||
}
|
||||
|
||||
// 10. Set options to ? CoerceOptionsToObject(options).
|
||||
auto* options = coerce_options_to_object(global_object, options_value);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
auto* options = TRY_OR_DISCARD(coerce_options_to_object(global_object, options_value));
|
||||
|
||||
// 11. Set tag to ? ApplyOptionsToTag(tag, options).
|
||||
if (auto applied_tag = apply_options_to_tag(global_object, tag, *options); applied_tag.has_value())
|
||||
|
|
|
@ -360,9 +360,7 @@ NumberFormat* initialize_number_format(GlobalObject& global_object, NumberFormat
|
|||
auto requested_locales = TRY_OR_DISCARD(canonicalize_locale_list(global_object, locales_value));
|
||||
|
||||
// 2. Set options to ? CoerceOptionsToObject(options).
|
||||
auto* options = coerce_options_to_object(global_object, options_value);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
auto* options = TRY_OR_DISCARD(coerce_options_to_object(global_object, options_value));
|
||||
|
||||
// 3. Let opt be a new Record.
|
||||
LocaleOptions opt {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue