Forráskód Böngészése

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
Timothy Flynn 11 hónapja
szülő
commit
a1a368bb61

+ 9 - 15
Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp

@@ -333,6 +333,7 @@ ThrowCompletionOr<Vector<String>> 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<String> 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<Array*> filter_locales(VM& vm, ReadonlySpan<String> 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<Unicode::LocaleExtension>();
-        auto no_extensions_locale = locale_id->to_string();
-
         Optional<MatchedLocale> 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);
     }

+ 25 - 30
Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesConstructor.cpp

@@ -53,7 +53,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> 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<DisplayNames>(vm, new_target, &Intrinsics::intl_display_names_prototype));
 
     // 3. Let requestedLocales be ? CanonicalizeLocaleList(locales).
@@ -69,69 +69,64 @@ ThrowCompletionOr<NonnullGCPtr<Object>> 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<TypeError>(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.
-
-    // 19. Let dataLocale be r.[[dataLocale]].
-    // 20. Let dataLocaleData be localeData.[[<dataLocale>]].
-    // 21. Let types be dataLocaleData.[[types]].
-    // 22. Assert: types is a Record (see 12.4.3).
+    // 18. Let resolvedLocaleData be r.[[LocaleData]].
+    // 19. Let types be resolvedLocaleData.[[types]].
+    // 20. Assert: types is a Record (see 12.2.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.[[<type>]].
-    // 25. Assert: typeFields is a Record (see 12.4.3).
+    // 22. Let typeFields be types.[[<type>]].
+    // 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.[[<languageDisplay>]].
-        // c. Assert: typeFields is a Record (see 12.4.3).
+        // b. Set typeFields to typeFields.[[<languageDisplay>]].
+        // c. Assert: typeFields is a Record (see 12.2.3).
     }
 
-    // 27. Let styleFields be typeFields.[[<style>]].
-    // 28. Assert: styleFields is a Record (see 12.4.3).
-    // 29. Set displayNames.[[Fields]] to styleFields.
+    // 25. Let styleFields be typeFields.[[<style>]].
+    // 26. Assert: styleFields is a Record (see 12.2.3).
+    // 27. Set displayNames.[[Fields]] to styleFields.
 
-    // 30. Return displayNames.
+    // 28. Return displayNames.
     return display_names;
 }
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp

