]> git.saurik.com Git - apple/javascriptcore.git/blame - runtime/DateInstance.h
JavaScriptCore-7600.1.4.9.tar.gz
[apple/javascriptcore.git] / runtime / DateInstance.h
CommitLineData
b37bf2e1
A
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
9dae56ea
A
21#ifndef DateInstance_h
22#define DateInstance_h
b37bf2e1 23
b37bf2e1
A
24#include "JSWrapperObject.h"
25
ba379fdc 26namespace JSC {
9dae56ea
A
27
28 class DateInstance : public JSWrapperObject {
6fe7ccc8 29 protected:
81345200 30 JS_EXPORT_PRIVATE DateInstance(VM&, Structure*);
93a37866
A
31 void finishCreation(VM&);
32 JS_EXPORT_PRIVATE void finishCreation(VM&, double);
6fe7ccc8
A
33
34 static void destroy(JSCell*);
35
b37bf2e1 36 public:
6fe7ccc8
A
37 typedef JSWrapperObject Base;
38
81345200 39 static DateInstance* create(VM& vm, Structure* structure, double date)
6fe7ccc8 40 {
81345200
A
41 DateInstance* instance = new (NotNull, allocateCell<DateInstance>(vm.heap)) DateInstance(vm, structure);
42 instance->finishCreation(vm, date);
6fe7ccc8
A
43 return instance;
44 }
45
81345200 46 static DateInstance* create(VM& vm, Structure* structure)
6fe7ccc8 47 {
81345200
A
48 DateInstance* instance = new (NotNull, allocateCell<DateInstance>(vm.heap)) DateInstance(vm, structure);
49 instance->finishCreation(vm);
6fe7ccc8
A
50 return instance;
51 }
9dae56ea 52
6fe7ccc8 53 double internalNumber() const { return internalValue().asNumber(); }
9dae56ea 54
81345200 55 DECLARE_EXPORT_INFO;
f9bf01c6
A
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
93a37866 71 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
f9bf01c6 72 {
81345200 73 return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
f9bf01c6
A
74 }
75
9dae56ea 76 private:
f9bf01c6
A
77 const GregorianDateTime* calculateGregorianDateTime(ExecState*) const;
78 const GregorianDateTime* calculateGregorianDateTimeUTC(ExecState*) const;
b37bf2e1 79
f9bf01c6 80 mutable RefPtr<DateInstanceData> m_data;
b37bf2e1
A
81 };
82
ba379fdc 83 DateInstance* asDateInstance(JSValue);
9dae56ea 84
ba379fdc 85 inline DateInstance* asDateInstance(JSValue value)
9dae56ea 86 {
81345200 87 ASSERT(asObject(value)->inherits(DateInstance::info()));
9dae56ea
A
88 return static_cast<DateInstance*>(asObject(value));
89 }
90
91} // namespace JSC
b37bf2e1 92
9dae56ea 93#endif // DateInstance_h