Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #include "mozilla/dom/Date.h"
8 :
9 : #include "jsapi.h" // for JS_ObjectIsDate
10 : #include "jsfriendapi.h" // for DateGetMsecSinceEpoch
11 : #include "js/Date.h" // for JS::NewDateObject, JS::ClippedTime, JS::TimeClip
12 : #include "js/RootingAPI.h" // for Rooted, MutableHandle
13 : #include "js/Value.h" // for Value
14 : #include "mozilla/FloatingPoint.h" // for IsNaN, UnspecifiedNaN
15 :
16 : namespace mozilla {
17 : namespace dom {
18 :
19 : bool
20 0 : Date::SetTimeStamp(JSContext* aCx, JSObject* aObject)
21 : {
22 0 : JS::Rooted<JSObject*> obj(aCx, aObject);
23 :
24 : double msecs;
25 0 : if (!js::DateGetMsecSinceEpoch(aCx, obj, &msecs)) {
26 0 : return false;
27 : }
28 :
29 0 : JS::ClippedTime time = JS::TimeClip(msecs);
30 0 : MOZ_ASSERT(NumbersAreIdentical(msecs, time.toDouble()));
31 :
32 0 : mMsecSinceEpoch = time;
33 0 : return true;
34 : }
35 :
36 : bool
37 0 : Date::ToDateObject(JSContext* aCx, JS::MutableHandle<JS::Value> aRval) const
38 : {
39 0 : JSObject* obj = JS::NewDateObject(aCx, mMsecSinceEpoch);
40 0 : if (!obj) {
41 0 : return false;
42 : }
43 :
44 0 : aRval.setObject(*obj);
45 0 : return true;
46 : }
47 :
48 : } // namespace dom
49 : } // namespace mozilla
|