-
Notifications
You must be signed in to change notification settings - Fork 108
Normative: Add Intl.Locale.prototype.variants #960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
spec/locale.html
Outdated
1. Perform ? RequireInternalSlot(_loc_, [[InitializedLocale]]). | ||
1. Let _variantsString_ be GetLocaleVariants(_loc_.[[Locale]]). | ||
1. Let _variantsList_ be StringSplitToList(_variantsString_, *"-"*). | ||
1. Return CreateArrayFromList(_variantsList_). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- @anba Should this also state the order need to be in alphabetical order ?
See the order discussion in
https://unicode.org/reports/tr35/#Canonical_Unicode_Locale_Identifiers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might benefit from a note, but nothing more—alphabetization is already required by use of CanonicalizeUnicodeLocaleId in the Intl.Locale constructor.
If we do this, then how about setting variants in option bag them? |
Good question, and I think the answer is "yes". This also interacts with the design question about representing variants as an array of strings or as a single dash-separated string, and I'm increasingly inclined towards the latter. |
TG2 discussion, focused on the motivation: https://github.com/tc39/ecma402/blob/main/meetings/notes-2025-04-03.md#normative-add-localeprototypegetvariants-960 |
In accord with #960 (comment) and TG2 discussion, this will be exposed as a string-returning |
c001a65
to
a606142
Compare
This reached consensus in TC39 plenary. |
1. Let _variants_ be GetLocaleVariants(_baseName_). | ||
1. Let _variants_ be ? GetOption(_options_, *"variants"*, ~string~, ~empty~, GetLocaleVariants(_baseName_)). | ||
1. If _variants_ is not *undefined*, then | ||
1. If _variants_ cannot be matched by the <code>unicode_variant_subtag</code> Unicode locale nonterminal, throw a *RangeError* exception. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unicode_variant_subtag
matches a single variant subtag. That means new Intl.Locale("kl-tunumiit-kleinsch")
will now always throw a RangeError
. Probably needs StringSplitToList(variants, "-")
and then check unicode_variant_subtag
on all elements of the returned List.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, nice catch. Fix: #1007.
…nst a subtag sequence Fixes tc39#960
https://bugs.webkit.org/show_bug.cgi?id=294755 Reviewed by NOBODY (OOPS!). tc39/ecma402#960 added `Intl.Locale.prototype.variants` to the ECMAScript specification. The test262 test suite has also been updated [1]. This patch implements `Intl.Locale.prototype.variants` for JSC. [1]: tc39/test262#4474 * JSTests/stress/intl-locale-prototype-variants.js: Added. (shouldBe): (shouldThrow): * JSTests/test262/expectations.yaml: * Source/JavaScriptCore/runtime/CommonIdentifiers.h: * Source/JavaScriptCore/runtime/IntlLocale.cpp: (JSC::LocaleIDBuilder::overrideLanguageScriptRegionVariants): (JSC::IntlLocale::initializeLocale): (JSC::IntlLocale::variants): (JSC::LocaleIDBuilder::overrideLanguageScriptRegion): Deleted. * Source/JavaScriptCore/runtime/IntlLocale.h: * Source/JavaScriptCore/runtime/IntlLocalePrototype.cpp: (JSC::JSC_DEFINE_CUSTOM_GETTER):
https://bugs.webkit.org/show_bug.cgi?id=294755 Reviewed by Yusuke Suzuki. tc39/ecma402#960 added `Intl.Locale.prototype.variants` to the ECMAScript specification. The test262 test suite has also been updated [1]. This patch implements `Intl.Locale.prototype.variants` for JSC. [1]: tc39/test262#4474 * JSTests/stress/intl-locale-prototype-variants.js: Added. (shouldBe): (shouldThrow): * JSTests/test262/expectations.yaml: * Source/JavaScriptCore/runtime/CommonIdentifiers.h: * Source/JavaScriptCore/runtime/IntlLocale.cpp: (JSC::LocaleIDBuilder::overrideLanguageScriptRegionVariants): (JSC::IntlLocale::initializeLocale): (JSC::IntlLocale::variants): (JSC::LocaleIDBuilder::overrideLanguageScriptRegion): Deleted. * Source/JavaScriptCore/runtime/IntlLocale.h: * Source/JavaScriptCore/runtime/IntlLocalePrototype.cpp: (JSC::JSC_DEFINE_CUSTOM_GETTER): Canonical link: https://commits.webkit.org/296467@main
Fixes #900
test262 PR: tc39/test262#4474