Commit 7afd712a authored by pgorszkowski's avatar pgorszkowski Committed by Commit bot

Invalidate defaultObjects if timezone changes

In case of calling 'toLocaleString', 'toLocaleTimeString' and
'toLocaleDateString' functions of 'Date' with empty 'locales' and
'options', DateTimeFormat is cached inside 'defaultObjects'.
If we change the timezone the cache is not invalidated.

BUG=v8:5022
TEST=cctest:DateCacheVersion. See the bug
CQ_INCLUDE_TRYBOTS=tryserver.v8:v8_linux_noi18n_rel_ng

Review-Url: https://codereview.chromium.org/1985423003
Cr-Commit-Position: refs/heads/master@{#36420}
parent 9aac80f4
......@@ -1991,6 +1991,23 @@ var defaultObjects = {
'dateformattime': UNDEFINED,
};
function clearDefaultObjects() {
defaultObjects['dateformatall'] = UNDEFINED;
defaultObjects['dateformatdate'] = UNDEFINED;
defaultObjects['dateformattime'] = UNDEFINED;
}
var date_cache_version = 0;
function checkDateCacheCurrent() {
var new_date_cache_version = %DateCacheVersion();
if (new_date_cache_version == date_cache_version) {
return;
}
date_cache_version = new_date_cache_version;
clearDefaultObjects();
}
/**
* Returns cached or newly created instance of a given service.
......@@ -1999,6 +2016,7 @@ var defaultObjects = {
function cachedOrNewService(service, locales, options, defaults) {
var useOptions = (IS_UNDEFINED(defaults)) ? options : defaults;
if (IS_UNDEFINED(locales) && IS_UNDEFINED(options)) {
checkDateCacheCurrent();
if (IS_UNDEFINED(defaultObjects[service])) {
defaultObjects[service] = new savedObjects[service](locales, useOptions);
}
......
......@@ -1145,6 +1145,23 @@ RUNTIME_FUNCTION(Runtime_StringLocaleConvertCase) {
reinterpret_cast<const char*>(lang_str));
}
RUNTIME_FUNCTION(Runtime_DateCacheVersion) {
HandleScope scope(isolate);
DCHECK_EQ(0, args.length());
if (isolate->serializer_enabled()) return isolate->heap()->undefined_value();
if (!isolate->eternal_handles()->Exists(EternalHandles::DATE_CACHE_VERSION)) {
Handle<FixedArray> date_cache_version =
isolate->factory()->NewFixedArray(1, TENURED);
date_cache_version->set(0, Smi::FromInt(0));
isolate->eternal_handles()->CreateSingleton(
isolate, *date_cache_version, EternalHandles::DATE_CACHE_VERSION);
}
Handle<FixedArray> date_cache_version =
Handle<FixedArray>::cast(isolate->eternal_handles()->GetSingleton(
EternalHandles::DATE_CACHE_VERSION));
return date_cache_version->get(0);
}
} // namespace internal
} // namespace v8
......
......@@ -261,7 +261,8 @@ namespace internal {
F(BreakIteratorBreakType, 1, 1) \
F(StringToLowerCaseI18N, 1, 1) \
F(StringToUpperCaseI18N, 1, 1) \
F(StringLocaleConvertCase, 3, 1)
F(StringLocaleConvertCase, 3, 1) \
F(DateCacheVersion, 0, 1)
#else
#define FOR_EACH_INTRINSIC_I18N(F)
#endif
......
......@@ -166,3 +166,26 @@ TEST(DaylightSavingsTime) {
CheckDST(august_20 + 2 * 3600 - 1000);
CheckDST(august_20);
}
#ifdef V8_I18N_SUPPORT
TEST(DateCacheVersion) {
FLAG_allow_natives_syntax = true;
v8::Isolate* isolate = CcTest::isolate();
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context);
v8::Local<v8::Number> date_cache_version =
v8::Local<v8::Number>::Cast(CompileRun("%DateCacheVersion()"));
CHECK(date_cache_version->IsNumber());
CHECK_EQ(0.0, date_cache_version->NumberValue(context).FromMaybe(-1.0));
v8::Date::DateTimeConfigurationChangeNotification(isolate);
date_cache_version =
v8::Local<v8::Number>::Cast(CompileRun("%DateCacheVersion()"));
CHECK(date_cache_version->IsNumber());
CHECK_EQ(1.0, date_cache_version->NumberValue(context).FromMaybe(-1.0));
}
#endif // V8_I18N_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