2012-09-11 10:05:00 +04:00
|
|
|
/* 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/. */
|
2012-09-28 10:02:28 +04:00
|
|
|
|
2012-09-11 10:05:00 +04:00
|
|
|
#include "jsapi.h"
|
|
|
|
#include "nsIDOMClassInfo.h"
|
2012-09-28 10:02:28 +04:00
|
|
|
#include "nsITimeService.h"
|
2012-09-11 10:05:00 +04:00
|
|
|
#include "TimeManager.h"
|
|
|
|
|
2012-11-05 19:20:03 +04:00
|
|
|
#ifdef MOZ_TIME_MANAGER
|
2012-09-11 10:05:00 +04:00
|
|
|
DOMCI_DATA(MozTimeManager, mozilla::dom::time::TimeManager)
|
2012-11-05 19:20:03 +04:00
|
|
|
#endif
|
2012-09-11 10:05:00 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
namespace time {
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(TimeManager)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMMozTimeManager)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2012-11-05 19:20:03 +04:00
|
|
|
#ifdef MOZ_TIME_MANAGER
|
2012-09-11 10:05:00 +04:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozTimeManager)
|
2012-11-05 19:20:03 +04:00
|
|
|
#endif
|
2012-09-11 10:05:00 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(TimeManager)
|
|
|
|
NS_IMPL_RELEASE(TimeManager)
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
TimeManager::Set(const JS::Value& date, JSContext* ctx) {
|
|
|
|
double dateMSec;
|
|
|
|
|
|
|
|
if (date.isObject()) {
|
2013-05-04 11:52:57 +04:00
|
|
|
JS::Rooted<JSObject*> dateObj(ctx, date.toObjectOrNull());
|
2012-09-11 10:05:00 +04:00
|
|
|
|
2012-09-21 08:41:49 +04:00
|
|
|
if (JS_ObjectIsDate(ctx, dateObj) && js_DateIsValid(dateObj)) {
|
|
|
|
dateMSec = js_DateGetMsecSinceEpoch(dateObj);
|
2012-09-11 10:05:00 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_WARN_IF_FALSE(JS_ObjectIsDate(ctx, dateObj), "This is not a Date object");
|
2012-09-21 08:41:49 +04:00
|
|
|
NS_WARN_IF_FALSE(js_DateIsValid(dateObj), "Date is not valid");
|
2012-09-11 10:05:00 +04:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
} else if (date.isNumber()) {
|
|
|
|
dateMSec = date.toNumber();
|
|
|
|
} else {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2012-09-28 10:02:28 +04:00
|
|
|
nsCOMPtr<nsITimeService> timeService = do_GetService(TIMESERVICE_CONTRACTID);
|
|
|
|
if (timeService) {
|
|
|
|
return timeService->Set(dateMSec);
|
|
|
|
}
|
2012-09-11 10:05:00 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace time
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|