Commit 980e0d32 authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

[api] Add new configuration change methods

This adds a new method Isolate::LocaleConfigurationChangeNotification
that clears the cached Locale allowing new Locales to be picked up in
later Locale operations.

It moves Date::DateTimeConfigurationChangeNotification to Isolate
(deprecating the old one) so that the configuration change methods are
found together.

Change-Id: Iffc15e326933c5bc5baf2f0eafdd5c148b8279a8
Reviewed-on: https://chromium-review.googlesource.com/c/1491608Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Commit-Queue: Dan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60003}
parent 505a26fa
...@@ -5316,9 +5316,11 @@ class V8_EXPORT Date : public Object { ...@@ -5316,9 +5316,11 @@ class V8_EXPORT Date : public Object {
* This API should not be called more than needed as it will * This API should not be called more than needed as it will
* negatively impact the performance of date operations. * negatively impact the performance of date operations.
*/ */
static void DateTimeConfigurationChangeNotification( V8_DEPRECATE_SOON(
Isolate* isolate, "Use Isolate::DateTimeConfigurationChangeNotification",
TimeZoneDetection time_zone_detection = TimeZoneDetection::kSkip); static void DateTimeConfigurationChangeNotification(
Isolate* isolate,
TimeZoneDetection time_zone_detection = TimeZoneDetection::kSkip));
private: private:
static void CheckCast(Value* obj); static void CheckCast(Value* obj);
...@@ -8546,6 +8548,45 @@ class V8_EXPORT Isolate { ...@@ -8546,6 +8548,45 @@ class V8_EXPORT Isolate {
*/ */
void SetAllowAtomicsWait(bool allow); void SetAllowAtomicsWait(bool allow);
/**
* Time zone redetection indicator for
* DateTimeConfigurationChangeNotification.
*
* kSkip indicates V8 that the notification should not trigger redetecting
* host time zone. kRedetect indicates V8 that host time zone should be
* redetected, and used to set the default time zone.
*
* The host time zone detection may require file system access or similar
* operations unlikely to be available inside a sandbox. If v8 is run inside a
* sandbox, the host time zone has to be detected outside the sandbox before
* calling DateTimeConfigurationChangeNotification function.
*/
enum class TimeZoneDetection { kSkip, kRedetect };
/**
* Notification that the embedder has changed the time zone, daylight savings
* time or other date / time configuration parameters. V8 keeps a cache of
* various values used for date / time computation. This notification will
* reset those cached values for the current context so that date / time
* configuration changes would be reflected.
*
* This API should not be called more than needed as it will negatively impact
* the performance of date operations.
*/
void DateTimeConfigurationChangeNotification(
TimeZoneDetection time_zone_detection = TimeZoneDetection::kSkip);
/**
* Notification that the embedder has changed the locale. V8 keeps a cache of
* various values used for locale computation. This notification will reset
* those cached values for the current context so that locale configuration
* changes would be reflected.
*
* This API should not be called more than needed as it will negatively impact
* the performance of locale operations.
*/
void LocaleConfigurationChangeNotification();
Isolate() = delete; Isolate() = delete;
~Isolate() = delete; ~Isolate() = delete;
Isolate(const Isolate&) = delete; Isolate(const Isolate&) = delete;
......
...@@ -6768,29 +6768,21 @@ double v8::Date::ValueOf() const { ...@@ -6768,29 +6768,21 @@ double v8::Date::ValueOf() const {
// Assert that the static TimeZoneDetection cast in // Assert that the static TimeZoneDetection cast in
// DateTimeConfigurationChangeNotification is valid. // DateTimeConfigurationChangeNotification is valid.
#define TIME_ZONE_DETECTION_ASSERT_EQ(value) \ #define TIME_ZONE_DETECTION_ASSERT_EQ(value) \
STATIC_ASSERT( \ STATIC_ASSERT( \
static_cast<int>(v8::Date::TimeZoneDetection::value) == \ static_cast<int>(v8::Isolate::TimeZoneDetection::value) == \
static_cast<int>(base::TimezoneCache::TimeZoneDetection::value)) static_cast<int>(base::TimezoneCache::TimeZoneDetection::value)); \
TIME_ZONE_DETECTION_ASSERT_EQ(kSkip); STATIC_ASSERT(static_cast<int>(v8::Isolate::TimeZoneDetection::value) == \
TIME_ZONE_DETECTION_ASSERT_EQ(kRedetect); static_cast<int>(v8::Date::TimeZoneDetection::value));
TIME_ZONE_DETECTION_ASSERT_EQ(kSkip)
TIME_ZONE_DETECTION_ASSERT_EQ(kRedetect)
#undef TIME_ZONE_DETECTION_ASSERT_EQ #undef TIME_ZONE_DETECTION_ASSERT_EQ
// static
void v8::Date::DateTimeConfigurationChangeNotification( void v8::Date::DateTimeConfigurationChangeNotification(
Isolate* isolate, TimeZoneDetection time_zone_detection) { Isolate* isolate, TimeZoneDetection time_zone_detection) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); isolate->DateTimeConfigurationChangeNotification(
LOG_API(i_isolate, Date, DateTimeConfigurationChangeNotification); static_cast<v8::Isolate::TimeZoneDetection>(time_zone_detection));
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
i_isolate->date_cache()->ResetDateCache(
static_cast<base::TimezoneCache::TimeZoneDetection>(time_zone_detection));
#ifdef V8_INTL_SUPPORT
i_isolate->clear_cached_icu_object(
i::Isolate::ICUObjectCacheType::kDefaultSimpleDateFormat);
i_isolate->clear_cached_icu_object(
i::Isolate::ICUObjectCacheType::kDefaultSimpleDateFormatForTime);
i_isolate->clear_cached_icu_object(
i::Isolate::ICUObjectCacheType::kDefaultSimpleDateFormatForDate);
#endif // V8_INTL_SUPPORT
} }
MaybeLocal<v8::RegExp> v8::RegExp::New(Local<Context> context, MaybeLocal<v8::RegExp> v8::RegExp::New(Local<Context> context,
...@@ -8899,6 +8891,33 @@ void Isolate::SetAllowAtomicsWait(bool allow) { ...@@ -8899,6 +8891,33 @@ void Isolate::SetAllowAtomicsWait(bool allow) {
isolate->set_allow_atomics_wait(allow); isolate->set_allow_atomics_wait(allow);
} }
void v8::Isolate::DateTimeConfigurationChangeNotification(
TimeZoneDetection time_zone_detection) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(this);
LOG_API(i_isolate, Isolate, DateTimeConfigurationChangeNotification);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
i_isolate->date_cache()->ResetDateCache(
static_cast<base::TimezoneCache::TimeZoneDetection>(time_zone_detection));
#ifdef V8_INTL_SUPPORT
i_isolate->clear_cached_icu_object(
i::Isolate::ICUObjectCacheType::kDefaultSimpleDateFormat);
i_isolate->clear_cached_icu_object(
i::Isolate::ICUObjectCacheType::kDefaultSimpleDateFormatForTime);
i_isolate->clear_cached_icu_object(
i::Isolate::ICUObjectCacheType::kDefaultSimpleDateFormatForDate);
#endif // V8_INTL_SUPPORT
}
void v8::Isolate::LocaleConfigurationChangeNotification() {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(this);
LOG_API(i_isolate, Isolate, LocaleConfigurationChangeNotification);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
#ifdef V8_INTL_SUPPORT
i_isolate->ResetDefaultLocale();
#endif // V8_INTL_SUPPORT
}
MicrotasksScope::MicrotasksScope(Isolate* isolate, MicrotasksScope::Type type) MicrotasksScope::MicrotasksScope(Isolate* isolate, MicrotasksScope::Type type)
: MicrotasksScope( : MicrotasksScope(
isolate, isolate,
......
...@@ -723,7 +723,6 @@ class RuntimeCallTimer final { ...@@ -723,7 +723,6 @@ class RuntimeCallTimer final {
V(Context_New) \ V(Context_New) \
V(Context_NewRemoteContext) \ V(Context_NewRemoteContext) \
V(DataView_New) \ V(DataView_New) \
V(Date_DateTimeConfigurationChangeNotification) \
V(Date_New) \ V(Date_New) \
V(Date_NumberValue) \ V(Date_NumberValue) \
V(Debug_Call) \ V(Debug_Call) \
...@@ -743,6 +742,8 @@ class RuntimeCallTimer final { ...@@ -743,6 +742,8 @@ class RuntimeCallTimer final {
V(Int16Array_New) \ V(Int16Array_New) \
V(Int32Array_New) \ V(Int32Array_New) \
V(Int8Array_New) \ V(Int8Array_New) \
V(Isolate_DateTimeConfigurationChangeNotification) \
V(Isolate_LocaleConfigurationChangeNotification) \
V(JSON_Parse) \ V(JSON_Parse) \
V(JSON_Stringify) \ V(JSON_Stringify) \
V(Map_AsArray) \ V(Map_AsArray) \
......
...@@ -1101,6 +1101,8 @@ class Isolate final : private HiddenFactory { ...@@ -1101,6 +1101,8 @@ class Isolate final : private HiddenFactory {
const std::string& default_locale() { return default_locale_; } const std::string& default_locale() { return default_locale_; }
void ResetDefaultLocale() { default_locale_.clear(); }
void set_default_locale(const std::string& locale) { void set_default_locale(const std::string& locale) {
DCHECK_EQ(default_locale_.length(), 0); DCHECK_EQ(default_locale_.length(), 0);
default_locale_ = locale; default_locale_ = locale;
......
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