Changeset 255120 in webkit
- Timestamp:
- Jan 25, 2020, 9:03:59 AM (5 years ago)
- Location:
- trunk/Source
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r255112 r255120 1 2020-01-24 Mark Lam <mark.lam@apple.com> 2 3 Move singleton Intl string locales out of JSGlobalObject. 4 https://bugs.webkit.org/show_bug.cgi?id=206791 5 <rdar://problem/58889037> 6 7 Reviewed by Yusuke Suzuki and Andy Wagoner. 8 9 We were creating an instance of these for each JSGlobalObject when they can be a 10 global singleton since they are always initialized with the same intl data 11 (barring a mid-flight change in intl settings, which we don't support even in the 12 existing code). 13 14 It turns out that intlPluralRulesAvailableLocales() wasn't called anywhere. 15 IntlPluralRules code currently just uses intlNumberFormatAvailableLocales(). 16 To document that this is intentional, we do the following: 17 1. have IntlPluralRules code call intlPluralRulesAvailableLocales(), and 18 2. have intlPluralRulesAvailableLocales() call intlNumberFormatAvailableLocales() 19 for its implementation. 20 See https://bugs.webkit.org/show_bug.cgi?id=206791#c7 and 21 https://bugs.webkit.org/show_bug.cgi?id=206791#c8. 22 23 In addMissingScriptLocales(), I'm deliberately naming the string with underscores 24 because it's much easier to read pa_PK_String and see that it refers to "pa-PK" 25 as opposed to paPKString. Ditto for zh_CN_String, zh_HK_String, zh_SG_String, 26 and zh_TW_String. 27 28 * runtime/IntlCollator.cpp: 29 (JSC::IntlCollator::initializeCollator): 30 * runtime/IntlCollatorConstructor.cpp: 31 (JSC::IntlCollatorConstructorFuncSupportedLocalesOf): 32 * runtime/IntlDateTimeFormat.cpp: 33 (JSC::IntlDateTimeFormat::initializeDateTimeFormat): 34 * runtime/IntlDateTimeFormatConstructor.cpp: 35 (JSC::IntlDateTimeFormatConstructorFuncSupportedLocalesOf): 36 * runtime/IntlNumberFormat.cpp: 37 (JSC::IntlNumberFormat::initializeNumberFormat): 38 * runtime/IntlNumberFormatConstructor.cpp: 39 (JSC::IntlNumberFormatConstructorFuncSupportedLocalesOf): 40 * runtime/IntlObject.cpp: 41 (JSC::convertICULocaleToBCP47LanguageTag): 42 (JSC::addMissingScriptLocales): 43 (JSC::intlCollatorAvailableLocales): 44 (JSC::intlDateTimeFormatAvailableLocales): 45 (JSC::intlNumberFormatAvailableLocales): 46 (JSC::defaultLocale): 47 * runtime/IntlObject.h: 48 * runtime/IntlPluralRules.cpp: 49 (JSC::IntlPluralRules::initializePluralRules): 50 * runtime/IntlPluralRulesConstructor.cpp: 51 (JSC::IntlPluralRulesConstructorFuncSupportedLocalesOf): 52 * runtime/JSGlobalObject.cpp: 53 (JSC::addMissingScriptLocales): Deleted. 54 (JSC::JSGlobalObject::intlCollatorAvailableLocales): Deleted. 55 (JSC::JSGlobalObject::intlDateTimeFormatAvailableLocales): Deleted. 56 (JSC::JSGlobalObject::intlNumberFormatAvailableLocales): Deleted. 57 (JSC::JSGlobalObject::intlPluralRulesAvailableLocales): Deleted. 58 * runtime/JSGlobalObject.h: 59 1 60 2020-01-24 Mark Lam <mark.lam@apple.com> 2 61 -
trunk/Source/JavaScriptCore/runtime/IntlCollator.cpp
r253019 r255120 2 2 * Copyright (C) 2015 Andy VanWagoner (andy@vanwagoner.family) 3 3 * Copyright (C) 2015 Sukolsak Sakshuwong (sukolsak@gmail.com) 4 * Copyright (C) 2016-20 19Apple Inc. All Rights Reserved.4 * Copyright (C) 2016-2020 Apple Inc. All Rights Reserved. 5 5 * 6 6 * Redistribution and use in source and binary forms, with or without … … 220 220 } 221 221 222 auto& availableLocales = globalObject->intlCollatorAvailableLocales();222 auto& availableLocales = intlCollatorAvailableLocales(); 223 223 auto result = resolveLocale(globalObject, availableLocales, requestedLocales, opt, relevantCollatorExtensionKeys, WTF_ARRAY_LENGTH(relevantCollatorExtensionKeys), localeData); 224 224 -
trunk/Source/JavaScriptCore/runtime/IntlCollatorConstructor.cpp
r252520 r255120 2 2 * Copyright (C) 2015 Andy VanWagoner (andy@vanwagoner.family) 3 3 * Copyright (C) 2015 Sukolsak Sakshuwong (sukolsak@gmail.com) 4 * Copyright (C) 2016 Apple Inc. All Rights Reserved.4 * Copyright (C) 2016-2020 Apple Inc. All Rights Reserved. 5 5 * 6 6 * Redistribution and use in source and binary forms, with or without … … 140 140 141 141 // 3. Return SupportedLocales(%Collator%.[[availableLocales]], requestedLocales, options). 142 RELEASE_AND_RETURN(scope, JSValue::encode(supportedLocales(globalObject, globalObject->intlCollatorAvailableLocales(), requestedLocales, callFrame->argument(1))));142 RELEASE_AND_RETURN(scope, JSValue::encode(supportedLocales(globalObject, intlCollatorAvailableLocales(), requestedLocales, callFrame->argument(1)))); 143 143 } 144 144 -
trunk/Source/JavaScriptCore/runtime/IntlDateTimeFormat.cpp
r253865 r255120 1 1 /* 2 2 * Copyright (C) 2015 Andy VanWagoner (andy@vanwagoner.family) 3 * Copyright (C) 2016-20 19Apple Inc. All rights reserved.3 * Copyright (C) 2016-2020 Apple Inc. All rights reserved. 4 4 * 5 5 * Redistribution and use in source and binary forms, with or without … … 471 471 opt.add("hc"_s, String()); 472 472 473 const HashSet<String> availableLocales = globalObject->intlDateTimeFormatAvailableLocales();473 const HashSet<String>& availableLocales = intlDateTimeFormatAvailableLocales(); 474 474 HashMap<String, String> resolved = resolveLocale(globalObject, availableLocales, requestedLocales, opt, IntlDTFInternal::relevantExtensionKeys, WTF_ARRAY_LENGTH(IntlDTFInternal::relevantExtensionKeys), IntlDTFInternal::localeData); 475 475 -
trunk/Source/JavaScriptCore/runtime/IntlDateTimeFormatConstructor.cpp
r252520 r255120 134 134 135 135 // 1. Let availableLocales be %DateTimeFormat%.[[availableLocales]]. 136 const HashSet<String> availableLocales = globalObject->intlDateTimeFormatAvailableLocales();136 const HashSet<String>& availableLocales = intlDateTimeFormatAvailableLocales(); 137 137 138 138 // 2. Let requestedLocales be CanonicalizeLocaleList(locales). -
trunk/Source/JavaScriptCore/runtime/IntlNumberFormat.cpp
r253865 r255120 2 2 * Copyright (C) 2015 Andy VanWagoner (andy@vanwagoner.family) 3 3 * Copyright (C) 2016 Sukolsak Sakshuwong (sukolsak@gmail.com) 4 * Copyright (C) 2016-20 19Apple Inc. All rights reserved.4 * Copyright (C) 2016-2020 Apple Inc. All rights reserved. 5 5 * 6 6 * Redistribution and use in source and binary forms, with or without … … 180 180 opt.add("localeMatcher"_s, matcher); 181 181 182 auto& availableLocales = globalObject->intlNumberFormatAvailableLocales();182 auto& availableLocales = intlNumberFormatAvailableLocales(); 183 183 auto result = resolveLocale(globalObject, availableLocales, requestedLocales, opt, relevantNumberExtensionKeys, WTF_ARRAY_LENGTH(relevantNumberExtensionKeys), IntlNFInternal::localeData); 184 184 -
trunk/Source/JavaScriptCore/runtime/IntlNumberFormatConstructor.cpp
r252520 r255120 1 1 /* 2 2 * Copyright (C) 2015 Andy VanWagoner (andy@vanwagoner.family) 3 * Copyright (C) 2016 Apple Inc. All Rights Reserved.3 * Copyright (C) 2016-2020 Apple Inc. All Rights Reserved. 4 4 * 5 5 * Redistribution and use in source and binary forms, with or without … … 134 134 135 135 // 1. Let availableLocales be %NumberFormat%.[[availableLocales]]. 136 const HashSet<String> availableLocales = globalObject->intlNumberFormatAvailableLocales();136 const HashSet<String>& availableLocales = intlNumberFormatAvailableLocales(); 137 137 138 138 // 2. Let requestedLocales be CanonicalizeLocaleList(locales). -
trunk/Source/JavaScriptCore/runtime/IntlObject.cpp
r255112 r255120 47 47 #include "ObjectPrototype.h" 48 48 #include "Options.h" 49 #include <unicode/ucol.h> 50 #include <unicode/udat.h> 49 51 #include <unicode/uloc.h> 52 #include <unicode/unum.h> 50 53 #include <unicode/unumsys.h> 51 54 #include <wtf/Assertions.h> … … 53 56 #include <wtf/NeverDestroyed.h> 54 57 #include <wtf/text/StringBuilder.h> 58 #include <wtf/text/StringImpl.h> 55 59 56 60 namespace JSC { … … 129 133 } 130 134 131 String convertICULocaleToBCP47LanguageTag(const char* localeID)135 static String convertICULocaleToBCP47LanguageTag(const char* localeID) 132 136 { 133 137 UErrorCode status = U_ZERO_ERROR; … … 140 144 } 141 145 if (!U_FAILURE(status)) 142 return String( buffer.data(), length);146 return String(StringImpl::createStaticStringImpl(buffer.data(), length)); 143 147 return String(); 148 } 149 150 static void addMissingScriptLocales(HashSet<String>& availableLocales) 151 { 152 static const NeverDestroyed<String> pa_PK_String(MAKE_STATIC_STRING_IMPL("pa-PK")); 153 static const NeverDestroyed<String> zh_CN_String(MAKE_STATIC_STRING_IMPL("zh-CN")); 154 static const NeverDestroyed<String> zh_HK_String(MAKE_STATIC_STRING_IMPL("zh-HK")); 155 static const NeverDestroyed<String> zh_SG_String(MAKE_STATIC_STRING_IMPL("zh-SG")); 156 static const NeverDestroyed<String> zh_TW_String(MAKE_STATIC_STRING_IMPL("zh-TW")); 157 if (availableLocales.contains("pa-Arab-PK")) 158 availableLocales.add(pa_PK_String.get()); 159 if (availableLocales.contains("zh-Hans-CN")) 160 availableLocales.add(zh_CN_String.get()); 161 if (availableLocales.contains("zh-Hant-HK")) 162 availableLocales.add(zh_HK_String.get()); 163 if (availableLocales.contains("zh-Hans-SG")) 164 availableLocales.add(zh_SG_String.get()); 165 if (availableLocales.contains("zh-Hant-TW")) 166 availableLocales.add(zh_TW_String.get()); 167 } 168 169 const HashSet<String>& intlCollatorAvailableLocales() 170 { 171 static NeverDestroyed<HashSet<String>> cachedAvailableLocales; 172 HashSet<String>& availableLocales = cachedAvailableLocales.get(); 173 174 static std::once_flag initializeOnce; 175 std::call_once(initializeOnce, [&] { 176 ASSERT(availableLocales.isEmpty()); 177 int32_t count = ucol_countAvailable(); 178 for (int32_t i = 0; i < count; ++i) { 179 String locale = convertICULocaleToBCP47LanguageTag(ucol_getAvailable(i)); 180 if (!locale.isEmpty()) 181 availableLocales.add(locale); 182 } 183 addMissingScriptLocales(availableLocales); 184 }); 185 return availableLocales; 186 } 187 188 const HashSet<String>& intlDateTimeFormatAvailableLocales() 189 { 190 static NeverDestroyed<HashSet<String>> cachedAvailableLocales; 191 HashSet<String>& availableLocales = cachedAvailableLocales.get(); 192 193 static std::once_flag initializeOnce; 194 std::call_once(initializeOnce, [&] { 195 ASSERT(availableLocales.isEmpty()); 196 int32_t count = udat_countAvailable(); 197 for (int32_t i = 0; i < count; ++i) { 198 String locale = convertICULocaleToBCP47LanguageTag(udat_getAvailable(i)); 199 if (!locale.isEmpty()) 200 availableLocales.add(locale); 201 } 202 addMissingScriptLocales(availableLocales); 203 }); 204 return availableLocales; 205 } 206 207 const HashSet<String>& intlNumberFormatAvailableLocales() 208 { 209 static NeverDestroyed<HashSet<String>> cachedAvailableLocales; 210 HashSet<String>& availableLocales = cachedAvailableLocales.get(); 211 212 static std::once_flag initializeOnce; 213 std::call_once(initializeOnce, [&] { 214 ASSERT(availableLocales.isEmpty()); 215 int32_t count = unum_countAvailable(); 216 for (int32_t i = 0; i < count; ++i) { 217 String locale = convertICULocaleToBCP47LanguageTag(unum_getAvailable(i)); 218 if (!locale.isEmpty()) 219 availableLocales.add(locale); 220 } 221 addMissingScriptLocales(availableLocales); 222 }); 223 return availableLocales; 144 224 } 145 225 … … 623 703 // If all else fails, ask ICU. It will probably say something bogus like en_us even if the user 624 704 // has configured some other language, but being wrong is better than crashing. 625 String locale = convertICULocaleToBCP47LanguageTag(uloc_getDefault()); 626 if (!locale.isEmpty()) 627 return locale; 705 static NeverDestroyed<String> icuDefaultLocalString; 706 static std::once_flag initializeOnce; 707 std::call_once(initializeOnce, [&] { 708 icuDefaultLocalString.get() = convertICULocaleToBCP47LanguageTag(uloc_getDefault()); 709 }); 710 if (!icuDefaultLocalString->isEmpty()) 711 return icuDefaultLocalString.get(); 628 712 629 713 return "en"_s; -
trunk/Source/JavaScriptCore/runtime/IntlObject.h
r251425 r255120 1 1 /* 2 2 * Copyright (C) 2015 Andy VanWagoner (andy@vanwagoner.family) 3 * Copyright (C) 2019 Apple Inc. All rights reserved.3 * Copyright (C) 2019-2020 Apple Inc. All rights reserved. 4 4 * 5 5 * Redistribution and use in source and binary forms, with or without … … 58 58 59 59 String defaultLocale(JSGlobalObject*); 60 String convertICULocaleToBCP47LanguageTag(const char* localeID); 60 const HashSet<String>& intlCollatorAvailableLocales(); 61 const HashSet<String>& intlDateTimeFormatAvailableLocales(); 62 const HashSet<String>& intlNumberFormatAvailableLocales(); 63 inline const HashSet<String>& intlPluralRulesAvailableLocales() { return intlNumberFormatAvailableLocales(); } 64 61 65 bool intlBooleanOption(JSGlobalObject*, JSValue options, PropertyName, bool& usesFallback); 62 66 String intlStringOption(JSGlobalObject*, JSValue options, PropertyName, std::initializer_list<const char*> values, const char* notFound, const char* fallback); -
trunk/Source/JavaScriptCore/runtime/IntlPluralRules.cpp
r253019 r255120 1 1 /* 2 2 * Copyright (C) 2018 Andy VanWagoner (andy@vanwagoner.family) 3 * Copyright (C) 2019 Apple Inc. All rights reserved.3 * Copyright (C) 2019-2020 Apple Inc. All rights reserved. 4 4 * 5 5 * Redistribution and use in source and binary forms, with or without … … 122 122 localeOpt.add(vm.propertyNames->localeMatcher.string(), localeMatcher); 123 123 124 const HashSet<String> availableLocales = globalObject->intlNumberFormatAvailableLocales();124 const HashSet<String>& availableLocales = intlPluralRulesAvailableLocales(); 125 125 HashMap<String, String> resolved = resolveLocale(globalObject, availableLocales, requestedLocales, localeOpt, nullptr, 0, IntlPRInternal::localeData); 126 126 m_locale = resolved.get(vm.propertyNames->locale.string()); -
trunk/Source/JavaScriptCore/runtime/IntlPluralRulesConstructor.cpp
r252520 r255120 1 1 /* 2 2 * Copyright (C) 2018 Andy VanWagoner (andy@vanwagoner.family) 3 * Copyright (C) 2020 Apple Inc. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 118 119 // 13.3.2 Intl.PluralRules.supportedLocalesOf (locales [, options ]) 119 120 // https://tc39.github.io/ecma402/#sec-intl.pluralrules.supportedlocalesof 120 const HashSet<String> availableLocales = globalObject->intlNumberFormatAvailableLocales();121 const HashSet<String>& availableLocales = intlPluralRulesAvailableLocales(); 121 122 122 123 Vector<String> requestedLocales = canonicalizeLocaleList(globalObject, callFrame->argument(0)); -
trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp
r254447 r255120 218 218 #include "IntlPluralRules.h" 219 219 #include "IntlPluralRulesPrototype.h" 220 #include <unicode/ucol.h>221 #include <unicode/udat.h>222 #include <unicode/unum.h>223 220 #endif // ENABLE(INTL) 224 221 … … 2068 2065 } 2069 2066 2070 # if ENABLE(INTL)2071 static void addMissingScriptLocales(HashSet<String>& availableLocales)2072 {2073 if (availableLocales.contains("pa-Arab-PK"))2074 availableLocales.add("pa-PK"_s);2075 if (availableLocales.contains("zh-Hans-CN"))2076 availableLocales.add("zh-CN"_s);2077 if (availableLocales.contains("zh-Hant-HK"))2078 availableLocales.add("zh-HK"_s);2079 if (availableLocales.contains("zh-Hans-SG"))2080 availableLocales.add("zh-SG"_s);2081 if (availableLocales.contains("zh-Hant-TW"))2082 availableLocales.add("zh-TW"_s);2083 }2084 2085 const HashSet<String>& JSGlobalObject::intlCollatorAvailableLocales()2086 {2087 if (m_intlCollatorAvailableLocales.isEmpty()) {2088 int32_t count = ucol_countAvailable();2089 for (int32_t i = 0; i < count; ++i) {2090 String locale = convertICULocaleToBCP47LanguageTag(ucol_getAvailable(i));2091 if (!locale.isEmpty())2092 m_intlCollatorAvailableLocales.add(locale);2093 }2094 addMissingScriptLocales(m_intlCollatorAvailableLocales);2095 }2096 return m_intlCollatorAvailableLocales;2097 }2098 2099 const HashSet<String>& JSGlobalObject::intlDateTimeFormatAvailableLocales()2100 {2101 if (m_intlDateTimeFormatAvailableLocales.isEmpty()) {2102 int32_t count = udat_countAvailable();2103 for (int32_t i = 0; i < count; ++i) {2104 String locale = convertICULocaleToBCP47LanguageTag(udat_getAvailable(i));2105 if (!locale.isEmpty())2106 m_intlDateTimeFormatAvailableLocales.add(locale);2107 }2108 addMissingScriptLocales(m_intlDateTimeFormatAvailableLocales);2109 }2110 return m_intlDateTimeFormatAvailableLocales;2111 }2112 2113 const HashSet<String>& JSGlobalObject::intlNumberFormatAvailableLocales()2114 {2115 if (m_intlNumberFormatAvailableLocales.isEmpty()) {2116 int32_t count = unum_countAvailable();2117 for (int32_t i = 0; i < count; ++i) {2118 String locale = convertICULocaleToBCP47LanguageTag(unum_getAvailable(i));2119 if (!locale.isEmpty())2120 m_intlNumberFormatAvailableLocales.add(locale);2121 }2122 addMissingScriptLocales(m_intlNumberFormatAvailableLocales);2123 }2124 return m_intlNumberFormatAvailableLocales;2125 }2126 2127 const HashSet<String>& JSGlobalObject::intlPluralRulesAvailableLocales()2128 {2129 if (m_intlPluralRulesAvailableLocales.isEmpty()) {2130 int32_t count = uloc_countAvailable();2131 for (int32_t i = 0; i < count; ++i) {2132 String locale = convertICULocaleToBCP47LanguageTag(uloc_getAvailable(i));2133 if (!locale.isEmpty())2134 m_intlPluralRulesAvailableLocales.add(locale);2135 }2136 addMissingScriptLocales(m_intlPluralRulesAvailableLocales);2137 }2138 return m_intlPluralRulesAvailableLocales;2139 }2140 2141 #endif // ENABLE(INTL)2142 2143 2067 void JSGlobalObject::bumpGlobalLexicalBindingEpoch(VM& vm) 2144 2068 { -
trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h
r254252 r255120 436 436 #endif 437 437 438 #if ENABLE(INTL)439 HashSet<String> m_intlCollatorAvailableLocales;440 HashSet<String> m_intlDateTimeFormatAvailableLocales;441 HashSet<String> m_intlNumberFormatAvailableLocales;442 HashSet<String> m_intlPluralRulesAvailableLocales;443 #endif // ENABLE(INTL)444 445 438 RefPtr<WatchpointSet> m_masqueradesAsUndefinedWatchpoint; 446 439 RefPtr<WatchpointSet> m_havingABadTimeWatchpoint; … … 799 792 #endif 800 793 801 #if ENABLE(INTL)802 const HashSet<String>& intlCollatorAvailableLocales();803 const HashSet<String>& intlDateTimeFormatAvailableLocales();804 const HashSet<String>& intlNumberFormatAvailableLocales();805 const HashSet<String>& intlPluralRulesAvailableLocales();806 #endif // ENABLE(INTL)807 808 794 void bumpGlobalLexicalBindingEpoch(VM&); 809 795 unsigned globalLexicalBindingEpoch() const { return m_globalLexicalBindingEpoch; } -
trunk/Source/WTF/ChangeLog
r255112 r255120 1 2020-01-24 Mark Lam <mark.lam@apple.com> 2 3 Move singleton Intl string locales out of JSGlobalObject. 4 https://bugs.webkit.org/show_bug.cgi?id=206791 5 <rdar://problem/58889037> 6 7 Reviewed by Yusuke Suzuki. 8 9 Fix a bug in StringImpl::createStaticStringImpl(): I forgot to set its hash value 10 when I introduced it. StaticStringImpls require that its hash code be set ahead 11 of time, and cannot be mutated at runtime. See the comment in the definition of 12 StaticStringImpl in StringImpl.h. 13 14 * wtf/text/StringImpl.cpp: 15 (WTF::StringImpl::createStaticStringImpl): 16 1 17 2020-01-24 Mark Lam <mark.lam@apple.com> 2 18 -
trunk/Source/WTF/wtf/text/StringImpl.cpp
r255112 r255120 284 284 Ref<StringImpl> StringImpl::createStaticStringImpl(const char* characters, unsigned length) 285 285 { 286 ASSERT(charactersAreAllASCII<LChar>(reinterpret_cast<const LChar*>(characters), length)); 287 Ref<StringImpl> result = createInternal(reinterpret_cast<const LChar*>(characters), length); 286 const LChar* lcharCharacters = reinterpret_cast<const LChar*>(characters); 287 ASSERT(charactersAreAllASCII<LChar>(lcharCharacters, length)); 288 Ref<StringImpl> result = createInternal(lcharCharacters, length); 289 result->setHash(StringHasher::computeHashAndMaskTop8Bits(lcharCharacters, length)); 288 290 result->m_refCount |= s_refCountFlagIsStaticString; 289 291 return result;
Note:
See TracChangeset
for help on using the changeset viewer.