]> git.saurik.com Git - apple/javascriptcore.git/blame_incremental - runtime/DateInstance.h
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / runtime / DateInstance.h
... / ...
CommitLineData
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
26namespace JSC {
27
28class DateInstance : public JSWrapperObject {
29protected:
30 JS_EXPORT_PRIVATE DateInstance(VM&, Structure*);
31 void finishCreation(VM&);
32 JS_EXPORT_PRIVATE void finishCreation(VM&, double);
33
34 JS_EXPORT_PRIVATE static void destroy(JSCell*);
35
36public:
37 typedef JSWrapperObject Base;
38
39 static DateInstance* create(VM& vm, Structure* structure, double date)
40 {
41 DateInstance* instance = new (NotNull, allocateCell<DateInstance>(vm.heap)) DateInstance(vm, structure);
42 instance->finishCreation(vm, date);
43 return instance;
44 }
45
46 static DateInstance* create(VM& vm, Structure* structure)
47 {
48 DateInstance* instance = new (NotNull, allocateCell<DateInstance>(vm.heap)) DateInstance(vm, structure);
49 instance->finishCreation(vm);
50 return instance;
51 }
52
53 double internalNumber() const { return internalValue().asNumber(); }
54
55 DECLARE_EXPORT_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), info());
74 }
75
76private:
77 JS_EXPORT_PRIVATE const GregorianDateTime* calculateGregorianDateTime(ExecState*) const;
78 JS_EXPORT_PRIVATE const GregorianDateTime* calculateGregorianDateTimeUTC(ExecState*) const;
79
80 mutable RefPtr<DateInstanceData> m_data;
81};
82
83DateInstance* asDateInstance(JSValue);
84
85inline DateInstance* asDateInstance(JSValue value)
86{
87 ASSERT(asObject(value)->inherits(DateInstance::info()));
88 return static_cast<DateInstance*>(asObject(value));
89}
90
91} // namespace JSC
92
93#endif // DateInstance_h