Commit 7bf5c54f authored by Yury Semikhatsky's avatar Yury Semikhatsky Committed by Commit Bot

Clear cached ICU objects when default locale changes

This is a follow-up fix for https://crrev.com/c/v8/v8/+/1491608

Bug: chromium:1051186
Change-Id: Ia76ad0e7665fe17013b45816350238c35e7199f6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2049899Reviewed-by: 's avatarFrank Tang <ftang@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarDan Elphick <delphick@chromium.org>
Commit-Queue: Dan Elphick <delphick@chromium.org>
Auto-Submit: Yury Semikhatsky <yurys@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67184}
parent ab547021
......@@ -9148,6 +9148,7 @@ void v8::Isolate::LocaleConfigurationChangeNotification() {
#ifdef V8_INTL_SUPPORT
i_isolate->ResetDefaultLocale();
i_isolate->ClearCachedIcuObjects();
#endif // V8_INTL_SUPPORT
}
......
......@@ -4420,6 +4420,9 @@ void Isolate::set_icu_object_in_cache(ICUObjectCacheType cache_type,
void Isolate::clear_cached_icu_object(ICUObjectCacheType cache_type) {
icu_object_cache_.erase(cache_type);
}
void Isolate::ClearCachedIcuObjects() { icu_object_cache_.clear(); }
#endif // V8_INTL_SUPPORT
bool StackLimitCheck::JsHasOverflowed(uintptr_t gap) const {
......
......@@ -1173,6 +1173,7 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
void set_icu_object_in_cache(ICUObjectCacheType cache_type,
std::shared_ptr<icu::UMemory> obj);
void clear_cached_icu_object(ICUObjectCacheType cache_type);
void ClearCachedIcuObjects();
#endif // V8_INTL_SUPPORT
......
......@@ -170,6 +170,7 @@ v8_source_set("cctest_sources") {
"test-allocation.cc",
"test-api-accessors.cc",
"test-api-array-buffer.cc",
"test-api-icu.cc",
"test-api-interceptors.cc",
"test-api-stack-traces.cc",
"test-api-typed-array.cc",
......
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifdef V8_INTL_SUPPORT
#include <stdlib.h>
#include "include/v8.h"
#include "src/objects/objects-inl.h"
#include "test/cctest/cctest.h"
#include "unicode/locid.h"
namespace {
void CheckLocaleSpecificValues(const char* locale, const char* date,
const char* number) {
CHECK(v8_str(locale)->StrictEquals(
CompileRun("Intl.NumberFormat().resolvedOptions().locale")));
CHECK(v8_str(date)->StrictEquals(
CompileRun("new Date('02/14/2020 13:45').toLocaleString()")));
CHECK(v8_str(number)->StrictEquals(
CompileRun("Number(10000.3).toLocaleString()")));
}
void SetIcuLocale(const char* locale_name) {
UErrorCode error_code = U_ZERO_ERROR;
icu::Locale locale(locale_name);
icu::Locale::setDefault(locale, error_code);
CHECK(U_SUCCESS(error_code));
}
} // namespace
TEST(LocaleConfigurationChangeNotification) {
icu::Locale default_locale = icu::Locale::getDefault();
LocalContext context;
v8::Isolate* isolate = context->GetIsolate();
v8::HandleScope scope(isolate);
SetIcuLocale("en_US");
isolate->LocaleConfigurationChangeNotification();
CheckLocaleSpecificValues("en-US", "2/14/2020, 1:45:00 PM", "10,000.3");
SetIcuLocale("ru_RU");
isolate->LocaleConfigurationChangeNotification();
CheckLocaleSpecificValues("ru-RU", "14.02.2020, 13:45:00", "10 000,3");
SetIcuLocale("zn_CN");
isolate->LocaleConfigurationChangeNotification();
CheckLocaleSpecificValues("zn-CN", "2020-2-14 13:45:00", "10,000.3");
UErrorCode error_code = U_ZERO_ERROR;
icu::Locale::setDefault(default_locale, error_code);
CHECK(U_SUCCESS(error_code));
}
#endif // V8_INTL_SUPPORT
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment