Encapsulate and protect all accesses to the vtable of Heap objects
[platform/upstream/qtdeclarative.git] / src / qml / jsruntime / qv4managed.cpp
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
34 #include "qv4managed_p.h"
35 #include <private/qv4mm_p.h>
36 #include "qv4errorobject_p.h"
37
38 using namespace QV4;
39
40
41 const VTable Managed::static_vtbl =
42 {
43     0,
44     Managed::IsExecutionContext,
45     Managed::IsString,
46     Managed::IsObject,
47     Managed::IsFunctionObject,
48     Managed::IsErrorObject,
49     Managed::IsArrayData,
50     0,
51     Managed::MyType,
52     "Managed",
53     0,
54     0 /*markObjects*/,
55     isEqualTo
56 };
57
58
59 QString Managed::className() const
60 {
61     const char *s = 0;
62     switch (Type(d()->vtable()->type)) {
63     case Type_Invalid:
64     case Type_String:
65         return QString();
66     case Type_Object:
67         s = "Object";
68         break;
69     case Type_ArrayObject:
70         s = "Array";
71         break;
72     case Type_FunctionObject:
73         s = "Function";
74         break;
75     case Type_BooleanObject:
76         s = "Boolean";
77         break;
78     case Type_NumberObject:
79         s = "Number";
80         break;
81     case Type_StringObject:
82         s = "String";
83         break;
84     case Type_DateObject:
85         s = "Date";
86         break;
87     case Type_RegExpObject:
88         s = "RegExp";
89         break;
90     case Type_ErrorObject:
91         switch (static_cast<Heap::ErrorObject *>(d())->errorType) {
92         case Heap::ErrorObject::Error:
93             s = "Error";
94             break;
95         case Heap::ErrorObject::EvalError:
96             s = "EvalError";
97             break;
98         case Heap::ErrorObject::RangeError:
99             s = "RangeError";
100             break;
101         case Heap::ErrorObject::ReferenceError:
102             s = "ReferenceError";
103             break;
104         case Heap::ErrorObject::SyntaxError:
105             s = "SyntaxError";
106             break;
107         case Heap::ErrorObject::TypeError:
108             s = "TypeError";
109             break;
110         case Heap::ErrorObject::URIError:
111             s = "URIError";
112             break;
113         }
114         break;
115     case Type_ArgumentsObject:
116         s = "Arguments";
117         break;
118     case Type_JsonObject:
119         s = "JSON";
120         break;
121     case Type_MathObject:
122         s = "Math";
123         break;
124
125     case Type_ExecutionContext:
126         s = "__ExecutionContext";
127         break;
128     case Type_ForeachIteratorObject:
129         s = "__ForeachIterator";
130         break;
131     case Type_RegExp:
132         s = "__RegExp";
133         break;
134
135     case Type_QmlSequence:
136         s = "QmlSequence";
137         break;
138     }
139     return QString::fromLatin1(s);
140 }
141
142 bool Managed::isEqualTo(Managed *, Managed *)
143 {
144     return false;
145 }