Bug 790499 - Time API: Call JS_ClearDateCaches() to update Date object's timezone when the system timezone is reset, r=jlebar
☠☠ backed out by 57deb0de3513 ☠ ☠
authorSteven Lee <slee@mozilla.com>
Fri, 21 Sep 2012 14:56:01 -0400
changeset 107744 9f16bba541ccf679095fd63543011256e7279de7
parent 107743 ed139b2239303d251a3e2469e68cb68ea6ab5558
child 107745 cbac99ae6a9968cac044699e8aa3bc3cc32c3f16
push id23507
push userryanvm@gmail.com
push dateSat, 22 Sep 2012 02:38:57 +0000
treeherdermozilla-central@8f359a9d1f19 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjlebar
bugs790499
milestone18.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 790499 - Time API: Call JS_ClearDateCaches() to update Date object's timezone when the system timezone is reset, r=jlebar
dom/time/DateCacheCleaner.cpp
dom/time/DateCacheCleaner.h
dom/time/Makefile.in
hal/HalTypes.h
layout/build/nsLayoutStatics.cpp
new file mode 100644
--- /dev/null
+++ b/dom/time/DateCacheCleaner.cpp
@@ -0,0 +1,62 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "mozilla/Hal.h"
+#include "mozilla/ClearOnShutdown.h"
+#include "DateCacheCleaner.h"
+
+#include "nsIJSContextStack.h"
+#include "mozilla/StaticPtr.h"
+
+using namespace mozilla::hal;
+
+namespace mozilla {
+namespace time {
+
+class DateCacheCleaner : public SystemTimeChangeObserver
+{
+public:
+  DateCacheCleaner()
+  {
+    RegisterSystemTimeChangeObserver(this);
+  }
+
+  ~DateCacheCleaner()
+  {
+    UnregisterSystemTimeChangeObserver(this);
+  }
+
+  virtual void Notify(const SystemTimeChange& aReason)
+  {
+    if (aReason == SYS_TIME_CHANGE_CLOCK) {
+      return;
+    }
+
+    nsCOMPtr<nsIThreadJSContextStack> stack =
+      do_GetService("@mozilla.org/js/xpc/ContextStack;1");
+    if (!stack) {
+      NS_WARNING("Failed to get JSContextStack");
+    }
+    JSContext *cx = stack->GetSafeJSContext();
+    if (!cx) {
+      NS_WARNING("Failed to GetSafeJSContext");
+    }
+    JS_ClearDateCaches(cx);
+  }
+};
+
+StaticAutoPtr<DateCacheCleaner> sDateCacheCleaner;
+
+void
+InitializeDateCacheCleaner()
+{
+  if (!sDateCacheCleaner) {
+    sDateCacheCleaner = new DateCacheCleaner();
+    ClearOnShutdown(&sDateCacheCleaner);
+  }
+}
+
+} // namespace time
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/dom/time/DateCacheCleaner.h
@@ -0,0 +1,16 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+ * InitializeDateCacheCleaner registers DateCacheCleaner to 
+ * SystemTimeChangeObserver. When time zone is changed, DateCacheCleaner calls
+ * JS_ClearDateCaches to update the time zone information.
+ */
+
+namespace mozilla {
+namespace time {
+void InitializeDateCacheCleaner();
+} //namespace time
+} //namespace mozilla
--- a/dom/time/Makefile.in
+++ b/dom/time/Makefile.in
@@ -15,20 +15,22 @@ LIBXUL_LIBRARY   = 1
 FORCE_STATIC_LIB = 1
 FAIL_ON_WARNINGS := 1
 
 include $(topsrcdir)/dom/dom-config.mk
 
 CPPSRCS = \
   TimeManager.cpp \
   TimeChangeObserver.cpp \
+  DateCacheCleaner.cpp \
   $(NULL)
 
 EXPORTS = \
   TimeChangeObserver.h \
+  DateCacheCleaner.h \
   $(NULL)
 
 XPIDLSRCS = \
   nsIDOMNavigatorTime.idl \
   nsIDOMTimeManager.idl \
   $(NULL)
 
 include $(topsrcdir)/config/config.mk
--- a/hal/HalTypes.h
+++ b/hal/HalTypes.h
@@ -76,16 +76,17 @@ enum WakeLockControl {
 
 enum SystemTimeChange {
   SYS_TIME_CHANGE_UNKNOWN = -1,
   SYS_TIME_CHANGE_CLOCK,
   SYS_TIME_CHANGE_TZ,
   SYS_TIME_CHANGE_GUARD
 };
 
+typedef Observer<SystemTimeChange> SystemTimeChangeObserver;
 } // namespace hal
 } // namespace mozilla
 
 namespace IPC {
 
 /**
  * Light type serializer.
  */
--- a/layout/build/nsLayoutStatics.cpp
+++ b/layout/build/nsLayoutStatics.cpp
@@ -95,22 +95,24 @@
 #include "nsRefreshDriver.h"
 #include "nsDOMMutationObserver.h"
 #include "nsHyphenationManager.h"
 #include "nsEditorSpellCheck.h"
 #include "nsWindowMemoryReporter.h"
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/ipc/ProcessPriorityManager.h"
 #include "nsPermissionManager.h"
+#include "DateCacheCleaner.h"
 
 extern void NS_ShutdownChainItemPool();
 
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::dom::ipc;
+using namespace mozilla::time;
 
 nsrefcnt nsLayoutStatics::sLayoutStaticRefcnt = 0;
 
 nsresult
 nsLayoutStatics::Initialize()
 {
   NS_ASSERTION(sLayoutStaticRefcnt == 0,
                "nsLayoutStatics isn't zero!");
@@ -253,16 +255,18 @@ nsLayoutStatics::Initialize()
   nsSVGUtils::Init();
 
   InitProcessPriorityManager();
 
   nsPermissionManager::AppUninstallObserverInit();
 
   nsDOMStorageBaseDB::Init();
 
+  InitializeDateCacheCleaner();
+
   return NS_OK;
 }
 
 void
 nsLayoutStatics::Shutdown()
 {
   // Don't need to shutdown nsWindowMemoryReporter, that will be done by the
   // memory reporter manager.