Commit 648fcd90 authored by sgjesse@chromium.org's avatar sgjesse@chromium.org

Adding Date::ResetCache() API so that the cache values in the Date object

can be reset to allow DST / timezone changes to be re-cached and reflected
in the Date object.

Patch by Mark Lam from Hewlett-Packard Development Company, LP

Review URL: http://codereview.chromium.org/5978001


git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@6067 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 8ff6c23c
......@@ -1355,6 +1355,21 @@ class Date : public Value {
V8EXPORT double NumberValue() const;
static inline Date* Cast(v8::Value* obj);
/**
* 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 in the Date
* object.
*
* This API should not be called more than needed as it will
* negatively impact the performance of date operations.
*/
V8EXPORT static void DateTimeConfigurationChangeNotification();
private:
V8EXPORT static void CheckCast(v8::Value* obj);
};
......
......@@ -3802,6 +3802,35 @@ double v8::Date::NumberValue() const {
}
void v8::Date::DateTimeConfigurationChangeNotification() {
ON_BAILOUT("v8::Date::DateTimeConfigurationChangeNotification()", return);
LOG_API("Date::DateTimeConfigurationChangeNotification");
ENTER_V8;
HandleScope scope;
// Get the function ResetDateCache (defined in date-delay.js).
i::Handle<i::String> func_name_str =
i::Factory::LookupAsciiSymbol("ResetDateCache");
i::MaybeObject* result = i::Top::builtins()->GetProperty(*func_name_str);
i::Object* object_func;
if (!result->ToObject(&object_func)) {
return;
}
if (object_func->IsJSFunction()) {
i::Handle<i::JSFunction> func =
i::Handle<i::JSFunction>(i::JSFunction::cast(object_func));
// Call ResetDateCache(0 but expect no exceptions:
bool caught_exception = false;
i::Handle<i::Object> result =
i::Execution::TryCall(func, i::Top::builtins(), 0, NULL,
&caught_exception);
}
}
static i::Handle<i::String> RegExpFlagsToString(RegExp::Flags flags) {
char flags_buf[3];
int num_flags = 0;
......
......@@ -1007,6 +1007,39 @@ function DateToJSON(key) {
}
function ResetDateCache() {
// Reset the local_time_offset:
local_time_offset = %DateLocalTimeOffset();
// Reset the DST offset cache:
var cache = DST_offset_cache;
cache.offset = 0;
cache.start = 0;
cache.end = -1;
cache.increment = 0;
cache.initial_increment = 19 * msPerDay;
// Reset the timezone cache:
timezone_cache_time = $NaN;
timezone_cache_timezone = undefined;
// Reset the ltcache:
ltcache.key = null;
ltcache.val = null;
// Reset the ymd_from_time_cache:
ymd_from_time_cache = [$NaN, $NaN, $NaN];
ymd_from_time_cached_time = $NaN;
// Reset the date cache:
cache = Date_cache;
cache.time = $NaN;
cache.year = $NaN;
cache.string = null;
}
// -------------------------------------------------------------------
function SetupDate() {
......
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