@@ -31,7 +31,7 @@ Vector<Unicode::ListFormat::Partition> create_parts_from_list(ListFormat const&
 String format_list(ListFormat const& list_format, ReadonlySpan<String> list)
 {
     // 1. Let parts be ! CreatePartsFromList(listFormat, list).
-    // 2. Let result be an empty String.
+    // 2. Let result be the empty String.
     // 3. For each Record { [[Type]], [[Value]] } part in parts, do
     //     a. Set result to the string-concatenation of result and part.[[Value]].
     // 4. Return result.

+ 1 - 1
Userland/Libraries/LibJS/Runtime/Intl/LocaleConstructor.cpp

@@ -260,7 +260,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> LocaleConstructor::construct(FunctionObj
     // 5. If relevantExtensionKeys contains "kn", then
     //     a. Append [[Numeric]] as the last element of internalSlotsList.
 
-    // 6. Let locale be ? OrdinaryCreateFromConstructor(NewTarget, "%Locale.prototype%", internalSlotsList).
+    // 6. Let locale be ? OrdinaryCreateFromConstructor(NewTarget, "%Intl.Locale.prototype%", internalSlotsList).
     auto locale = TRY(ordinary_create_from_constructor<Locale>(vm, new_target, &Intrinsics::intl_locale_prototype));
 
     String tag;

+ 1 - 1
Userland/Libraries/LibJS/Runtime/Intl/NumberFormatConstructor.cpp

@@ -51,7 +51,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> NumberFormatConstructor::construct(Funct
     auto locales = vm.argument(0);
     auto options = vm.argument(1);
 
-    // 2. Let numberFormat be ? OrdinaryCreateFromConstructor(newTarget, "%NumberFormat.prototype%", « [[InitializedNumberFormat]], [[Locale]], [[DataLocale]], [[NumberingSystem]], [[Style]], [[Unit]], [[UnitDisplay]], [[Currency]], [[CurrencyDisplay]], [[CurrencySign]], [[MinimumIntegerDigits]], [[MinimumFractionDigits]], [[MaximumFractionDigits]], [[MinimumSignificantDigits]], [[MaximumSignificantDigits]], [[RoundingType]], [[Notation]], [[CompactDisplay]], [[UseGrouping]], [[SignDisplay]], [[RoundingMode]], [[RoundingIncrement]], [[TrailingZeroDisplay]], [[BoundFormat]] »).
+    // 2. Let numberFormat be ? OrdinaryCreateFromConstructor(newTarget, "%Intl.NumberFormat.prototype%", « [[InitializedNumberFormat]], [[Locale]], [[DataLocale]], [[NumberingSystem]], [[Style]], [[Unit]], [[UnitDisplay]], [[Currency]], [[CurrencyDisplay]], [[CurrencySign]], [[MinimumIntegerDigits]], [[MinimumFractionDigits]], [[MaximumFractionDigits]], [[MinimumSignificantDigits]], [[MaximumSignificantDigits]], [[RoundingType]], [[Notation]], [[CompactDisplay]], [[UseGrouping]], [[SignDisplay]], [[RoundingMode]], [[RoundingIncrement]], [[TrailingZeroDisplay]], [[BoundFormat]] »).
     auto number_format = TRY(ordinary_create_from_constructor<NumberFormat>(vm, new_target, &Intrinsics::intl_number_format_prototype));
 
     // 3. Perform ? InitializeNumberFormat(numberFormat, locales, options).

+ 6 - 7
Userland/Libraries/LibJS/Runtime/Intl/PluralRulesConstructor.cpp

@@ -70,20 +70,19 @@ ThrowCompletionOr<NonnullGCPtr<Object>> PluralRulesConstructor::construct(Functi
     // 7. Set opt.[[localeMatcher]] to matcher.
     opt.locale_matcher = matcher;
 
-    // 8. Let localeData be %Intl.PluralRules%.[[LocaleData]].
-    // 9. Let r be ResolveLocale(%Intl.PluralRules%.[[AvailableLocales]], requestedLocales, opt, %Intl.PluralRules%.[[RelevantExtensionKeys]], localeData).
+    // 8. Let r be ResolveLocale(%Intl.PluralRules%.[[AvailableLocales]], requestedLocales, opt, %Intl.PluralRules%.[[RelevantExtensionKeys]], %Intl.PluralRules%.[[LocaleData]]).
     auto result = resolve_locale(requested_locales, opt, {});
 
-    // 10. Set pluralRules.[[Locale]] to r.[[locale]].
+    // 9. Set pluralRules.[[Locale]] to r.[[locale]].
     plural_rules->set_locale(move(result.locale));
 
-    // 11. Let t be ? GetOption(options, "type", string, « "cardinal", "ordinal" », "cardinal").
+    // 10. Let t be ? GetOption(options, "type", string, « "cardinal", "ordinal" », "cardinal").
     auto type = TRY(get_option(vm, *options, vm.names.type, OptionType::String, AK::Array { "cardinal"sv, "ordinal"sv }, "cardinal"sv));
 
-    // 12. Set pluralRules.[[Type]] to t.
+    // 11. Set pluralRules.[[Type]] to t.
     plural_rules->set_type(type.as_string().utf8_string_view());
 
-    // 13. Perform ? SetNumberFormatDigitOptions(pluralRules, options, 0, 3, "standard").
+    // 12. Perform ? SetNumberFormatDigitOptions(pluralRules, options, 0, 3, "standard").
     TRY(set_number_format_digit_options(vm, plural_rules, *options, 0, 3, Unicode::Notation::Standard));
 
     // Non-standard, create an ICU number formatter for this Intl object.
@@ -96,7 +95,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> PluralRulesConstructor::construct(Functi
     formatter->create_plural_rules(plural_rules->type());
     plural_rules->set_formatter(move(formatter));
 
-    // 14. Return pluralRules.
+    // 13. Return pluralRules.
     return plural_rules;
 }
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp

@@ -88,7 +88,7 @@ ThrowCompletionOr<String> format_relative_time(VM& vm, RelativeTimeFormat& relat
         return TRY(singular_relative_time_unit(vm, unit));
     }());
 
-    // 2. Let result be an empty String.
+    // 2. Let result be the empty String.
     // 3. For each Record { [[Type]], [[Value]], [[Unit]] } part in parts, do
     //     a. Set result to the string-concatenation of result and part.[[Value]].
     // 4. Return result.

+ 1 - 1
Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatConstructor.cpp

@@ -51,7 +51,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> RelativeTimeFormatConstructor::construct
     auto locales_value = vm.argument(0);
     auto options_value = vm.argument(1);
 
-    // 2. Let relativeTimeFormat be ? OrdinaryCreateFromConstructor(NewTarget, "%RelativeTimeFormat.prototype%", « [[InitializedRelativeTimeFormat]], [[Locale]], [[LocaleData]], [[Style]], [[Numeric]], [[NumberFormat]], [[NumberingSystem]], [[PluralRules]] »).
+    // 2. Let relativeTimeFormat be ? OrdinaryCreateFromConstructor(NewTarget, "%Intl.RelativeTimeFormat.prototype%", « [[InitializedRelativeTimeFormat]], [[Locale]], [[LocaleData]], [[Style]], [[Numeric]], [[NumberFormat]], [[NumberingSystem]], [[PluralRules]] »).
     auto relative_time_format = TRY(ordinary_create_from_constructor<RelativeTimeFormat>(vm, new_target, &Intrinsics::intl_relative_time_format_prototype));
 
     // 3. Let requestedLocales be ? CanonicalizeLocaleList(locales).

+ 1 - 1
Userland/Libraries/LibJS/Runtime/Intl/SegmenterConstructor.cpp

@@ -53,7 +53,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> SegmenterConstructor::construct(Function
     auto options_value = vm.argument(1);
 
     // 2. Let internalSlotsList be « [[InitializedSegmenter]], [[Locale]], [[SegmenterGranularity]] ».
-    // 3. Let segmenter be ? OrdinaryCreateFromConstructor(NewTarget, "%Segmenter.prototype%", internalSlotsList).
+    // 3. Let segmenter be ? OrdinaryCreateFromConstructor(NewTarget, "%Intl.Segmenter.prototype%", internalSlotsList).
     auto segmenter = TRY(ordinary_create_from_constructor<Segmenter>(vm, new_target, &Intrinsics::intl_segmenter_prototype));
 
     // 4. Let requestedLocales be ? CanonicalizeLocaleList(locales).

+ 11 - 16
Userland/Libraries/LibJS/Runtime/StringPrototype.cpp

@@ -1261,42 +1261,37 @@ static ThrowCompletionOr<String> transform_case(VM& vm, String const& string, Va
     // 1. Let requestedLocales be ? CanonicalizeLocaleList(locales).
     auto requested_locales = TRY(Intl::canonicalize_locale_list(vm, locales));
 
-    Optional<Unicode::LocaleID> requested_locale;
+    String requested_locale;
 
     // 2. If requestedLocales is not an empty List, then
     if (!requested_locales.is_empty()) {
         // a. Let requestedLocale be requestedLocales[0].
-        requested_locale = Unicode::parse_unicode_locale_id(requested_locales[0]);
+        requested_locale = requested_locales[0];
     }
     // 3. Else,
     else {
         // a. Let requestedLocale be ! DefaultLocale().
-        requested_locale = Unicode::parse_unicode_locale_id(Unicode::default_locale());
+        requested_locale = String::from_utf8_without_validation(Unicode::default_locale().bytes());
     }
-    VERIFY(requested_locale.has_value());
 
-    // 4. Let noExtensionsLocale be the String value that is requestedLocale with any Unicode locale extension sequences removed.
-    requested_locale->remove_extension_type<Unicode::LocaleExtension>();
-    auto no_extensions_locale = requested_locale->to_string();
+    // 4. Let availableLocales be an Available Locales List which includes the language tags for which the Unicode Character Database contains language-sensitive case mappings. If the implementation supports additional locale-sensitive case mappings, availableLocales should also include their corresponding language tags.
+    // 5. Let match be LookupMatchingLocaleByPrefix(availableLocales, « requestedLocale »).
+    auto match = Intl::lookup_matching_locale_by_prefix({ { requested_locale } });
 
-    // 5. Let availableLocales be a List with language tags that includes the languages for which the Unicode Character Database contains language sensitive case mappings. Implementations may add additional language tags if they support case mapping for additional locales.
-    // 6. Let match be LookupMatchingLocaleByPrefix(availableLocales, noExtensionsLocale).
-    auto match = Intl::lookup_matching_locale_by_prefix({ { no_extensions_locale } });
-
-    // 7. If match is not undefined, let locale be match.[[locale]]; else let locale be "und".
+    // 6. If match is not undefined, let locale be match.[[locale]]; else let locale be "und".
     StringView locale = match.has_value() ? match->locale : "und"sv;
 
-    // 8. Let codePoints be StringToCodePoints(S).
+    // 7. Let codePoints be StringToCodePoints(S).
 
     String new_code_points;
 
     switch (target_case) {
-    // 9. If targetCase is lower, then
+    // 8. If targetCase is lower, then
     case TargetCase::Lower:
         // a. Let newCodePoints be a List whose elements are the result of a lowercase transformation of codePoints according to an implementation-derived algorithm using locale or the Unicode Default Case Conversion algorithm.
         new_code_points = MUST(string.to_lowercase(locale));
         break;
-    // 10. Else,
+    // 9. Else,
     case TargetCase::Upper:
         // a. Assert: targetCase is upper.
         // b. Let newCodePoints be a List whose elements are the result of an uppercase transformation of codePoints according to an implementation-derived algorithm using locale or the Unicode Default Case Conversion algorithm.
@@ -1306,7 +1301,7 @@ static ThrowCompletionOr<String> transform_case(VM& vm, String const& string, Va
         VERIFY_NOT_REACHED();
     }
 
-    // 11. Return CodePointsToString(newCodePoints).
+    // 10. Return CodePointsToString(newCodePoints).
     return new_code_points;
 }