[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/1491608 Reviewed-by: Ulan Degenbaev <ulan@chromium.org> Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org> Commit-Queue: Dan Elphick <delphick@chromium.org> Cr-Commit-Position: refs/heads/master@{#60003}
This commit is contained in:
parent
505a26fac7
commit
980e0d32d0
47
include/v8.h
47
include/v8.h
@ -5316,9 +5316,11 @@ class V8_EXPORT Date : public Object {
|
||||
* This API should not be called more than needed as it will
|
||||
* negatively impact the performance of date operations.
|
||||
*/
|
||||
static void DateTimeConfigurationChangeNotification(
|
||||
Isolate* isolate,
|
||||
TimeZoneDetection time_zone_detection = TimeZoneDetection::kSkip);
|
||||
V8_DEPRECATE_SOON(
|
||||
"Use Isolate::DateTimeConfigurationChangeNotification",
|
||||
static void DateTimeConfigurationChangeNotification(
|
||||
Isolate* isolate,
|
||||
TimeZoneDetection time_zone_detection = TimeZoneDetection::kSkip));
|
||||
|
||||
private:
|
||||
static void CheckCast(Value* obj);
|
||||
@ -8546,6 +8548,45 @@ class V8_EXPORT Isolate {
|
||||
*/
|
||||
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(const Isolate&) = delete;
|
||||
|
57
src/api.cc
57
src/api.cc
@ -6768,29 +6768,21 @@ double v8::Date::ValueOf() const {
|
||||
|
||||
// Assert that the static TimeZoneDetection cast in
|
||||
// DateTimeConfigurationChangeNotification is valid.
|
||||
#define TIME_ZONE_DETECTION_ASSERT_EQ(value) \
|
||||
STATIC_ASSERT( \
|
||||
static_cast<int>(v8::Date::TimeZoneDetection::value) == \
|
||||
static_cast<int>(base::TimezoneCache::TimeZoneDetection::value))
|
||||
TIME_ZONE_DETECTION_ASSERT_EQ(kSkip);
|
||||
TIME_ZONE_DETECTION_ASSERT_EQ(kRedetect);
|
||||
#define TIME_ZONE_DETECTION_ASSERT_EQ(value) \
|
||||
STATIC_ASSERT( \
|
||||
static_cast<int>(v8::Isolate::TimeZoneDetection::value) == \
|
||||
static_cast<int>(base::TimezoneCache::TimeZoneDetection::value)); \
|
||||
STATIC_ASSERT(static_cast<int>(v8::Isolate::TimeZoneDetection::value) == \
|
||||
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
|
||||
|
||||
// static
|
||||
void v8::Date::DateTimeConfigurationChangeNotification(
|
||||
Isolate* isolate, TimeZoneDetection time_zone_detection) {
|
||||
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
||||
LOG_API(i_isolate, Date, 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
|
||||
isolate->DateTimeConfigurationChangeNotification(
|
||||
static_cast<v8::Isolate::TimeZoneDetection>(time_zone_detection));
|
||||
}
|
||||
|
||||
MaybeLocal<v8::RegExp> v8::RegExp::New(Local<Context> context,
|
||||
@ -8899,6 +8891,33 @@ void Isolate::SetAllowAtomicsWait(bool 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(
|
||||
isolate,
|
||||
|
@ -723,7 +723,6 @@ class RuntimeCallTimer final {
|
||||
V(Context_New) \
|
||||
V(Context_NewRemoteContext) \
|
||||
V(DataView_New) \
|
||||
V(Date_DateTimeConfigurationChangeNotification) \
|
||||
V(Date_New) \
|
||||
V(Date_NumberValue) \
|
||||
V(Debug_Call) \
|
||||
@ -743,6 +742,8 @@ class RuntimeCallTimer final {
|
||||
V(Int16Array_New) \
|
||||
V(Int32Array_New) \
|
||||
V(Int8Array_New) \
|
||||
V(Isolate_DateTimeConfigurationChangeNotification) \
|
||||
V(Isolate_LocaleConfigurationChangeNotification) \
|
||||
V(JSON_Parse) \
|
||||
V(JSON_Stringify) \
|
||||
V(Map_AsArray) \
|
||||
|
@ -1101,6 +1101,8 @@ class Isolate final : private HiddenFactory {
|
||||
|
||||
const std::string& default_locale() { return default_locale_; }
|
||||
|
||||
void ResetDefaultLocale() { default_locale_.clear(); }
|
||||
|
||||
void set_default_locale(const std::string& locale) {
|
||||
DCHECK_EQ(default_locale_.length(), 0);
|
||||
default_locale_ = locale;
|
||||
|
Loading…
Reference in New Issue
Block a user