LibJS: Canonicalize extension values in the Intl.Locale constructor

This is a normative change in the ECMA-402 spec. See:
https://github.com/tc39/ecma402/commit/f7983ff
This commit is contained in:
Timothy Flynn 2024-02-05 15:21:02 -05:00
parent cfde0bb005
commit d91ea41654
2 changed files with 14 additions and 4 deletions

View file

@ -182,15 +182,19 @@ static LocaleAndKeys apply_unicode_extension_to_tag(StringView tag, LocaleAndKey
// f. If optionsValue is not undefined, then
if (options_value.has_value()) {
// i. Assert: Type(optionsValue) is String.
// ii. Let value be optionsValue.
value = options_value.release_value();
// iii. If entry is not empty, then
// ii. Let optionsUValue be the ASCII-lowercase of optionsValue.
// NOTE: LibLocale performs this transformation itself.
// iii. Set value to the String value resulting from canonicalizing optionsUValue as a value of key key per Unicode Technical Standard #35 Part 1 Core, Annex C LocaleId Canonicalization Section 5 Canonicalizing Syntax, Processing LocaleIds.
value = ::Locale::canonicalize_unicode_extension_values(key, *options_value, ::Locale::RemoveTrue::Yes);
// iv. If entry is not empty, then
if (entry != nullptr) {
// 1. Set entry.[[Value]] to value.
entry->value = *value;
}
// iv. Else,
// v. Else,
else {
// 1. Append the Record { [[Key]]: key, [[Value]]: value } to keywords.
keywords.append({ MUST(String::from_utf8(key)), *value });

View file

@ -12,5 +12,11 @@ describe("normal behavior", () => {
expect(new Intl.Locale("en-u-ca-abc").calendar).toBe("abc");
expect(new Intl.Locale("en", { calendar: "abc" }).calendar).toBe("abc");
expect(new Intl.Locale("en-u-ca-abc", { calendar: "def" }).calendar).toBe("def");
expect(new Intl.Locale("en", { calendar: "islamicc" }).calendar).toBe("islamic-civil");
expect(new Intl.Locale("en-u-ca-islamicc").calendar).toBe("islamic-civil");
expect(new Intl.Locale("en", { calendar: "ethiopic-amete-alem" }).calendar).toBe("ethioaa");
expect(new Intl.Locale("en-u-ca-ethiopic-amete-alem").calendar).toBe("ethioaa");
});
});