]>
Commit | Line | Data |
---|---|---|
9dae56ea A |
1 | /* |
2 | * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) | |
3 | * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | |
4 | * | |
5 | * This library is free software; you can redistribute it and/or | |
6 | * modify it under the terms of the GNU Lesser General Public | |
7 | * License as published by the Free Software Foundation; either | |
8 | * version 2 of the License, or (at your option) any later version. | |
9 | * | |
10 | * This library is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * Lesser General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU Lesser General Public | |
16 | * License along with this library; if not, write to the Free Software | |
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 | |
18 | * USA | |
19 | * | |
20 | */ | |
21 | ||
22 | #include "config.h" | |
23 | #include "DateInstance.h" | |
24 | ||
6fe7ccc8 | 25 | #include "JSDateMath.h" |
f9bf01c6 | 26 | #include "JSGlobalObject.h" |
81345200 | 27 | #include "JSCInlines.h" |
9dae56ea A |
28 | #include <math.h> |
29 | #include <wtf/MathExtras.h> | |
30 | ||
ba379fdc A |
31 | using namespace WTF; |
32 | ||
9dae56ea A |
33 | namespace JSC { |
34 | ||
6fe7ccc8 | 35 | const ClassInfo DateInstance::s_info = {"Date", &JSWrapperObject::s_info, 0, 0, CREATE_METHOD_TABLE(DateInstance)}; |
9dae56ea | 36 | |
81345200 A |
37 | DateInstance::DateInstance(VM& vm, Structure* structure) |
38 | : JSWrapperObject(vm, structure) | |
9dae56ea | 39 | { |
6fe7ccc8 A |
40 | } |
41 | ||
93a37866 | 42 | void DateInstance::finishCreation(VM& vm) |
6fe7ccc8 | 43 | { |
93a37866 | 44 | Base::finishCreation(vm); |
81345200 | 45 | ASSERT(inherits(info())); |
93a37866 | 46 | setInternalValue(vm, jsNaN()); |
9dae56ea A |
47 | } |
48 | ||
93a37866 | 49 | void DateInstance::finishCreation(VM& vm, double time) |
9dae56ea | 50 | { |
93a37866 | 51 | Base::finishCreation(vm); |
81345200 | 52 | ASSERT(inherits(info())); |
93a37866 | 53 | setInternalValue(vm, jsNumber(timeClip(time))); |
6fe7ccc8 A |
54 | } |
55 | ||
56 | void DateInstance::destroy(JSCell* cell) | |
57 | { | |
93a37866 | 58 | static_cast<DateInstance*>(cell)->DateInstance::~DateInstance(); |
9dae56ea A |
59 | } |
60 | ||
f9bf01c6 | 61 | const GregorianDateTime* DateInstance::calculateGregorianDateTime(ExecState* exec) const |
9dae56ea A |
62 | { |
63 | double milli = internalNumber(); | |
93a37866 | 64 | if (std::isnan(milli)) |
f9bf01c6 A |
65 | return 0; |
66 | ||
81345200 | 67 | VM& vm = exec->vm(); |
f9bf01c6 | 68 | if (!m_data) |
81345200 | 69 | m_data = vm.dateInstanceCache.add(milli); |
f9bf01c6 A |
70 | |
71 | if (m_data->m_gregorianDateTimeCachedForMS != milli) { | |
81345200 | 72 | msToGregorianDateTime(vm, milli, false, m_data->m_cachedGregorianDateTime); |
f9bf01c6 A |
73 | m_data->m_gregorianDateTimeCachedForMS = milli; |
74 | } | |
75 | return &m_data->m_cachedGregorianDateTime; | |
9dae56ea A |
76 | } |
77 | ||
f9bf01c6 | 78 | const GregorianDateTime* DateInstance::calculateGregorianDateTimeUTC(ExecState* exec) const |
9dae56ea A |
79 | { |
80 | double milli = internalNumber(); | |
93a37866 | 81 | if (std::isnan(milli)) |
f9bf01c6 | 82 | return 0; |
9dae56ea | 83 | |
81345200 | 84 | VM& vm = exec->vm(); |
f9bf01c6 | 85 | if (!m_data) |
81345200 | 86 | m_data = vm.dateInstanceCache.add(milli); |
9dae56ea | 87 | |
f9bf01c6 | 88 | if (m_data->m_gregorianDateTimeUTCCachedForMS != milli) { |
81345200 | 89 | msToGregorianDateTime(vm, milli, true, m_data->m_cachedGregorianDateTimeUTC); |
f9bf01c6 A |
90 | m_data->m_gregorianDateTimeUTCCachedForMS = milli; |
91 | } | |
92 | return &m_data->m_cachedGregorianDateTimeUTC; | |
9dae56ea A |
93 | } |
94 | ||
95 | } // namespace JSC |