From a1a368bb6190fe7669247bc5a3fc1f1cf32aeeeb Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 15 Aug 2024 15:55:33 -0400 Subject: [PATCH] LibJS: Fix editorial rebasing errors in the ECMA-402 spec This is the remainder of the editorial rebasing errors that were fixed in: https://github.com/tc39/ecma402/commit/3f029b0 --- .../LibJS/Runtime/Intl/AbstractOperations.cpp | 24 +++----- .../Runtime/Intl/DisplayNamesConstructor.cpp | 55 +++++++++---------- .../LibJS/Runtime/Intl/ListFormat.cpp | 2 +- .../LibJS/Runtime/Intl/LocaleConstructor.cpp | 2 +- .../Runtime/Intl/NumberFormatConstructor.cpp | 2 +- .../Runtime/Intl/PluralRulesConstructor.cpp | 13 ++--- .../LibJS/Runtime/Intl/RelativeTimeFormat.cpp | 2 +- .../Intl/RelativeTimeFormatConstructor.cpp | 2 +- .../Runtime/Intl/SegmenterConstructor.cpp | 2 +- .../LibJS/Runtime/StringPrototype.cpp | 27 ++++----- 10 files changed, 57 insertions(+), 74 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp index 86c3e045366..5120a3effb4 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp @@ -333,6 +333,7 @@ ThrowCompletionOr> canonicalize_locale_list(VM& vm, Value locales // d. Increase k by 1. } + // 8. Return seen. return seen; } @@ -586,7 +587,7 @@ ResolvedLocale resolve_locale(ReadonlySpan requested_locales, LocaleOpti found_locale = insert_unicode_extension_and_canonicalize(locale_id.release_value(), {}, move(supported_keywords)); } - // 15. Set result.[[locale]] to foundLocale. + // 15. Set result.[[Locale]] to foundLocale. result.locale = move(found_locale); // 16. Return result. @@ -609,27 +610,20 @@ ThrowCompletionOr filter_locales(VM& vm, ReadonlySpan requested_ // 4. For each element locale of requestedLocales, do for (auto const& locale : requested_locales) { - auto locale_id = Unicode::parse_unicode_locale_id(locale); - VERIFY(locale_id.has_value()); - - // a. Let noExtensionsLocale be the String value that is locale with any Unicode locale extension sequences removed. - locale_id->remove_extension_type(); - auto no_extensions_locale = locale_id->to_string(); - Optional match; - // b. If matcher is "lookup", then + // a. If matcher is "lookup", then if (matcher.as_string().utf8_string_view() == "lookup"sv) { - // i. Let match be LookupMatchingLocaleByPrefix(availableLocales, noExtensionsLocale). - match = lookup_matching_locale_by_prefix({ { no_extensions_locale } }); + // i. Let match be LookupMatchingLocaleByPrefix(availableLocales, « locale »). + match = lookup_matching_locale_by_prefix({ { locale } }); } - // c. Else, + // b. Else, else { - // i. Let match be LookupMatchingLocaleByBestFit(availableLocales, noExtensionsLocale). - match = lookup_matching_locale_by_best_fit({ { no_extensions_locale } }); + // i. Let match be LookupMatchingLocaleByBestFit(availableLocales, « locale »). + match = lookup_matching_locale_by_best_fit({ { locale } }); } - // d. If match is not undefined, append locale to subset. + // c. If match is not undefined, append locale to subset. if (match.has_value()) subset.append(locale); } diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesConstructor.cpp index 6d986cce881..1ee3d8d2414 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesConstructor.cpp @@ -53,7 +53,7 @@ ThrowCompletionOr> DisplayNamesConstructor::construct(Funct auto locale_value = vm.argument(0); auto options_value = vm.argument(1); - // 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNames.prototype%", « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[LanguageDisplay]], [[Fields]] »). + // 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%Intl.DisplayNames.prototype%", « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[LanguageDisplay]], [[Fields]] »). auto display_names = TRY(ordinary_create_from_constructor(vm, new_target, &Intrinsics::intl_display_names_prototype)); // 3. Let requestedLocales be ? CanonicalizeLocaleList(locales). @@ -69,69 +69,64 @@ ThrowCompletionOr> DisplayNamesConstructor::construct(Funct // 6. Let opt be a new Record. LocaleOptions opt {}; - // 7. Let localeData be %DisplayNames%.[[LocaleData]]. - - // 8. Let matcher be ? GetOption(options, "localeMatcher", string, « "lookup", "best fit" », "best fit"). + // 7. Let matcher be ? GetOption(options, "localeMatcher", string, « "lookup", "best fit" », "best fit"). 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. + // 8. Set opt.[[localeMatcher]] to matcher. opt.locale_matcher = matcher; - // 10. Let r be ResolveLocale(%DisplayNames%.[[AvailableLocales]], requestedLocales, opt, %DisplayNames%.[[RelevantExtensionKeys]]). + // 9. Let r be ResolveLocale(%Intl.DisplayNames%.[[AvailableLocales]], requestedLocales, opt, %Intl.DisplayNames%.[[RelevantExtensionKeys]], %Intl.DisplayNames%.[[LocaleData]]). auto result = resolve_locale(requested_locales, opt, {}); - // 11. Let style be ? GetOption(options, "style", string, « "narrow", "short", "long" », "long"). + // 10. Let style be ? GetOption(options, "style", string, « "narrow", "short", "long" », "long"). 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. + // 11. Set displayNames.[[Style]] to style. display_names->set_style(style.as_string().utf8_string_view()); - // 13. Let type be ? GetOption(options, "type", string, « "language", "region", "script", "currency", "calendar", "dateTimeField" », undefined). + // 12. Let type be ? GetOption(options, "type", string, « "language", "region", "script", "currency", "calendar", "dateTimeField" », undefined). 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. + // 13. If type is undefined, throw a TypeError exception. if (type.is_undefined()) return vm.throw_completion(ErrorType::IsUndefined, "options.type"sv); - // 15. Set displayNames.[[Type]] to type. + // 14. Set displayNames.[[Type]] to type. display_names->set_type(type.as_string().utf8_string_view()); - // 16. Let fallback be ? GetOption(options, "fallback", string, « "code", "none" », "code"). + // 15. Let fallback be ? GetOption(options, "fallback", string, « "code", "none" », "code"). auto fallback = TRY(get_option(vm, *options, vm.names.fallback, OptionType::String, { "code"sv, "none"sv }, "code"sv)); - // 17. Set displayNames.[[Fallback]] to fallback. + // 16. Set displayNames.[[Fallback]] to fallback. display_names->set_fallback(fallback.as_string().utf8_string_view()); - // 18. Set displayNames.[[Locale]] to r.[[locale]]. + // 17. Set displayNames.[[Locale]] to r.[[Locale]]. display_names->set_locale(move(result.locale)); - // Note: Several of the steps below are skipped in favor of deferring to LibUnicode. + // 18. Let resolvedLocaleData be r.[[LocaleData]]. + // 19. Let types be resolvedLocaleData.[[types]]. + // 20. Assert: types is a Record (see 12.2.3). - // 19. Let dataLocale be r.[[dataLocale]]. - // 20. Let dataLocaleData be localeData.[[]]. - // 21. Let types be dataLocaleData.[[types]]. - // 22. Assert: types is a Record (see 12.4.3). - - // 23. Let languageDisplay be ? GetOption(options, "languageDisplay", string, « "dialect", "standard" », "dialect"). + // 21. Let languageDisplay be ? GetOption(options, "languageDisplay", string, « "dialect", "standard" », "dialect"). auto language_display = TRY(get_option(vm, *options, vm.names.languageDisplay, OptionType::String, { "dialect"sv, "standard"sv }, "dialect"sv)); - // 24. Let typeFields be types.[[]]. - // 25. Assert: typeFields is a Record (see 12.4.3). + // 22. Let typeFields be types.[[]]. + // 23. Assert: typeFields is a Record (see 12.2.3). - // 26. If type is "language", then + // 24. If type is "language", then if (display_names->type() == DisplayNames::Type::Language) { // a. Set displayNames.[[LanguageDisplay]] to languageDisplay. display_names->set_language_display(language_display.as_string().utf8_string_view()); - // b. Let typeFields be typeFields.[[]]. - // c. Assert: typeFields is a Record (see 12.4.3). + // b. Set typeFields to typeFields.[[]]. + // c. Assert: typeFields is a Record (see 12.2.3). } - // 27. Let styleFields be typeFields.[[