diff options
author | Linus Groh <mail@linusgroh.de> | 2022-08-20 08:52:42 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-08-23 13:58:30 +0100 |
commit | 694f66b5ca7e95e9ce24df327e80b0cffc5ff6c7 (patch) | |
tree | 5c0a4b7b6804affcaaccfefd2f7320a00509a422 /Userland/Libraries/LibJS/Runtime/Intl | |
parent | f9705eb2f489416a32d145f5363ab0783949add3 (diff) | |
download | serenity-694f66b5ca7e95e9ce24df327e80b0cffc5ff6c7.zip |
LibJS: Replace GlobalObject with VM in Temporal AOs [Part 2/19]
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/Intl')
12 files changed, 59 insertions, 81 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp index d521709aa8..ce3157c770 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp @@ -569,13 +569,12 @@ Vector<String> best_fit_supported_locales(Vector<String> const& requested_locale ThrowCompletionOr<Array*> supported_locales(VM& vm, Vector<String> const& requested_locales, Value options) { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); // 1. Set options to ? CoerceOptionsToObject(options). auto* options_object = TRY(coerce_options_to_object(vm, 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, OptionType::String, { "lookup"sv, "best fit"sv }, "best fit"sv)); + auto matcher = TRY(get_option(vm, *options_object, vm.names.localeMatcher, OptionType::String, { "lookup"sv, "best fit"sv }, "best fit"sv)); Vector<String> supported_locales; diff --git a/Userland/Libraries/LibJS/Runtime/Intl/CollatorConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/CollatorConstructor.cpp index 23e2cc26d9..8f5724a8e7 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/CollatorConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/CollatorConstructor.cpp @@ -27,7 +27,7 @@ static ThrowCompletionOr<Collator*> initialize_collator(VM& vm, Collator& collat auto* options = TRY(coerce_options_to_object(vm, options_value)); // 3. Let usage be ? GetOption(options, "usage", "string", « "sort", "search" », "sort"). - auto usage = TRY(get_option(global_object, *options, vm.names.usage, OptionType::String, { "sort"sv, "search"sv }, "sort"sv)); + auto usage = TRY(get_option(vm, *options, vm.names.usage, OptionType::String, { "sort"sv, "search"sv }, "sort"sv)); // 4. Set collator.[[Usage]] to usage. collator.set_usage(usage.as_string().string()); @@ -41,13 +41,13 @@ static ThrowCompletionOr<Collator*> initialize_collator(VM& vm, Collator& collat LocaleOptions opt {}; // 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). - auto matcher = TRY(get_option(global_object, *options, vm.names.localeMatcher, OptionType::String, { "lookup"sv, "best fit"sv }, "best fit"sv)); + auto matcher = TRY(get_option(vm, *options, vm.names.localeMatcher, OptionType::String, { "lookup"sv, "best fit"sv }, "best fit"sv)); // 9. Set opt.[[localeMatcher]] to matcher. opt.locale_matcher = matcher; // 10. Let collation be ? GetOption(options, "collation", "string", undefined, undefined). - auto collation = TRY(get_option(global_object, *options, vm.names.collation, OptionType::String, {}, Empty {})); + auto collation = TRY(get_option(vm, *options, vm.names.collation, OptionType::String, {}, Empty {})); // 11. If collation is not undefined, then if (!collation.is_undefined()) { @@ -60,7 +60,7 @@ static ThrowCompletionOr<Collator*> initialize_collator(VM& vm, Collator& collat } // 13. Let numeric be ? GetOption(options, "numeric", "boolean", undefined, undefined). - auto numeric = TRY(get_option(global_object, *options, vm.names.numeric, OptionType::Boolean, {}, Empty {})); + auto numeric = TRY(get_option(vm, *options, vm.names.numeric, OptionType::Boolean, {}, Empty {})); // 14. If numeric is not undefined, then // a. Let numeric be ! ToString(numeric). @@ -70,7 +70,7 @@ static ThrowCompletionOr<Collator*> initialize_collator(VM& vm, Collator& collat // 16. Let caseFirst be ? GetOption(options, "caseFirst", "string", « "upper", "lower", "false" », undefined). // 17. Set opt.[[kf]] to caseFirst. - auto case_first = TRY(get_option(global_object, *options, vm.names.caseFirst, OptionType::String, { "upper"sv, "lower"sv, "false"sv }, Empty {})); + auto case_first = TRY(get_option(vm, *options, vm.names.caseFirst, OptionType::String, { "upper"sv, "lower"sv, "false"sv }, Empty {})); if (!case_first.is_undefined()) opt.kf = case_first.as_string().string(); @@ -101,7 +101,7 @@ static ThrowCompletionOr<Collator*> initialize_collator(VM& vm, Collator& collat } // 26. Let sensitivity be ? GetOption(options, "sensitivity", "string", « "base", "accent", "case", "variant" », undefined). - auto sensitivity = TRY(get_option(global_object, *options, vm.names.sensitivity, OptionType::String, { "base"sv, "accent"sv, "case"sv, "variant"sv }, Empty {})); + auto sensitivity = TRY(get_option(vm, *options, vm.names.sensitivity, OptionType::String, { "base"sv, "accent"sv, "case"sv, "variant"sv }, Empty {})); // 27. If sensitivity is undefined, then if (sensitivity.is_undefined()) { @@ -123,7 +123,7 @@ static ThrowCompletionOr<Collator*> initialize_collator(VM& vm, Collator& collat collator.set_sensitivity(sensitivity.as_string().string()); // 29. Let ignorePunctuation be ? GetOption(options, "ignorePunctuation", "boolean", undefined, false). - auto ignore_punctuation = TRY(get_option(global_object, *options, vm.names.ignorePunctuation, OptionType::Boolean, {}, false)); + auto ignore_punctuation = TRY(get_option(vm, *options, vm.names.ignorePunctuation, OptionType::Boolean, {}, false)); // 30. Set collator.[[IgnorePunctuation]] to ignorePunctuation. collator.set_ignore_punctuation(ignore_punctuation.as_bool()); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatConstructor.cpp index 9a44050345..dcd46ff63e 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatConstructor.cpp @@ -98,13 +98,13 @@ ThrowCompletionOr<DateTimeFormat*> initialize_date_time_format(VM& vm, DateTimeF LocaleOptions opt {}; // 4. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). - auto matcher = TRY(get_option(global_object, *options, vm.names.localeMatcher, OptionType::String, AK::Array { "lookup"sv, "best fit"sv }, "best fit"sv)); + auto matcher = TRY(get_option(vm, *options, vm.names.localeMatcher, OptionType::String, AK::Array { "lookup"sv, "best fit"sv }, "best fit"sv)); // 5. Set opt.[[localeMatcher]] to matcher. opt.locale_matcher = matcher; // 6. Let calendar be ? GetOption(options, "calendar", "string", undefined, undefined). - auto calendar = TRY(get_option(global_object, *options, vm.names.calendar, OptionType::String, {}, Empty {})); + auto calendar = TRY(get_option(vm, *options, vm.names.calendar, OptionType::String, {}, Empty {})); // 7. If calendar is not undefined, then if (!calendar.is_undefined()) { @@ -117,7 +117,7 @@ ThrowCompletionOr<DateTimeFormat*> initialize_date_time_format(VM& vm, DateTimeF } // 9. Let numberingSystem be ? GetOption(options, "numberingSystem", "string", undefined, undefined). - auto numbering_system = TRY(get_option(global_object, *options, vm.names.numberingSystem, OptionType::String, {}, Empty {})); + auto numbering_system = TRY(get_option(vm, *options, vm.names.numberingSystem, OptionType::String, {}, Empty {})); // 10. If numberingSystem is not undefined, then if (!numbering_system.is_undefined()) { @@ -130,10 +130,10 @@ ThrowCompletionOr<DateTimeFormat*> initialize_date_time_format(VM& vm, DateTimeF } // 12. Let hour12 be ? GetOption(options, "hour12", "boolean", undefined, undefined). - auto hour12 = TRY(get_option(global_object, *options, vm.names.hour12, OptionType::Boolean, {}, Empty {})); + auto hour12 = TRY(get_option(vm, *options, vm.names.hour12, OptionType::Boolean, {}, Empty {})); // 13. Let hourCycle be ? GetOption(options, "hourCycle", "string", « "h11", "h12", "h23", "h24" », undefined). - auto hour_cycle = TRY(get_option(global_object, *options, vm.names.hourCycle, OptionType::String, AK::Array { "h11"sv, "h12"sv, "h23"sv, "h24"sv }, Empty {})); + auto hour_cycle = TRY(get_option(vm, *options, vm.names.hourCycle, OptionType::String, AK::Array { "h11"sv, "h12"sv, "h23"sv, "h24"sv }, Empty {})); // 14. If hour12 is not undefined, then if (!hour12.is_undefined()) { @@ -274,7 +274,7 @@ ThrowCompletionOr<DateTimeFormat*> initialize_date_time_format(VM& vm, DateTimeF else { // i. Let values be a List whose elements are the strings given in the Values column of the row. // ii. Let value be ? GetOption(options, prop, "string", values, undefined). - auto value = TRY(get_option(global_object, *options, property, OptionType::String, values, Empty {})); + auto value = TRY(get_option(vm, *options, property, OptionType::String, values, Empty {})); // d. Set formatOptions.[[<prop>]] to value. if (!value.is_undefined()) { @@ -290,17 +290,17 @@ ThrowCompletionOr<DateTimeFormat*> initialize_date_time_format(VM& vm, DateTimeF })); // 37. Let matcher be ? GetOption(options, "formatMatcher", "string", « "basic", "best fit" », "best fit"). - matcher = TRY(get_option(global_object, *options, vm.names.formatMatcher, OptionType::String, AK::Array { "basic"sv, "best fit"sv }, "best fit"sv)); + matcher = TRY(get_option(vm, *options, vm.names.formatMatcher, OptionType::String, AK::Array { "basic"sv, "best fit"sv }, "best fit"sv)); // 38. Let dateStyle be ? GetOption(options, "dateStyle", "string", « "full", "long", "medium", "short" », undefined). - auto date_style = TRY(get_option(global_object, *options, vm.names.dateStyle, OptionType::String, AK::Array { "full"sv, "long"sv, "medium"sv, "short"sv }, Empty {})); + auto date_style = TRY(get_option(vm, *options, vm.names.dateStyle, OptionType::String, AK::Array { "full"sv, "long"sv, "medium"sv, "short"sv }, Empty {})); // 39. Set dateTimeFormat.[[DateStyle]] to dateStyle. if (!date_style.is_undefined()) date_time_format.set_date_style(date_style.as_string().string()); // 40. Let timeStyle be ? GetOption(options, "timeStyle", "string", « "full", "long", "medium", "short" », undefined). - auto time_style = TRY(get_option(global_object, *options, vm.names.timeStyle, OptionType::String, AK::Array { "full"sv, "long"sv, "medium"sv, "short"sv }, Empty {})); + auto time_style = TRY(get_option(vm, *options, vm.names.timeStyle, OptionType::String, AK::Array { "full"sv, "long"sv, "medium"sv, "short"sv }, Empty {})); // 41. Set dateTimeFormat.[[TimeStyle]] to timeStyle. if (!time_style.is_undefined()) diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesConstructor.cpp index cbbf0c3426..03d3452431 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesConstructor.cpp @@ -63,7 +63,7 @@ ThrowCompletionOr<Object*> DisplayNamesConstructor::construct(FunctionObject& ne return vm.throw_completion<TypeError>(ErrorType::IsUndefined, "options"sv); // 5. Set options to ? GetOptionsObject(options). - auto* options = TRY(Temporal::get_options_object(global_object, options_value)); + auto* options = TRY(Temporal::get_options_object(vm, options_value)); // 6. Let opt be a new Record. LocaleOptions opt {}; @@ -71,7 +71,7 @@ ThrowCompletionOr<Object*> DisplayNamesConstructor::construct(FunctionObject& ne // 7. Let localeData be %DisplayNames%.[[LocaleData]]. // 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). - auto matcher = TRY(get_option(global_object, *options, vm.names.localeMatcher, OptionType::String, { "lookup"sv, "best fit"sv }, "best fit"sv)); + auto matcher = TRY(get_option(vm, *options, vm.names.localeMatcher, OptionType::String, { "lookup"sv, "best fit"sv }, "best fit"sv)); // 9. Set opt.[[localeMatcher]] to matcher. opt.locale_matcher = matcher; @@ -80,13 +80,13 @@ ThrowCompletionOr<Object*> DisplayNamesConstructor::construct(FunctionObject& ne auto result = resolve_locale(requested_locales, opt, {}); // 11. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). - auto style = TRY(get_option(global_object, *options, vm.names.style, OptionType::String, { "narrow"sv, "short"sv, "long"sv }, "long"sv)); + auto style = TRY(get_option(vm, *options, vm.names.style, OptionType::String, { "narrow"sv, "short"sv, "long"sv }, "long"sv)); // 12. Set displayNames.[[Style]] to style. display_names->set_style(style.as_string().string()); // 13. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency", "calendar", "dateTimeField" », undefined). - auto type = TRY(get_option(global_object, *options, vm.names.type, OptionType::String, { "language"sv, "region"sv, "script"sv, "currency"sv, "calendar"sv, "dateTimeField"sv }, Empty {})); + auto type = TRY(get_option(vm, *options, vm.names.type, OptionType::String, { "language"sv, "region"sv, "script"sv, "currency"sv, "calendar"sv, "dateTimeField"sv }, Empty {})); // 14. If type is undefined, throw a TypeError exception. if (type.is_undefined()) @@ -96,7 +96,7 @@ ThrowCompletionOr<Object*> DisplayNamesConstructor::construct(FunctionObject& ne display_names->set_type(type.as_string().string()); // 16. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code"). - auto fallback = TRY(get_option(global_object, *options, vm.names.fallback, OptionType::String, { "code"sv, "none"sv }, "code"sv)); + auto fallback = TRY(get_option(vm, *options, vm.names.fallback, OptionType::String, { "code"sv, "none"sv }, "code"sv)); // 17. Set displayNames.[[Fallback]] to fallback. display_names->set_fallback(fallback.as_string().string()); @@ -112,7 +112,7 @@ ThrowCompletionOr<Object*> DisplayNamesConstructor::construct(FunctionObject& ne // 22. Assert: types is a Record (see 12.4.3). // 23. Let languageDisplay be ? GetOption(options, "languageDisplay", "string", « "dialect", "standard" », "dialect"). - auto language_display = TRY(get_option(global_object, *options, vm.names.languageDisplay, OptionType::String, { "dialect"sv, "standard"sv }, "dialect"sv)); + auto language_display = TRY(get_option(vm, *options, vm.names.languageDisplay, OptionType::String, { "dialect"sv, "standard"sv }, "dialect"sv)); // 24. Let typeFields be types.[[<type>]]. // 25. Assert: typeFields is a Record (see 12.4.3). diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp index 4cea981932..453352520c 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp @@ -133,9 +133,6 @@ StringView DurationFormat::display_to_string(Display display) // 1.1.3 ToDurationRecord ( input ), https://tc39.es/proposal-intl-duration-format/#sec-todurationrecord ThrowCompletionOr<Temporal::DurationRecord> to_duration_record(VM& vm, Value input) { - auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); - // 1. If Type(input) is not Object, throw a TypeError exception. if (!input.is_object()) return vm.throw_completion<TypeError>(ErrorType::NotAnObject, input); @@ -164,7 +161,7 @@ ThrowCompletionOr<Temporal::DurationRecord> to_duration_record(VM& vm, Value inp // i. Set any to true. any = true; // ii. Set value to ? ToIntegerWithoutRounding(value). - value_number = TRY(Temporal::to_integer_without_rounding(global_object, value, ErrorType::TemporalInvalidDurationPropertyValueNonIntegral, unit, value)); + value_number = TRY(Temporal::to_integer_without_rounding(vm, value, ErrorType::TemporalInvalidDurationPropertyValueNonIntegral, unit, value)); } // e. Else, else { @@ -242,11 +239,8 @@ bool is_valid_duration_record(Temporal::DurationRecord const& record) // 1.1.6 GetDurationUnitOptions ( unit, options, baseStyle, stylesList, digitalBase, prevStyle ), https://tc39.es/proposal-intl-duration-format/#sec-getdurationunitoptions ThrowCompletionOr<DurationUnitOptions> get_duration_unit_options(VM& vm, String const& unit, Object const& options, StringView base_style, Span<StringView const> styles_list, StringView digital_base, Optional<String> const& previous_style) { - auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); - // 1. Let style be ? GetOption(options, unit, "string", stylesList, undefined). - auto style_value = TRY(get_option(global_object, options, unit, OptionType::String, styles_list, Empty {})); + auto style_value = TRY(get_option(vm, options, unit, OptionType::String, styles_list, Empty {})); // 2. Let displayDefault be "always". auto display_default = "always"sv; @@ -276,7 +270,7 @@ ThrowCompletionOr<DurationUnitOptions> get_duration_unit_options(VM& vm, String auto display_field = String::formatted("{}Display", unit); // 5. Let display be ? GetOption(options, displayField, "string", « "auto", "always" », displayDefault). - auto display = TRY(get_option(global_object, options, display_field, OptionType::String, { "auto"sv, "always"sv }, display_default)); + auto display = TRY(get_option(vm, options, display_field, OptionType::String, { "auto"sv, "always"sv }, display_default)); // 6. If prevStyle is "numeric" or "2-digit", then if (previous_style == "numeric"sv || previous_style == "2-digit"sv) { diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatConstructor.cpp index 995ef3953d..a0457cbb4f 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatConstructor.cpp @@ -56,13 +56,13 @@ ThrowCompletionOr<Object*> DurationFormatConstructor::construct(FunctionObject& auto requested_locales = TRY(canonicalize_locale_list(vm, locales)); // 4. Let options be ? GetOptionsObject(options). - auto* options = TRY(Temporal::get_options_object(global_object, options_value)); + auto* options = TRY(Temporal::get_options_object(vm, options_value)); // 5. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). - auto matcher = TRY(get_option(global_object, *options, vm.names.localeMatcher, OptionType::String, { "lookup"sv, "best fit"sv }, "best fit"sv)); + auto matcher = TRY(get_option(vm, *options, vm.names.localeMatcher, OptionType::String, { "lookup"sv, "best fit"sv }, "best fit"sv)); // 6. Let numberingSystem be ? GetOption(options, "numberingSystem", "string", undefined, undefined). - auto numbering_system = TRY(get_option(global_object, *options, vm.names.numberingSystem, OptionType::String, {}, Empty {})); + auto numbering_system = TRY(get_option(vm, *options, vm.names.numberingSystem, OptionType::String, {}, Empty {})); // FIXME: Missing spec step - If numberingSystem is not undefined, then if (!numbering_system.is_undefined()) { @@ -90,7 +90,7 @@ ThrowCompletionOr<Object*> DurationFormatConstructor::construct(FunctionObject& duration_format->set_numbering_system(result.nu.release_value()); // 13. Let style be ? GetOption(options, "style", "string", « "long", "short", "narrow", "digital" », "long"). - auto style = TRY(get_option(global_object, *options, vm.names.style, OptionType::String, { "long"sv, "short"sv, "narrow"sv, "digital"sv }, "long"sv)); + auto style = TRY(get_option(vm, *options, vm.names.style, OptionType::String, { "long"sv, "short"sv, "narrow"sv, "digital"sv }, "long"sv)); // 14. Set durationFormat.[[Style]] to style. duration_format->set_style(style.as_string().string()); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/ListFormatConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/ListFormatConstructor.cpp index abc0c29df7..dcfabc52ab 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/ListFormatConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/ListFormatConstructor.cpp @@ -58,13 +58,13 @@ ThrowCompletionOr<Object*> ListFormatConstructor::construct(FunctionObject& new_ auto requested_locales = TRY(canonicalize_locale_list(vm, locale_value)); // 4. Set options to ? GetOptionsObject(options). - auto* options = TRY(Temporal::get_options_object(global_object, options_value)); + auto* options = TRY(Temporal::get_options_object(vm, options_value)); // 5. Let opt be a new Record. LocaleOptions opt {}; // 6. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). - auto matcher = TRY(get_option(global_object, *options, vm.names.localeMatcher, OptionType::String, { "lookup"sv, "best fit"sv }, "best fit"sv)); + auto matcher = TRY(get_option(vm, *options, vm.names.localeMatcher, OptionType::String, { "lookup"sv, "best fit"sv }, "best fit"sv)); // 7. Set opt.[[localeMatcher]] to matcher. opt.locale_matcher = matcher; @@ -78,13 +78,13 @@ ThrowCompletionOr<Object*> ListFormatConstructor::construct(FunctionObject& new_ list_format->set_locale(move(result.locale)); // 11. Let type be ? GetOption(options, "type", "string", « "conjunction", "disjunction", "unit" », "conjunction"). - auto type = TRY(get_option(global_object, *options, vm.names.type, OptionType::String, { "conjunction"sv, "disjunction"sv, "unit"sv }, "conjunction"sv)); + auto type = TRY(get_option(vm, *options, vm.names.type, OptionType::String, { "conjunction"sv, "disjunction"sv, "unit"sv }, "conjunction"sv)); // 12. Set listFormat.[[Type]] to type. list_format->set_type(type.as_string().string()); // 13. Let style be ? GetOption(options, "style", "string", « "long", "short", "narrow" », "long"). - auto style = TRY(get_option(global_object, *options, vm.names.style, OptionType::String, { "long"sv, "short"sv, "narrow"sv }, "long"sv)); + auto style = TRY(get_option(vm, *options, vm.names.style, OptionType::String, { "long"sv, "short"sv, "narrow"sv }, "long"sv)); // 14. Set listFormat.[[Style]] to style. list_format->set_style(style.as_string().string()); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/LocaleConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/LocaleConstructor.cpp index b7a28b5357..f11afc57d6 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/LocaleConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/LocaleConstructor.cpp @@ -28,10 +28,7 @@ struct LocaleAndKeys { // Note: This is not an AO in the spec. This just serves to abstract very similar steps in ApplyOptionsToTag and the Intl.Locale constructor. static ThrowCompletionOr<Optional<String>> get_string_option(VM& vm, Object const& options, PropertyKey const& property, Function<bool(StringView)> validator, Span<StringView const> values = {}) { - auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); - - auto option = TRY(get_option(global_object, options, property, OptionType::String, values, Empty {})); + auto option = TRY(get_option(vm, options, property, OptionType::String, values, Empty {})); if (option.is_undefined()) return Optional<String> {}; @@ -311,7 +308,7 @@ ThrowCompletionOr<Object*> LocaleConstructor::construct(FunctionObject& new_targ opt.kf = TRY(get_string_option(vm, *options, vm.names.caseFirst, nullptr, AK::Array { "upper"sv, "lower"sv, "false"sv })); // 23. Let kn be ? GetOption(options, "numeric", "boolean", undefined, undefined). - auto kn = TRY(get_option(global_object, *options, vm.names.numeric, OptionType::Boolean, {}, Empty {})); + auto kn = TRY(get_option(vm, *options, vm.names.numeric, OptionType::Boolean, {}, Empty {})); // 24. If kn is not undefined, set kn to ! ToString(kn). // 25. Set opt.[[kn]] to kn. diff --git a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatConstructor.cpp index 8d4785b430..4294200fcd 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatConstructor.cpp @@ -83,9 +83,6 @@ JS_DEFINE_NATIVE_FUNCTION(NumberFormatConstructor::supported_locales_of) // 1.1.2 InitializeNumberFormat ( numberFormat, locales, options ), https://tc39.es/proposal-intl-numberformat-v3/out/numberformat/proposed.html#sec-initializenumberformat ThrowCompletionOr<NumberFormat*> initialize_number_format(VM& vm, NumberFormat& number_format, Value locales_value, Value options_value) { - auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); - // 1. Let requestedLocales be ? CanonicalizeLocaleList(locales). auto requested_locales = TRY(canonicalize_locale_list(vm, locales_value)); @@ -96,13 +93,13 @@ ThrowCompletionOr<NumberFormat*> initialize_number_format(VM& vm, NumberFormat& LocaleOptions opt {}; // 4. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). - auto matcher = TRY(get_option(global_object, *options, vm.names.localeMatcher, OptionType::String, { "lookup"sv, "best fit"sv }, "best fit"sv)); + auto matcher = TRY(get_option(vm, *options, vm.names.localeMatcher, OptionType::String, { "lookup"sv, "best fit"sv }, "best fit"sv)); // 5. Set opt.[[localeMatcher]] to matcher. opt.locale_matcher = matcher; // 6. Let numberingSystem be ? GetOption(options, "numberingSystem", "string", undefined, undefined). - auto numbering_system = TRY(get_option(global_object, *options, vm.names.numberingSystem, OptionType::String, {}, Empty {})); + auto numbering_system = TRY(get_option(vm, *options, vm.names.numberingSystem, OptionType::String, {}, Empty {})); // 7. If numberingSystem is not undefined, then if (!numbering_system.is_undefined()) { @@ -164,7 +161,7 @@ ThrowCompletionOr<NumberFormat*> initialize_number_format(VM& vm, NumberFormat& } // 18. Let notation be ? GetOption(options, "notation", "string", « "standard", "scientific", "engineering", "compact" », "standard"). - auto notation = TRY(get_option(global_object, *options, vm.names.notation, OptionType::String, { "standard"sv, "scientific"sv, "engineering"sv, "compact"sv }, "standard"sv)); + auto notation = TRY(get_option(vm, *options, vm.names.notation, OptionType::String, { "standard"sv, "scientific"sv, "engineering"sv, "compact"sv }, "standard"sv)); // 19. Set numberFormat.[[Notation]] to notation. number_format.set_notation(notation.as_string().string()); @@ -193,13 +190,13 @@ ThrowCompletionOr<NumberFormat*> initialize_number_format(VM& vm, NumberFormat& number_format.set_rounding_increment(*rounding_increment); // 26. Let trailingZeroDisplay be ? GetOption(options, "trailingZeroDisplay", "string", « "auto", "stripIfInteger" », "auto"). - auto trailing_zero_display = TRY(get_option(global_object, *options, vm.names.trailingZeroDisplay, OptionType::String, { "auto"sv, "stripIfInteger"sv }, "auto"sv)); + auto trailing_zero_display = TRY(get_option(vm, *options, vm.names.trailingZeroDisplay, OptionType::String, { "auto"sv, "stripIfInteger"sv }, "auto"sv)); // 27. Set numberFormat.[[TrailingZeroDisplay]] to trailingZeroDisplay. number_format.set_trailing_zero_display(trailing_zero_display.as_string().string()); // 28. Let compactDisplay be ? GetOption(options, "compactDisplay", "string", « "short", "long" », "short"). - auto compact_display = TRY(get_option(global_object, *options, vm.names.compactDisplay, OptionType::String, { "short"sv, "long"sv }, "short"sv)); + auto compact_display = TRY(get_option(vm, *options, vm.names.compactDisplay, OptionType::String, { "short"sv, "long"sv }, "short"sv)); // 29. Let defaultUseGrouping be "auto". auto default_use_grouping = "auto"sv; @@ -220,13 +217,13 @@ ThrowCompletionOr<NumberFormat*> initialize_number_format(VM& vm, NumberFormat& number_format.set_use_grouping(use_grouping); // 33. Let signDisplay be ? GetOption(options, "signDisplay", "string", « "auto", "never", "always", "exceptZero, "negative" », "auto"). - auto sign_display = TRY(get_option(global_object, *options, vm.names.signDisplay, OptionType::String, { "auto"sv, "never"sv, "always"sv, "exceptZero"sv, "negative"sv }, "auto"sv)); + auto sign_display = TRY(get_option(vm, *options, vm.names.signDisplay, OptionType::String, { "auto"sv, "never"sv, "always"sv, "exceptZero"sv, "negative"sv }, "auto"sv)); // 34. Set numberFormat.[[SignDisplay]] to signDisplay. number_format.set_sign_display(sign_display.as_string().string()); // 35. Let roundingMode be ? GetOption(options, "roundingMode", "string", « "ceil", "floor", "expand", "trunc", "halfCeil", "halfFloor", "halfExpand", "halfTrunc", "halfEven" », "halfExpand"). - auto rounding_mode = TRY(get_option(global_object, *options, vm.names.roundingMode, OptionType::String, { "ceil"sv, "floor"sv, "expand"sv, "trunc"sv, "halfCeil"sv, "halfFloor"sv, "halfExpand"sv, "halfTrunc"sv, "halfEven"sv }, "halfExpand"sv)); + auto rounding_mode = TRY(get_option(vm, *options, vm.names.roundingMode, OptionType::String, { "ceil"sv, "floor"sv, "expand"sv, "trunc"sv, "halfCeil"sv, "halfFloor"sv, "halfExpand"sv, "halfTrunc"sv, "halfEven"sv }, "halfExpand"sv)); // 36. Set numberFormat.[[RoundingMode]] to roundingMode. number_format.set_rounding_mode(rounding_mode.as_string().string()); @@ -239,9 +236,6 @@ ThrowCompletionOr<NumberFormat*> initialize_number_format(VM& vm, NumberFormat& // 1.1.1 SetNumberFormatDigitOptions ( intlObj, options, mnfdDefault, mxfdDefault, notation ), https://tc39.es/proposal-intl-numberformat-v3/out/numberformat/proposed.html#sec-setnfdigitoptions ThrowCompletionOr<void> set_number_format_digit_options(VM& vm, NumberFormatBase& intl_object, Object const& options, int default_min_fraction_digits, int default_max_fraction_digits, NumberFormat::Notation notation) { - auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); - // 1. Let mnid be ? GetNumberOption(options, "minimumIntegerDigits,", 1, 21, 1). auto min_integer_digits = TRY(get_number_option(vm, options, vm.names.minimumIntegerDigits, 1, 21, 1)); @@ -261,7 +255,7 @@ ThrowCompletionOr<void> set_number_format_digit_options(VM& vm, NumberFormatBase intl_object.set_min_integer_digits(*min_integer_digits); // 7. Let roundingPriority be ? GetOption(options, "roundingPriority", "string", « "auto", "morePrecision", "lessPrecision" », "auto"). - auto rounding_priority = TRY(get_option(global_object, options, vm.names.roundingPriority, OptionType::String, { "auto"sv, "morePrecision"sv, "lessPrecision"sv }, "auto"sv)); + auto rounding_priority = TRY(get_option(vm, options, vm.names.roundingPriority, OptionType::String, { "auto"sv, "morePrecision"sv, "lessPrecision"sv }, "auto"sv)); // 8. If mnsd is not undefined or mxsd is not undefined, then // a. Let hasSd be true. @@ -403,20 +397,17 @@ ThrowCompletionOr<void> set_number_format_digit_options(VM& vm, NumberFormatBase // 15.1.4 SetNumberFormatUnitOptions ( intlObj, options ), https://tc39.es/ecma402/#sec-setnumberformatunitoptions ThrowCompletionOr<void> set_number_format_unit_options(VM& vm, NumberFormat& intl_object, Object const& options) { - auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); - // 1. Assert: Type(intlObj) is Object. // 2. Assert: Type(options) is Object. // 3. Let style be ? GetOption(options, "style", "string", « "decimal", "percent", "currency", "unit" », "decimal"). - auto style = TRY(get_option(global_object, options, vm.names.style, OptionType::String, { "decimal"sv, "percent"sv, "currency"sv, "unit"sv }, "decimal"sv)); + auto style = TRY(get_option(vm, options, vm.names.style, OptionType::String, { "decimal"sv, "percent"sv, "currency"sv, "unit"sv }, "decimal"sv)); // 4. Set intlObj.[[Style]] to style. intl_object.set_style(style.as_string().string()); // 5. Let currency be ? GetOption(options, "currency", "string", undefined, undefined). - auto currency = TRY(get_option(global_object, options, vm.names.currency, OptionType::String, {}, Empty {})); + auto currency = TRY(get_option(vm, options, vm.names.currency, OptionType::String, {}, Empty {})); // 6. If currency is undefined, then if (currency.is_undefined()) { @@ -430,13 +421,13 @@ ThrowCompletionOr<void> set_number_format_unit_options(VM& vm, NumberFormat& int return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, currency, "currency"sv); // 8. Let currencyDisplay be ? GetOption(options, "currencyDisplay", "string", « "code", "symbol", "narrowSymbol", "name" », "symbol"). - auto currency_display = TRY(get_option(global_object, options, vm.names.currencyDisplay, OptionType::String, { "code"sv, "symbol"sv, "narrowSymbol"sv, "name"sv }, "symbol"sv)); + auto currency_display = TRY(get_option(vm, options, vm.names.currencyDisplay, OptionType::String, { "code"sv, "symbol"sv, "narrowSymbol"sv, "name"sv }, "symbol"sv)); // 9. Let currencySign be ? GetOption(options, "currencySign", "string", « "standard", "accounting" », "standard"). - auto currency_sign = TRY(get_option(global_object, options, vm.names.currencySign, OptionType::String, { "standard"sv, "accounting"sv }, "standard"sv)); + auto currency_sign = TRY(get_option(vm, options, vm.names.currencySign, OptionType::String, { "standard"sv, "accounting"sv }, "standard"sv)); // 10. Let unit be ? GetOption(options, "unit", "string", undefined, undefined). - auto unit = TRY(get_option(global_object, options, vm.names.unit, OptionType::String, {}, Empty {})); + auto unit = TRY(get_option(vm, options, vm.names.unit, OptionType::String, {}, Empty {})); // 11. If unit is undefined, then if (unit.is_undefined()) { @@ -450,7 +441,7 @@ ThrowCompletionOr<void> set_number_format_unit_options(VM& vm, NumberFormat& int return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, unit, "unit"sv); // 13. Let unitDisplay be ? GetOption(options, "unitDisplay", "string", « "short", "narrow", "long" », "short"). - auto unit_display = TRY(get_option(global_object, options, vm.names.unitDisplay, OptionType::String, { "short"sv, "narrow"sv, "long"sv }, "short"sv)); + auto unit_display = TRY(get_option(vm, options, vm.names.unitDisplay, OptionType::String, { "short"sv, "narrow"sv, "long"sv }, "short"sv)); // 14. If style is "currency", then if (intl_object.style() == NumberFormat::Style::Currency) { diff --git a/Userland/Libraries/LibJS/Runtime/Intl/PluralRulesConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/PluralRulesConstructor.cpp index 0bf55d104e..029e4bcef8 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/PluralRulesConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/PluralRulesConstructor.cpp @@ -76,9 +76,6 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesConstructor::supported_locales_of) // 16.1.2 InitializePluralRules ( pluralRules, locales, options ), https://tc39.es/ecma402/#sec-initializepluralrules ThrowCompletionOr<PluralRules*> initialize_plural_rules(VM& vm, PluralRules& plural_rules, Value locales_value, Value options_value) { - auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); - // 1. Let requestedLocales be ? CanonicalizeLocaleList(locales). auto requested_locales = TRY(canonicalize_locale_list(vm, locales_value)); @@ -89,13 +86,13 @@ ThrowCompletionOr<PluralRules*> initialize_plural_rules(VM& vm, PluralRules& plu LocaleOptions opt {}; // 4. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). - auto matcher = TRY(get_option(global_object, *options, vm.names.localeMatcher, OptionType::String, AK::Array { "lookup"sv, "best fit"sv }, "best fit"sv)); + auto matcher = TRY(get_option(vm, *options, vm.names.localeMatcher, OptionType::String, AK::Array { "lookup"sv, "best fit"sv }, "best fit"sv)); // 5. Set opt.[[localeMatcher]] to matcher. opt.locale_matcher = matcher; // 6. Let t be ? GetOption(options, "type", "string", « "cardinal", "ordinal" », "cardinal"). - auto type = TRY(get_option(global_object, *options, vm.names.type, OptionType::String, AK::Array { "cardinal"sv, "ordinal"sv }, "cardinal"sv)); + auto type = TRY(get_option(vm, *options, vm.names.type, OptionType::String, AK::Array { "cardinal"sv, "ordinal"sv }, "cardinal"sv)); // 7. Set pluralRules.[[Type]] to t. plural_rules.set_type(type.as_string().string()); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatConstructor.cpp index 701c6f78ab..22e40b3f5f 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatConstructor.cpp @@ -92,13 +92,13 @@ ThrowCompletionOr<RelativeTimeFormat*> initialize_relative_time_format(VM& vm, R LocaleOptions opt {}; // 4. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). - auto matcher = TRY(get_option(global_object, *options, vm.names.localeMatcher, OptionType::String, AK::Array { "lookup"sv, "best fit"sv }, "best fit"sv)); + auto matcher = TRY(get_option(vm, *options, vm.names.localeMatcher, OptionType::String, AK::Array { "lookup"sv, "best fit"sv }, "best fit"sv)); // 5. Set opt.[[LocaleMatcher]] to matcher. opt.locale_matcher = matcher; // 6. Let numberingSystem be ? GetOption(options, "numberingSystem", "string", undefined, undefined). - auto numbering_system = TRY(get_option(global_object, *options, vm.names.numberingSystem, OptionType::String, {}, Empty {})); + auto numbering_system = TRY(get_option(vm, *options, vm.names.numberingSystem, OptionType::String, {}, Empty {})); // 7. If numberingSystem is not undefined, then if (!numbering_system.is_undefined()) { @@ -128,13 +128,13 @@ ThrowCompletionOr<RelativeTimeFormat*> initialize_relative_time_format(VM& vm, R relative_time_format.set_numbering_system(result.nu.release_value()); // 15. Let style be ? GetOption(options, "style", "string", « "long", "short", "narrow" », "long"). - auto style = TRY(get_option(global_object, *options, vm.names.style, OptionType::String, { "long"sv, "short"sv, "narrow"sv }, "long"sv)); + auto style = TRY(get_option(vm, *options, vm.names.style, OptionType::String, { "long"sv, "short"sv, "narrow"sv }, "long"sv)); // 16. Set relativeTimeFormat.[[Style]] to style. relative_time_format.set_style(style.as_string().string()); // 17. Let numeric be ? GetOption(options, "numeric", "string", « "always", "auto" », "always"). - auto numeric = TRY(get_option(global_object, *options, vm.names.numeric, OptionType::String, { "always"sv, "auto"sv }, "always"sv)); + auto numeric = TRY(get_option(vm, *options, vm.names.numeric, OptionType::String, { "always"sv, "auto"sv }, "always"sv)); // 18. Set relativeTimeFormat.[[Numeric]] to numeric. relative_time_format.set_numeric(numeric.as_string().string()); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/SegmenterConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/SegmenterConstructor.cpp index ddc0be47c0..009baa2ef9 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/SegmenterConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/SegmenterConstructor.cpp @@ -58,13 +58,13 @@ ThrowCompletionOr<Object*> SegmenterConstructor::construct(FunctionObject& new_t auto requested_locales = TRY(canonicalize_locale_list(vm, locales)); // 5. Set options to ? GetOptionsObject(options). - auto* options = TRY(Temporal::get_options_object(global_object, options_value)); + auto* options = TRY(Temporal::get_options_object(vm, options_value)); // 6. Let opt be a new Record. LocaleOptions opt {}; // 7. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). - auto matcher = TRY(get_option(global_object, *options, vm.names.localeMatcher, OptionType::String, { "lookup"sv, "best fit"sv }, "best fit"sv)); + auto matcher = TRY(get_option(vm, *options, vm.names.localeMatcher, OptionType::String, { "lookup"sv, "best fit"sv }, "best fit"sv)); // 8. Set opt.[[localeMatcher]] to matcher. opt.locale_matcher = matcher; @@ -78,7 +78,7 @@ ThrowCompletionOr<Object*> SegmenterConstructor::construct(FunctionObject& new_t segmenter->set_locale(move(result.locale)); // 12. Let granularity be ? GetOption(options, "granularity", "string", « "grapheme", "word", "sentence" », "grapheme"). - auto granularity = TRY(get_option(global_object, *options, vm.names.granularity, OptionType::String, { "grapheme"sv, "word"sv, "sentence"sv }, "grapheme"sv)); + auto granularity = TRY(get_option(vm, *options, vm.names.granularity, OptionType::String, { "grapheme"sv, "word"sv, "sentence"sv }, "grapheme"sv)); // 13. Set segmenter.[[SegmenterGranularity]] to granularity. segmenter->set_segmenter_granularity(granularity.as_string().string()); |