Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (255119 => 255120)
--- trunk/Source/_javascript_Core/ChangeLog 2020-01-25 16:51:34 UTC (rev 255119)
+++ trunk/Source/_javascript_Core/ChangeLog 2020-01-25 17:03:59 UTC (rev 255120)
@@ -1,5 +1,64 @@
2020-01-24 Mark Lam <[email protected]>
+ Move singleton Intl string locales out of JSGlobalObject.
+ https://bugs.webkit.org/show_bug.cgi?id=206791
+ <rdar://problem/58889037>
+
+ Reviewed by Yusuke Suzuki and Andy Wagoner.
+
+ We were creating an instance of these for each JSGlobalObject when they can be a
+ global singleton since they are always initialized with the same intl data
+ (barring a mid-flight change in intl settings, which we don't support even in the
+ existing code).
+
+ It turns out that intlPluralRulesAvailableLocales() wasn't called anywhere.
+ IntlPluralRules code currently just uses intlNumberFormatAvailableLocales().
+ To document that this is intentional, we do the following:
+ 1. have IntlPluralRules code call intlPluralRulesAvailableLocales(), and
+ 2. have intlPluralRulesAvailableLocales() call intlNumberFormatAvailableLocales()
+ for its implementation.
+ See https://bugs.webkit.org/show_bug.cgi?id=206791#c7 and
+ https://bugs.webkit.org/show_bug.cgi?id=206791#c8.
+
+ In addMissingScriptLocales(), I'm deliberately naming the string with underscores
+ because it's much easier to read pa_PK_String and see that it refers to "pa-PK"
+ as opposed to paPKString. Ditto for zh_CN_String, zh_HK_String, zh_SG_String,
+ and zh_TW_String.
+
+ * runtime/IntlCollator.cpp:
+ (JSC::IntlCollator::initializeCollator):
+ * runtime/IntlCollatorConstructor.cpp:
+ (JSC::IntlCollatorConstructorFuncSupportedLocalesOf):
+ * runtime/IntlDateTimeFormat.cpp:
+ (JSC::IntlDateTimeFormat::initializeDateTimeFormat):
+ * runtime/IntlDateTimeFormatConstructor.cpp:
+ (JSC::IntlDateTimeFormatConstructorFuncSupportedLocalesOf):
+ * runtime/IntlNumberFormat.cpp:
+ (JSC::IntlNumberFormat::initializeNumberFormat):
+ * runtime/IntlNumberFormatConstructor.cpp:
+ (JSC::IntlNumberFormatConstructorFuncSupportedLocalesOf):
+ * runtime/IntlObject.cpp:
+ (JSC::convertICULocaleToBCP47LanguageTag):
+ (JSC::addMissingScriptLocales):
+ (JSC::intlCollatorAvailableLocales):
+ (JSC::intlDateTimeFormatAvailableLocales):
+ (JSC::intlNumberFormatAvailableLocales):
+ (JSC::defaultLocale):
+ * runtime/IntlObject.h:
+ * runtime/IntlPluralRules.cpp:
+ (JSC::IntlPluralRules::initializePluralRules):
+ * runtime/IntlPluralRulesConstructor.cpp:
+ (JSC::IntlPluralRulesConstructorFuncSupportedLocalesOf):
+ * runtime/JSGlobalObject.cpp:
+ (JSC::addMissingScriptLocales): Deleted.
+ (JSC::JSGlobalObject::intlCollatorAvailableLocales): Deleted.
+ (JSC::JSGlobalObject::intlDateTimeFormatAvailableLocales): Deleted.
+ (JSC::JSGlobalObject::intlNumberFormatAvailableLocales): Deleted.
+ (JSC::JSGlobalObject::intlPluralRulesAvailableLocales): Deleted.
+ * runtime/JSGlobalObject.h:
+
+2020-01-24 Mark Lam <[email protected]>
+
IntlObject's cached strings should be immortal and safe for concurrent access.
https://bugs.webkit.org/show_bug.cgi?id=206779
<rdar://problem/58831763>
Modified: trunk/Source/_javascript_Core/runtime/IntlCollator.cpp (255119 => 255120)
--- trunk/Source/_javascript_Core/runtime/IntlCollator.cpp 2020-01-25 16:51:34 UTC (rev 255119)
+++ trunk/Source/_javascript_Core/runtime/IntlCollator.cpp 2020-01-25 17:03:59 UTC (rev 255120)
@@ -1,7 +1,7 @@
/*
* Copyright (C) 2015 Andy VanWagoner ([email protected])
* Copyright (C) 2015 Sukolsak Sakshuwong ([email protected])
- * Copyright (C) 2016-2019 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2016-2020 Apple Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -219,7 +219,7 @@
opt.add("kf"_s, caseFirst);
}
- auto& availableLocales = globalObject->intlCollatorAvailableLocales();
+ auto& availableLocales = intlCollatorAvailableLocales();
auto result = resolveLocale(globalObject, availableLocales, requestedLocales, opt, relevantCollatorExtensionKeys, WTF_ARRAY_LENGTH(relevantCollatorExtensionKeys), localeData);
m_locale = result.get("locale"_s);
Modified: trunk/Source/_javascript_Core/runtime/IntlCollatorConstructor.cpp (255119 => 255120)
--- trunk/Source/_javascript_Core/runtime/IntlCollatorConstructor.cpp 2020-01-25 16:51:34 UTC (rev 255119)
+++ trunk/Source/_javascript_Core/runtime/IntlCollatorConstructor.cpp 2020-01-25 17:03:59 UTC (rev 255120)
@@ -1,7 +1,7 @@
/*
* Copyright (C) 2015 Andy VanWagoner ([email protected])
* Copyright (C) 2015 Sukolsak Sakshuwong ([email protected])
- * Copyright (C) 2016 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2016-2020 Apple Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -139,7 +139,7 @@
RETURN_IF_EXCEPTION(scope, encodedJSValue());
// 3. Return SupportedLocales(%Collator%.[[availableLocales]], requestedLocales, options).
- RELEASE_AND_RETURN(scope, JSValue::encode(supportedLocales(globalObject, globalObject->intlCollatorAvailableLocales(), requestedLocales, callFrame->argument(1))));
+ RELEASE_AND_RETURN(scope, JSValue::encode(supportedLocales(globalObject, intlCollatorAvailableLocales(), requestedLocales, callFrame->argument(1))));
}
} // namespace JSC
Modified: trunk/Source/_javascript_Core/runtime/IntlDateTimeFormat.cpp (255119 => 255120)
--- trunk/Source/_javascript_Core/runtime/IntlDateTimeFormat.cpp 2020-01-25 16:51:34 UTC (rev 255119)
+++ trunk/Source/_javascript_Core/runtime/IntlDateTimeFormat.cpp 2020-01-25 17:03:59 UTC (rev 255120)
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2015 Andy VanWagoner ([email protected])
- * Copyright (C) 2016-2019 Apple Inc. All rights reserved.
+ * Copyright (C) 2016-2020 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -470,7 +470,7 @@
} else
opt.add("hc"_s, String());
- const HashSet<String> availableLocales = globalObject->intlDateTimeFormatAvailableLocales();
+ const HashSet<String>& availableLocales = intlDateTimeFormatAvailableLocales();
HashMap<String, String> resolved = resolveLocale(globalObject, availableLocales, requestedLocales, opt, IntlDTFInternal::relevantExtensionKeys, WTF_ARRAY_LENGTH(IntlDTFInternal::relevantExtensionKeys), IntlDTFInternal::localeData);
m_locale = resolved.get(vm.propertyNames->locale.string());
Modified: trunk/Source/_javascript_Core/runtime/IntlDateTimeFormatConstructor.cpp (255119 => 255120)
--- trunk/Source/_javascript_Core/runtime/IntlDateTimeFormatConstructor.cpp 2020-01-25 16:51:34 UTC (rev 255119)
+++ trunk/Source/_javascript_Core/runtime/IntlDateTimeFormatConstructor.cpp 2020-01-25 17:03:59 UTC (rev 255120)
@@ -133,7 +133,7 @@
// 12.2.2 Intl.DateTimeFormat.supportedLocalesOf(locales [, options]) (ECMA-402 2.0)
// 1. Let availableLocales be %DateTimeFormat%.[[availableLocales]].
- const HashSet<String> availableLocales = globalObject->intlDateTimeFormatAvailableLocales();
+ const HashSet<String>& availableLocales = intlDateTimeFormatAvailableLocales();
// 2. Let requestedLocales be CanonicalizeLocaleList(locales).
Vector<String> requestedLocales = canonicalizeLocaleList(globalObject, callFrame->argument(0));
Modified: trunk/Source/_javascript_Core/runtime/IntlNumberFormat.cpp (255119 => 255120)
--- trunk/Source/_javascript_Core/runtime/IntlNumberFormat.cpp 2020-01-25 16:51:34 UTC (rev 255119)
+++ trunk/Source/_javascript_Core/runtime/IntlNumberFormat.cpp 2020-01-25 17:03:59 UTC (rev 255120)
@@ -1,7 +1,7 @@
/*
* Copyright (C) 2015 Andy VanWagoner ([email protected])
* Copyright (C) 2016 Sukolsak Sakshuwong ([email protected])
- * Copyright (C) 2016-2019 Apple Inc. All rights reserved.
+ * Copyright (C) 2016-2020 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -179,7 +179,7 @@
RETURN_IF_EXCEPTION(scope, void());
opt.add("localeMatcher"_s, matcher);
- auto& availableLocales = globalObject->intlNumberFormatAvailableLocales();
+ auto& availableLocales = intlNumberFormatAvailableLocales();
auto result = resolveLocale(globalObject, availableLocales, requestedLocales, opt, relevantNumberExtensionKeys, WTF_ARRAY_LENGTH(relevantNumberExtensionKeys), IntlNFInternal::localeData);
m_locale = result.get("locale"_s);
Modified: trunk/Source/_javascript_Core/runtime/IntlNumberFormatConstructor.cpp (255119 => 255120)
--- trunk/Source/_javascript_Core/runtime/IntlNumberFormatConstructor.cpp 2020-01-25 16:51:34 UTC (rev 255119)
+++ trunk/Source/_javascript_Core/runtime/IntlNumberFormatConstructor.cpp 2020-01-25 17:03:59 UTC (rev 255120)
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2015 Andy VanWagoner ([email protected])
- * Copyright (C) 2016 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2016-2020 Apple Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -133,7 +133,7 @@
// 11.2.2 Intl.NumberFormat.supportedLocalesOf(locales [, options]) (ECMA-402 2.0)
// 1. Let availableLocales be %NumberFormat%.[[availableLocales]].
- const HashSet<String> availableLocales = globalObject->intlNumberFormatAvailableLocales();
+ const HashSet<String>& availableLocales = intlNumberFormatAvailableLocales();
// 2. Let requestedLocales be CanonicalizeLocaleList(locales).
Vector<String> requestedLocales = canonicalizeLocaleList(globalObject, callFrame->argument(0));
Modified: trunk/Source/_javascript_Core/runtime/IntlObject.cpp (255119 => 255120)
--- trunk/Source/_javascript_Core/runtime/IntlObject.cpp 2020-01-25 16:51:34 UTC (rev 255119)
+++ trunk/Source/_javascript_Core/runtime/IntlObject.cpp 2020-01-25 17:03:59 UTC (rev 255120)
@@ -46,12 +46,16 @@
#include "Lookup.h"
#include "ObjectPrototype.h"
#include "Options.h"
+#include <unicode/ucol.h>
+#include <unicode/udat.h>
#include <unicode/uloc.h>
+#include <unicode/unum.h>
#include <unicode/unumsys.h>
#include <wtf/Assertions.h>
#include <wtf/Language.h>
#include <wtf/NeverDestroyed.h>
#include <wtf/text/StringBuilder.h>
+#include <wtf/text/StringImpl.h>
namespace JSC {
@@ -128,7 +132,7 @@
return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
}
-String convertICULocaleToBCP47LanguageTag(const char* localeID)
+static String convertICULocaleToBCP47LanguageTag(const char* localeID)
{
UErrorCode status = U_ZERO_ERROR;
Vector<char, 32> buffer(32);
@@ -139,10 +143,86 @@
uloc_toLanguageTag(localeID, buffer.data(), buffer.size(), false, &status);
}
if (!U_FAILURE(status))
- return String(buffer.data(), length);
+ return String(StringImpl::createStaticStringImpl(buffer.data(), length));
return String();
}
+static void addMissingScriptLocales(HashSet<String>& availableLocales)
+{
+ static const NeverDestroyed<String> pa_PK_String(MAKE_STATIC_STRING_IMPL("pa-PK"));
+ static const NeverDestroyed<String> zh_CN_String(MAKE_STATIC_STRING_IMPL("zh-CN"));
+ static const NeverDestroyed<String> zh_HK_String(MAKE_STATIC_STRING_IMPL("zh-HK"));
+ static const NeverDestroyed<String> zh_SG_String(MAKE_STATIC_STRING_IMPL("zh-SG"));
+ static const NeverDestroyed<String> zh_TW_String(MAKE_STATIC_STRING_IMPL("zh-TW"));
+ if (availableLocales.contains("pa-Arab-PK"))
+ availableLocales.add(pa_PK_String.get());
+ if (availableLocales.contains("zh-Hans-CN"))
+ availableLocales.add(zh_CN_String.get());
+ if (availableLocales.contains("zh-Hant-HK"))
+ availableLocales.add(zh_HK_String.get());
+ if (availableLocales.contains("zh-Hans-SG"))
+ availableLocales.add(zh_SG_String.get());
+ if (availableLocales.contains("zh-Hant-TW"))
+ availableLocales.add(zh_TW_String.get());
+}
+
+const HashSet<String>& intlCollatorAvailableLocales()
+{
+ static NeverDestroyed<HashSet<String>> cachedAvailableLocales;
+ HashSet<String>& availableLocales = cachedAvailableLocales.get();
+
+ static std::once_flag initializeOnce;
+ std::call_once(initializeOnce, [&] {
+ ASSERT(availableLocales.isEmpty());
+ int32_t count = ucol_countAvailable();
+ for (int32_t i = 0; i < count; ++i) {
+ String locale = convertICULocaleToBCP47LanguageTag(ucol_getAvailable(i));
+ if (!locale.isEmpty())
+ availableLocales.add(locale);
+ }
+ addMissingScriptLocales(availableLocales);
+ });
+ return availableLocales;
+}
+
+const HashSet<String>& intlDateTimeFormatAvailableLocales()
+{
+ static NeverDestroyed<HashSet<String>> cachedAvailableLocales;
+ HashSet<String>& availableLocales = cachedAvailableLocales.get();
+
+ static std::once_flag initializeOnce;
+ std::call_once(initializeOnce, [&] {
+ ASSERT(availableLocales.isEmpty());
+ int32_t count = udat_countAvailable();
+ for (int32_t i = 0; i < count; ++i) {
+ String locale = convertICULocaleToBCP47LanguageTag(udat_getAvailable(i));
+ if (!locale.isEmpty())
+ availableLocales.add(locale);
+ }
+ addMissingScriptLocales(availableLocales);
+ });
+ return availableLocales;
+}
+
+const HashSet<String>& intlNumberFormatAvailableLocales()
+{
+ static NeverDestroyed<HashSet<String>> cachedAvailableLocales;
+ HashSet<String>& availableLocales = cachedAvailableLocales.get();
+
+ static std::once_flag initializeOnce;
+ std::call_once(initializeOnce, [&] {
+ ASSERT(availableLocales.isEmpty());
+ int32_t count = unum_countAvailable();
+ for (int32_t i = 0; i < count; ++i) {
+ String locale = convertICULocaleToBCP47LanguageTag(unum_getAvailable(i));
+ if (!locale.isEmpty())
+ availableLocales.add(locale);
+ }
+ addMissingScriptLocales(availableLocales);
+ });
+ return availableLocales;
+}
+
bool intlBooleanOption(JSGlobalObject* globalObject, JSValue options, PropertyName property, bool& usesFallback)
{
// GetOption (options, property, type="boolean", values, fallback)
@@ -622,9 +702,13 @@
// If all else fails, ask ICU. It will probably say something bogus like en_us even if the user
// has configured some other language, but being wrong is better than crashing.
- String locale = convertICULocaleToBCP47LanguageTag(uloc_getDefault());
- if (!locale.isEmpty())
- return locale;
+ static NeverDestroyed<String> icuDefaultLocalString;
+ static std::once_flag initializeOnce;
+ std::call_once(initializeOnce, [&] {
+ icuDefaultLocalString.get() = convertICULocaleToBCP47LanguageTag(uloc_getDefault());
+ });
+ if (!icuDefaultLocalString->isEmpty())
+ return icuDefaultLocalString.get();
return "en"_s;
}
Modified: trunk/Source/_javascript_Core/runtime/IntlObject.h (255119 => 255120)
--- trunk/Source/_javascript_Core/runtime/IntlObject.h 2020-01-25 16:51:34 UTC (rev 255119)
+++ trunk/Source/_javascript_Core/runtime/IntlObject.h 2020-01-25 17:03:59 UTC (rev 255120)
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2015 Andy VanWagoner ([email protected])
- * Copyright (C) 2019 Apple Inc. All rights reserved.
+ * Copyright (C) 2019-2020 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -57,7 +57,11 @@
};
String defaultLocale(JSGlobalObject*);
-String convertICULocaleToBCP47LanguageTag(const char* localeID);
+const HashSet<String>& intlCollatorAvailableLocales();
+const HashSet<String>& intlDateTimeFormatAvailableLocales();
+const HashSet<String>& intlNumberFormatAvailableLocales();
+inline const HashSet<String>& intlPluralRulesAvailableLocales() { return intlNumberFormatAvailableLocales(); }
+
bool intlBooleanOption(JSGlobalObject*, JSValue options, PropertyName, bool& usesFallback);
String intlStringOption(JSGlobalObject*, JSValue options, PropertyName, std::initializer_list<const char*> values, const char* notFound, const char* fallback);
unsigned intlNumberOption(JSGlobalObject*, JSValue options, PropertyName, unsigned minimum, unsigned maximum, unsigned fallback);
Modified: trunk/Source/_javascript_Core/runtime/IntlPluralRules.cpp (255119 => 255120)
--- trunk/Source/_javascript_Core/runtime/IntlPluralRules.cpp 2020-01-25 16:51:34 UTC (rev 255119)
+++ trunk/Source/_javascript_Core/runtime/IntlPluralRules.cpp 2020-01-25 17:03:59 UTC (rev 255120)
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2018 Andy VanWagoner ([email protected])
- * Copyright (C) 2019 Apple Inc. All rights reserved.
+ * Copyright (C) 2019-2020 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -121,7 +121,7 @@
RETURN_IF_EXCEPTION(scope, void());
localeOpt.add(vm.propertyNames->localeMatcher.string(), localeMatcher);
- const HashSet<String> availableLocales = globalObject->intlNumberFormatAvailableLocales();
+ const HashSet<String>& availableLocales = intlPluralRulesAvailableLocales();
HashMap<String, String> resolved = resolveLocale(globalObject, availableLocales, requestedLocales, localeOpt, nullptr, 0, IntlPRInternal::localeData);
m_locale = resolved.get(vm.propertyNames->locale.string());
if (m_locale.isEmpty()) {
Modified: trunk/Source/_javascript_Core/runtime/IntlPluralRulesConstructor.cpp (255119 => 255120)
--- trunk/Source/_javascript_Core/runtime/IntlPluralRulesConstructor.cpp 2020-01-25 16:51:34 UTC (rev 255119)
+++ trunk/Source/_javascript_Core/runtime/IntlPluralRulesConstructor.cpp 2020-01-25 17:03:59 UTC (rev 255120)
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2018 Andy VanWagoner ([email protected])
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -117,7 +118,7 @@
// 13.3.2 Intl.PluralRules.supportedLocalesOf (locales [, options ])
// https://tc39.github.io/ecma402/#sec-intl.pluralrules.supportedlocalesof
- const HashSet<String> availableLocales = globalObject->intlNumberFormatAvailableLocales();
+ const HashSet<String>& availableLocales = intlPluralRulesAvailableLocales();
Vector<String> requestedLocales = canonicalizeLocaleList(globalObject, callFrame->argument(0));
RETURN_IF_EXCEPTION(scope, encodedJSValue());
Modified: trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp (255119 => 255120)
--- trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp 2020-01-25 16:51:34 UTC (rev 255119)
+++ trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp 2020-01-25 17:03:59 UTC (rev 255120)
@@ -217,9 +217,6 @@
#include "IntlObject.h"
#include "IntlPluralRules.h"
#include "IntlPluralRulesPrototype.h"
-#include <unicode/ucol.h>
-#include <unicode/udat.h>
-#include <unicode/unum.h>
#endif // ENABLE(INTL)
#if ENABLE(REMOTE_INSPECTOR)
@@ -2067,79 +2064,6 @@
#endif
}
-# if ENABLE(INTL)
-static void addMissingScriptLocales(HashSet<String>& availableLocales)
-{
- if (availableLocales.contains("pa-Arab-PK"))
- availableLocales.add("pa-PK"_s);
- if (availableLocales.contains("zh-Hans-CN"))
- availableLocales.add("zh-CN"_s);
- if (availableLocales.contains("zh-Hant-HK"))
- availableLocales.add("zh-HK"_s);
- if (availableLocales.contains("zh-Hans-SG"))
- availableLocales.add("zh-SG"_s);
- if (availableLocales.contains("zh-Hant-TW"))
- availableLocales.add("zh-TW"_s);
-}
-
-const HashSet<String>& JSGlobalObject::intlCollatorAvailableLocales()
-{
- if (m_intlCollatorAvailableLocales.isEmpty()) {
- int32_t count = ucol_countAvailable();
- for (int32_t i = 0; i < count; ++i) {
- String locale = convertICULocaleToBCP47LanguageTag(ucol_getAvailable(i));
- if (!locale.isEmpty())
- m_intlCollatorAvailableLocales.add(locale);
- }
- addMissingScriptLocales(m_intlCollatorAvailableLocales);
- }
- return m_intlCollatorAvailableLocales;
-}
-
-const HashSet<String>& JSGlobalObject::intlDateTimeFormatAvailableLocales()
-{
- if (m_intlDateTimeFormatAvailableLocales.isEmpty()) {
- int32_t count = udat_countAvailable();
- for (int32_t i = 0; i < count; ++i) {
- String locale = convertICULocaleToBCP47LanguageTag(udat_getAvailable(i));
- if (!locale.isEmpty())
- m_intlDateTimeFormatAvailableLocales.add(locale);
- }
- addMissingScriptLocales(m_intlDateTimeFormatAvailableLocales);
- }
- return m_intlDateTimeFormatAvailableLocales;
-}
-
-const HashSet<String>& JSGlobalObject::intlNumberFormatAvailableLocales()
-{
- if (m_intlNumberFormatAvailableLocales.isEmpty()) {
- int32_t count = unum_countAvailable();
- for (int32_t i = 0; i < count; ++i) {
- String locale = convertICULocaleToBCP47LanguageTag(unum_getAvailable(i));
- if (!locale.isEmpty())
- m_intlNumberFormatAvailableLocales.add(locale);
- }
- addMissingScriptLocales(m_intlNumberFormatAvailableLocales);
- }
- return m_intlNumberFormatAvailableLocales;
-}
-
-const HashSet<String>& JSGlobalObject::intlPluralRulesAvailableLocales()
-{
- if (m_intlPluralRulesAvailableLocales.isEmpty()) {
- int32_t count = uloc_countAvailable();
- for (int32_t i = 0; i < count; ++i) {
- String locale = convertICULocaleToBCP47LanguageTag(uloc_getAvailable(i));
- if (!locale.isEmpty())
- m_intlPluralRulesAvailableLocales.add(locale);
- }
- addMissingScriptLocales(m_intlPluralRulesAvailableLocales);
- }
- return m_intlPluralRulesAvailableLocales;
-}
-
-#endif // ENABLE(INTL)
-
void JSGlobalObject::bumpGlobalLexicalBindingEpoch(VM& vm)
{
if (++m_globalLexicalBindingEpoch == Options::thresholdForGlobalLexicalBindingEpoch()) {
Modified: trunk/Source/_javascript_Core/runtime/JSGlobalObject.h (255119 => 255120)
--- trunk/Source/_javascript_Core/runtime/JSGlobalObject.h 2020-01-25 16:51:34 UTC (rev 255119)
+++ trunk/Source/_javascript_Core/runtime/JSGlobalObject.h 2020-01-25 17:03:59 UTC (rev 255120)
@@ -435,13 +435,6 @@
std::unique_ptr<JSGlobalObjectDebuggable> m_inspectorDebuggable;
#endif
-#if ENABLE(INTL)
- HashSet<String> m_intlCollatorAvailableLocales;
- HashSet<String> m_intlDateTimeFormatAvailableLocales;
- HashSet<String> m_intlNumberFormatAvailableLocales;
- HashSet<String> m_intlPluralRulesAvailableLocales;
-#endif // ENABLE(INTL)
-
RefPtr<WatchpointSet> m_masqueradesAsUndefinedWatchpoint;
RefPtr<WatchpointSet> m_havingABadTimeWatchpoint;
RefPtr<WatchpointSet> m_varInjectionWatchpoint;
@@ -798,13 +791,6 @@
JSGlobalObjectDebuggable& inspectorDebuggable() { return *m_inspectorDebuggable.get(); }
#endif
-#if ENABLE(INTL)
- const HashSet<String>& intlCollatorAvailableLocales();
- const HashSet<String>& intlDateTimeFormatAvailableLocales();
- const HashSet<String>& intlNumberFormatAvailableLocales();
- const HashSet<String>& intlPluralRulesAvailableLocales();
-#endif // ENABLE(INTL)
-
void bumpGlobalLexicalBindingEpoch(VM&);
unsigned globalLexicalBindingEpoch() const { return m_globalLexicalBindingEpoch; }
static ptrdiff_t globalLexicalBindingEpochOffset() { return OBJECT_OFFSETOF(JSGlobalObject, m_globalLexicalBindingEpoch); }
Modified: trunk/Source/WTF/ChangeLog (255119 => 255120)
--- trunk/Source/WTF/ChangeLog 2020-01-25 16:51:34 UTC (rev 255119)
+++ trunk/Source/WTF/ChangeLog 2020-01-25 17:03:59 UTC (rev 255120)
@@ -1,5 +1,21 @@
2020-01-24 Mark Lam <[email protected]>
+ Move singleton Intl string locales out of JSGlobalObject.
+ https://bugs.webkit.org/show_bug.cgi?id=206791
+ <rdar://problem/58889037>
+
+ Reviewed by Yusuke Suzuki.
+
+ Fix a bug in StringImpl::createStaticStringImpl(): I forgot to set its hash value
+ when I introduced it. StaticStringImpls require that its hash code be set ahead
+ of time, and cannot be mutated at runtime. See the comment in the definition of
+ StaticStringImpl in StringImpl.h.
+
+ * wtf/text/StringImpl.cpp:
+ (WTF::StringImpl::createStaticStringImpl):
+
+2020-01-24 Mark Lam <[email protected]>
+
IntlObject's cached strings should be immortal and safe for concurrent access.
https://bugs.webkit.org/show_bug.cgi?id=206779
<rdar://problem/58831763>
Modified: trunk/Source/WTF/wtf/text/StringImpl.cpp (255119 => 255120)
--- trunk/Source/WTF/wtf/text/StringImpl.cpp 2020-01-25 16:51:34 UTC (rev 255119)
+++ trunk/Source/WTF/wtf/text/StringImpl.cpp 2020-01-25 17:03:59 UTC (rev 255120)
@@ -283,8 +283,10 @@
Ref<StringImpl> StringImpl::createStaticStringImpl(const char* characters, unsigned length)
{
- ASSERT(charactersAreAllASCII<LChar>(reinterpret_cast<const LChar*>(characters), length));
- Ref<StringImpl> result = createInternal(reinterpret_cast<const LChar*>(characters), length);
+ const LChar* lcharCharacters = reinterpret_cast<const LChar*>(characters);
+ ASSERT(charactersAreAllASCII<LChar>(lcharCharacters, length));
+ Ref<StringImpl> result = createInternal(lcharCharacters, length);
+ result->setHash(StringHasher::computeHashAndMaskTop8Bits(lcharCharacters, length));
result->m_refCount |= s_refCountFlagIsStaticString;
return result;
}