]> git.saurik.com Git - apple/javascriptcore.git/blob - runtime/DateInstance.h
JavaScriptCore-1218.33.tar.gz
[apple/javascriptcore.git] / runtime / DateInstance.h
1 /*
2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3 * Copyright (C) 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 USA
18 *
19 */
20
21 #ifndef DateInstance_h
22 #define DateInstance_h
23
24 #include "JSWrapperObject.h"
25
26 namespace JSC {
27
28 class DateInstance : public JSWrapperObject {
29 protected:
30 JS_EXPORT_PRIVATE DateInstance(ExecState*, Structure*);
31 void finishCreation(VM&);
32 JS_EXPORT_PRIVATE void finishCreation(VM&, double);
33
34 static void destroy(JSCell*);
35
36 public:
37 typedef JSWrapperObject Base;
38
39 static DateInstance* create(ExecState* exec, Structure* structure, double date)
40 {
41 DateInstance* instance = new (NotNull, allocateCell<DateInstance>(*exec->heap())) DateInstance(exec, structure);
42 instance->finishCreation(exec->vm(), date);
43 return instance;
44 }
45
46 static DateInstance* create(ExecState* exec, Structure* structure)
47 {
48 DateInstance* instance = new (NotNull, allocateCell<DateInstance>(*exec->heap())) DateInstance(exec, structure);
49 instance->finishCreation(exec->vm());
50 return instance;
51 }
52
53 double internalNumber() const { return internalValue().asNumber(); }
54
55 static JS_EXPORTDATA const ClassInfo s_info;
56
57 const GregorianDateTime* gregorianDateTime(ExecState* exec) const
58 {
59 if (m_data && m_data->m_gregorianDateTimeCachedForMS == internalNumber())
60 return &m_data->m_cachedGregorianDateTime;
61 return calculateGregorianDateTime(exec);
62 }
63
64 const GregorianDateTime* gregorianDateTimeUTC(ExecState* exec) const
65 {
66 if (m_data && m_data->m_gregorianDateTimeUTCCachedForMS == internalNumber())
67 return &m_data->m_cachedGregorianDateTimeUTC;
68 return calculateGregorianDateTimeUTC(exec);
69 }
70
71 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
72 {
73 return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), &s_info);
74 }
75
76 private:
77 const GregorianDateTime* calculateGregorianDateTime(ExecState*) const;
78 const GregorianDateTime* calculateGregorianDateTimeUTC(ExecState*) const;
79
80 mutable RefPtr<DateInstanceData> m_data;
81 };
82
83 DateInstance* asDateInstance(JSValue);
84
85 inline DateInstance* asDateInstance(JSValue value)
86 {
87 ASSERT(asObject(value)->inherits(&DateInstance::s_info));
88 return static_cast<DateInstance*>(asObject(value));
89 }
90
91 } // namespace JSC
92
93 #endif // DateInstance_h