Title: [262890] trunk
Revision
262890
Author
ross.kirsl...@sony.com
Date
2020-06-10 19:20:47 -0700 (Wed, 10 Jun 2020)

Log Message

REGRESSION(r260697): [Intl] "missing script" locales like zh-TW are no longer mapped
https://bugs.webkit.org/show_bug.cgi?id=213007

Reviewed by Darin Adler.

JSTests:

* stress/intl-missing-script-locales.js: Added.

Source/_javascript_Core:

addMissingScriptLocales was removed from IntlObject when changing our locale resolution to depend more directly
on ICU, but apparently even latest ICU won't perform this legacy "region implies script" mapping for us.

ICU 65+ does have uloc_openAvailableByType which will do the trick, so perhaps we should use this in the future,
but it still doesn't seem to help us with Collator, which has its own separate set of "available locales".

The exact set of locales which should be mapped is currently under discussion here:
https://github.com/tc39/ecma402/issues/159
But the crux seems to be that we should ensure we have an xx-ZZ alias for all available xx-Yyyy-ZZ locales.

* runtime/IntlObject.cpp:
(JSC::addScriptlessLocaleIfNeeded):
(JSC::intlAvailableLocales):
(JSC::intlCollatorAvailableLocales):

Modified Paths

Added Paths

Diff

Modified: trunk/JSTests/ChangeLog (262889 => 262890)


--- trunk/JSTests/ChangeLog	2020-06-11 02:20:45 UTC (rev 262889)
+++ trunk/JSTests/ChangeLog	2020-06-11 02:20:47 UTC (rev 262890)
@@ -1,3 +1,12 @@
+2020-06-10  Ross Kirsling  <ross.kirsl...@sony.com>
+
+        REGRESSION(r260697): [Intl] "missing script" locales like zh-TW are no longer mapped
+        https://bugs.webkit.org/show_bug.cgi?id=213007
+
+        Reviewed by Darin Adler.
+
+        * stress/intl-missing-script-locales.js: Added.
+
 2020-06-10  Caitlin Potter  <ca...@igalia.com>
 
         [JSC] add stress test for op_get_private_name

Added: trunk/JSTests/stress/intl-missing-script-locales.js (0 => 262890)


--- trunk/JSTests/stress/intl-missing-script-locales.js	                        (rev 0)
+++ trunk/JSTests/stress/intl-missing-script-locales.js	2020-06-11 02:20:47 UTC (rev 262890)
@@ -0,0 +1,21 @@
+function shouldBe(actual, expected) {
+    if (actual !== expected)
+        print(`expected ${expected} but got ${actual}`);
+}
+
+const locales = [
+  ['pa-PK', 'pa-Arab-PK'],
+  ['zh-HK', 'zh-Hant-HK'],
+  ['zh-SG', 'zh-Hans-SG'],
+  ['zh-TW', 'zh-Hant-TW']
+];
+
+// Collator is the only class with differing "available locales";
+// DateTimeFormat is used here as a representative for the rest.
+for (let [alias, locale] of locales) {
+  if (new Intl.Collator(locale).resolvedOptions().locale === locale)
+    shouldBe(new Intl.Collator(alias).resolvedOptions().locale, alias);
+
+  if (new Intl.DateTimeFormat(locale).resolvedOptions().locale === locale)
+    shouldBe(new Intl.DateTimeFormat(alias).resolvedOptions().locale, alias);
+}

Modified: trunk/Source/_javascript_Core/ChangeLog (262889 => 262890)


