mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 10:44:56 +00:00
Bug 790499 - Time API: Call JS_ClearDateCaches() to update Date object's timezone when the system timezone is reset, r=jlebar
--HG-- extra : rebase_source : ddd264047c861c3244dfdf43e695705ec675f066
This commit is contained in:
parent
87bfca191a
commit
19635a398b
62
dom/time/DateCacheCleaner.cpp
Normal file
62
dom/time/DateCacheCleaner.cpp
Normal file
@ -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
|
16
dom/time/DateCacheCleaner.h
Normal file
16
dom/time/DateCacheCleaner.h
Normal file
@ -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
|
@ -20,10 +20,12 @@ include $(topsrcdir)/dom/dom-config.mk
|
||||
CPPSRCS = \
|
||||
TimeManager.cpp \
|
||||
TimeChangeObserver.cpp \
|
||||
DateCacheCleaner.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
TimeChangeObserver.h \
|
||||
DateCacheCleaner.h \
|
||||
$(NULL)
|
||||
|
||||
XPIDLSRCS = \
|
||||
|
@ -81,6 +81,7 @@ enum SystemTimeChange {
|
||||
SYS_TIME_CHANGE_GUARD
|
||||
};
|
||||
|
||||
typedef Observer<SystemTimeChange> SystemTimeChangeObserver;
|
||||
} // namespace hal
|
||||
} // namespace mozilla
|
||||
|
||||
|
@ -100,12 +100,14 @@
|
||||
#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;
|
||||
|
||||
@ -258,6 +260,8 @@ nsLayoutStatics::Initialize()
|
||||
|
||||
nsDOMStorageBaseDB::Init();
|
||||
|
||||
InitializeDateCacheCleaner();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user