Bug 790499 - Time API: Call JS_ClearDateCaches() to update Date object's timezone when the system timezone is reset, r=jlebar
authorSteven Lee <slee@mozilla.com>
Wed, 17 Oct 2012 00:26:00 -0400
changeset 110526 80fffd499dca98186393793a74836147683958b5
parent 110525 b803ce91fc0ebaf17d59c913d437a8fe08759fc7
child 110527 93dc400ae049812e01e13e54144f64e8edcacc45
push id16600
push userjlebar@mozilla.com
push dateWed, 17 Oct 2012 15:23:06 +0000
treeherdermozilla-inbound@80fffd499dca [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjlebar
bugs790499
milestone19.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,64 @@
+/* -*- 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 dom {
+namespace time {
+
+class DateCacheCleaner : public SystemTimeChangeObserver
+{
+public:
+  DateCacheCleaner()
+  {
+    RegisterSystemTimeChangeObserver(this);
+  }
+
+  ~DateCacheCleaner()
+  {
+    UnregisterSystemTimeChangeObserver(this);
+  }
+  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 dom
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/dom/time/DateCacheCleaner.h
@@ -0,0 +1,18 @@
+/* -*- 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 dom {
+namespace time {
+void InitializeDateCacheCleaner();
+} //namespace time
+} //namespace dom
+} //namespace mozilla
--- a/dom/time/Makefile.in
+++ b/dom/time/Makefile.in
@@ -19,21 +19,23 @@ FAIL_ON_WARNINGS := 1
 include $(topsrcdir)/dom/dom-config.mk
 
 EXPORTS_NAMESPACES = mozilla/dom/time
 
 CPPSRCS = \
   TimeManager.cpp \
   TimeService.cpp \
   TimeChangeObserver.cpp \
+  DateCacheCleaner.cpp \
   $(NULL)
 
 EXPORTS_mozilla/dom/time = \
   TimeService.h \
   TimeChangeObserver.h \
+  DateCacheCleaner.h \
   $(NULL)
 
 XPIDLSRCS = \
   nsIDOMNavigatorTime.idl \
   nsIDOMTimeManager.idl \
   nsITimeService.idl \
   $(NULL)
 
--- a/hal/HalTypes.h
+++ b/hal/HalTypes.h
@@ -162,16 +162,17 @@ enum FMRadioCountry {
   FM_RADIO_COUNTRY_TW,  //Taiwan
   FM_RADIO_COUNTRY_TR,  //Turkey
   FM_RADIO_COUNTRY_UA,  //Ukraine
   FM_RADIO_COUNTRY_USER_DEFINED,
   NUM_FM_RADIO_COUNTRY
 };
 
 typedef Observer<FMRadioOperationInformation> FMRadioObserver;
+typedef Observer<SystemTimeChange> SystemTimeChangeObserver;
 } // namespace hal
 } // namespace mozilla
 
 namespace IPC {
 
 /**
  * Light type serializer.
  */
--- a/layout/build/nsLayoutStatics.cpp
+++ b/layout/build/nsLayoutStatics.cpp
@@ -97,22 +97,24 @@
 #include "nsHyphenationManager.h"
 #include "nsEditorSpellCheck.h"
 #include "nsWindowMemoryReporter.h"
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/ipc/ProcessPriorityManager.h"
 #include "nsPermissionManager.h"
 #include "nsCookieService.h"
 #include "nsApplicationCacheService.h"
+#include "mozilla/dom/time/DateCacheCleaner.h"
 
 extern void NS_ShutdownChainItemPool();
 
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::dom::ipc;
+using namespace mozilla::dom::time;
 
 nsrefcnt nsLayoutStatics::sLayoutStaticRefcnt = 0;
 
 nsresult
 nsLayoutStatics::Initialize()
 {
   NS_ASSERTION(sLayoutStaticRefcnt == 0,
                "nsLayoutStatics isn't zero!");
@@ -257,16 +259,18 @@ nsLayoutStatics::Initialize()
   InitProcessPriorityManager();
 
   nsPermissionManager::AppUninstallObserverInit();
   nsCookieService::AppClearDataObserverInit();
   nsApplicationCacheService::AppClearDataObserverInit();
 
   nsDOMStorageBaseDB::Init();
 
+  InitializeDateCacheCleaner();
+
   return NS_OK;
 }
 
 void
 nsLayoutStatics::Shutdown()
 {
   // Don't need to shutdown nsWindowMemoryReporter, that will be done by the
   // memory reporter manager.