Encapsulate and protect all accesses to the vtable of Heap objects
[platform/upstream/qtdeclarative.git] / src / qml / jsruntime / qv4dateobject_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the QtQml module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL21$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** $QT_END_LICENSE$
31 **
32 ****************************************************************************/
33 #ifndef QV4DATEOBJECT_P_H
34 #define QV4DATEOBJECT_P_H
35
36 #include "qv4object_p.h"
37 #include "qv4functionobject_p.h"
38 #include <QtCore/qnumeric.h>
39
40 QT_BEGIN_NAMESPACE
41
42 class QDateTime;
43
44 namespace QV4 {
45
46 namespace Heap {
47
48 struct DateObject : Object {
49     DateObject(InternalClass *ic, QV4::Object *prototype)
50         : Object(ic, prototype)
51     {
52         date = qSNaN();
53     }
54
55     DateObject(QV4::ExecutionEngine *engine, const Value &date)
56         : Object(engine->emptyClass, engine->datePrototype())
57     {
58         this->date = date.toNumber();
59     }
60     DateObject(QV4::ExecutionEngine *engine, const QDateTime &date);
61     double date;
62 };
63
64
65 struct DateCtor : FunctionObject {
66     DateCtor(QV4::ExecutionContext *scope);
67 };
68
69 }
70
71 struct DateObject: Object {
72     V4_OBJECT2(DateObject, Object)
73     Q_MANAGED_TYPE(DateObject)
74
75
76     double date() const { return d()->date; }
77     void setDate(double date) { d()->date = date; }
78
79     QDateTime toQDateTime() const;
80 };
81
82 template<>
83 inline const DateObject *Value::as() const {
84     return isManaged() && m() && m()->vtable()->type == Managed::Type_DateObject ? static_cast<const DateObject *>(this) : 0;
85 }
86
87 struct DateCtor: FunctionObject
88 {
89     V4_OBJECT2(DateCtor, FunctionObject)
90
91     static ReturnedValue construct(const Managed *, CallData *callData);
92     static ReturnedValue call(const Managed *that, CallData *);
93 };
94
95 struct DatePrototype: DateObject
96 {
97     void init(ExecutionEngine *engine, Object *ctor);
98
99     static double getThisDate(ExecutionContext *ctx);
100
101     static ReturnedValue method_parse(CallContext *ctx);
102     static ReturnedValue method_UTC(CallContext *ctx);
103     static ReturnedValue method_now(CallContext *ctx);
104
105     static ReturnedValue method_toString(CallContext *ctx);
106     static ReturnedValue method_toDateString(CallContext *ctx);
107     static ReturnedValue method_toTimeString(CallContext *ctx);
108     static ReturnedValue method_toLocaleString(CallContext *ctx);
109     static ReturnedValue method_toLocaleDateString(CallContext *ctx);
110     static ReturnedValue method_toLocaleTimeString(CallContext *ctx);
111     static ReturnedValue method_valueOf(CallContext *ctx);
112     static ReturnedValue method_getTime(CallContext *ctx);
113     static ReturnedValue method_getYear(CallContext *ctx);
114     static ReturnedValue method_getFullYear(CallContext *ctx);
115     static ReturnedValue method_getUTCFullYear(CallContext *ctx);
116     static ReturnedValue method_getMonth(CallContext *ctx);
117     static ReturnedValue method_getUTCMonth(CallContext *ctx);
118     static ReturnedValue method_getDate(CallContext *ctx);
119     static ReturnedValue method_getUTCDate(CallContext *ctx);
120     static ReturnedValue method_getDay(CallContext *ctx);
121     static ReturnedValue method_getUTCDay(CallContext *ctx);
122     static ReturnedValue method_getHours(CallContext *ctx);
123     static ReturnedValue method_getUTCHours(CallContext *ctx);
124     static ReturnedValue method_getMinutes(CallContext *ctx);
125     static ReturnedValue method_getUTCMinutes(CallContext *ctx);
126     static ReturnedValue method_getSeconds(CallContext *ctx);
127     static ReturnedValue method_getUTCSeconds(CallContext *ctx);
128     static ReturnedValue method_getMilliseconds(CallContext *ctx);
129     static ReturnedValue method_getUTCMilliseconds(CallContext *ctx);
130     static ReturnedValue method_getTimezoneOffset(CallContext *ctx);
131     static ReturnedValue method_setTime(CallContext *ctx);
132     static ReturnedValue method_setMilliseconds(CallContext *ctx);
133     static ReturnedValue method_setUTCMilliseconds(CallContext *ctx);
134     static ReturnedValue method_setSeconds(CallContext *ctx);
135     static ReturnedValue method_setUTCSeconds(CallContext *ctx);
136     static ReturnedValue method_setMinutes(CallContext *ctx);
137     static ReturnedValue method_setUTCMinutes(CallContext *ctx);
138     static ReturnedValue method_setHours(CallContext *ctx);
139     static ReturnedValue method_setUTCHours(CallContext *ctx);
140     static ReturnedValue method_setDate(CallContext *ctx);
141     static ReturnedValue method_setUTCDate(CallContext *ctx);
142     static ReturnedValue method_setMonth(CallContext *ctx);
143     static ReturnedValue method_setUTCMonth(CallContext *ctx);
144     static ReturnedValue method_setYear(CallContext *ctx);
145     static ReturnedValue method_setFullYear(CallContext *ctx);
146     static ReturnedValue method_setUTCFullYear(CallContext *ctx);
147     static ReturnedValue method_toUTCString(CallContext *ctx);
148     static ReturnedValue method_toISOString(CallContext *ctx);
149     static ReturnedValue method_toJSON(CallContext *ctx);
150
151     static void timezoneUpdated();
152 };
153
154 }
155
156 QT_END_NAMESPACE
157
158 #endif // QV4ECMAOBJECTS_P_H