--- trunk/Source/_javascript_Core/ChangeLog	2020-06-11 02:20:45 UTC (rev 262889)
+++ trunk/Source/_javascript_Core/ChangeLog	2020-06-11 02:20:47 UTC (rev 262890)
@@ -1,3 +1,25 @@
+2020-06-10  Ross Kirsling  <ross.kirsl...@sony.com>
+
+        REGRESSION(r260697): [Intl] "missing script" locales like zh-TW are no longer mapped
+        https://bugs.webkit.org/show_bug.cgi?id=213007
+
+        Reviewed by Darin Adler.
+
+        addMissingScriptLocales was removed from IntlObject when changing our locale resolution to depend more directly
+        on ICU, but apparently even latest ICU won't perform this legacy "region implies script" mapping for us.
+
+        ICU 65+ does have uloc_openAvailableByType which will do the trick, so perhaps we should use this in the future,
+        but it still doesn't seem to help us with Collator, which has its own separate set of "available locales".
+
+        The exact set of locales which should be mapped is currently under discussion here:
+        https://github.com/tc39/ecma402/issues/159
+        But the crux seems to be that we should ensure we have an xx-ZZ alias for all available xx-Yyyy-ZZ locales.
+
+        * runtime/IntlObject.cpp:
+        (JSC::addScriptlessLocaleIfNeeded):
+        (JSC::intlAvailableLocales):
+        (JSC::intlCollatorAvailableLocales):
+
 2020-06-10  Yusuke Suzuki  <ysuz...@apple.com>
 
         [JSC] JSCallbackObject::deleteProperty should redirect to Parent::deletePropertyByIndex if propertyName is index

Modified: trunk/Source/_javascript_Core/runtime/IntlObject.cpp (262889 => 262890)


--- trunk/Source/_javascript_Core/runtime/IntlObject.cpp	2020-06-11 02:20:45 UTC (rev 262889)
+++ trunk/Source/_javascript_Core/runtime/IntlObject.cpp	2020-06-11 02:20:47 UTC (rev 262890)
@@ -188,6 +188,32 @@
     return String(buffer.data(), buffer.size());
 }
 
+// Ensure we have xx-ZZ whenever we have xx-Yyyy-ZZ.
+static void addScriptlessLocaleIfNeeded(HashSet<String>& availableLocales, StringView locale)
+{
+    if (locale.length() < 10)
+        return;
+
+    Vector<StringView, 3> subtags;
+    for (auto subtag : locale.split('-')) {
+        if (subtags.size() == 3)
+            return;
+        subtags.append(subtag);
+    }
+
+    if (subtags.size() < 3 || subtags[1].length() != 4 || subtags[2].length() > 3)
+        return;
+
+    Vector<char, 12> buffer;
+    ASSERT(subtags[0].is8Bit() && subtags[0].isAllASCII());
+    buffer.append(reinterpret_cast<const char*>(subtags[0].characters8()), subtags[0].length());
+    buffer.append('-');
+    ASSERT(subtags[2].is8Bit() && subtags[2].isAllASCII());
+    buffer.append(reinterpret_cast<const char*>(subtags[2].characters8()), subtags[2].length());
+
+    availableLocales.add(StringImpl::createStaticStringImpl(buffer.data(), buffer.size()));
+}
+
 const HashSet<String>& intlAvailableLocales()
 {
     static NeverDestroyed<HashSet<String>> cachedAvailableLocales;
@@ -200,8 +226,10 @@
         int32_t count = uloc_countAvailable();
         for (int32_t i = 0; i < count; ++i) {
             String locale = languageTagForLocaleID(uloc_getAvailable(i), isImmortal);
-            if (!locale.isEmpty())
-                availableLocales.add(locale);
+            if (locale.isEmpty())
+                continue;
+            availableLocales.add(locale);
+            addScriptlessLocaleIfNeeded(availableLocales, locale);
         }
     });
     return availableLocales;
@@ -219,8 +247,10 @@
         int32_t count = ucol_countAvailable();
         for (int32_t i = 0; i < count; ++i) {
             String locale = languageTagForLocaleID(ucol_getAvailable(i), isImmortal);
-            if (!locale.isEmpty())
-                availableLocales.add(locale);
+            if (locale.isEmpty())
+                continue;
+            availableLocales.add(locale);
+            addScriptlessLocaleIfNeeded(availableLocales, locale);
         }
     });
     return availableLocales;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to