Revision: 6067
Author: [email protected]
Date: Fri Dec 17 04:45:27 2010
Log: 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

http://code.google.com/p/v8/source/detail?r=6067

Modified:
 /branches/bleeding_edge/include/v8.h
 /branches/bleeding_edge/src/api.cc
 /branches/bleeding_edge/src/date.js

=======================================
--- /branches/bleeding_edge/include/v8.h        Tue Dec 14 05:21:46 2010
+++ /branches/bleeding_edge/include/v8.h        Fri Dec 17 04:45:27 2010
@@ -1355,6 +1355,21 @@
   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);
 };
=======================================
--- /branches/bleeding_edge/src/api.cc  Thu Dec 16 05:24:23 2010
+++ /branches/bleeding_edge/src/api.cc  Fri Dec 17 04:45:27 2010
@@ -3800,6 +3800,35 @@
   i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj);
   return jsvalue->value()->Number();
 }
+
+
+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) {
=======================================
--- /branches/bleeding_edge/src/date.js Thu Dec 16 05:02:09 2010
+++ /branches/bleeding_edge/src/date.js Fri Dec 17 04:45:27 2010
@@ -1005,6 +1005,39 @@
   }
   return o.toISOString();
 }
+
+
+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;
+}


 // -------------------------------------------------------------------

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to