1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQml module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
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 https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://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 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39#ifndef QV4LOOKUP_H
40#define QV4LOOKUP_H
41
42//
43// W A R N I N G
44// -------------
45//
46// This file is not part of the Qt API. It exists purely as an
47// implementation detail. This header file may change from version to
48// version without notice, or even be removed.
49//
50// We mean it.
51//
52
53#include "qv4global_p.h"
54#include "qv4runtime_p.h"
55#include "qv4engine_p.h"
56#include "qv4context_p.h"
57#include "qv4object_p.h"
58#include "qv4internalclass_p.h"
59
60QT_BEGIN_NAMESPACE
61
62namespace QV4 {
63
64struct Q_QML_PRIVATE_EXPORT Lookup {
65 union {
66 ReturnedValue (*getter)(Lookup *l, ExecutionEngine *engine, const Value &object);
67 ReturnedValue (*globalGetter)(Lookup *l, ExecutionEngine *engine);
68 ReturnedValue (*qmlContextPropertyGetter)(Lookup *l, ExecutionEngine *engine, Value *thisObject);
69 bool (*setter)(Lookup *l, ExecutionEngine *engine, Value &object, const Value &v);
70 };
71 // NOTE: gc assumes the first two entries in the struct are pointers to heap objects or null
72 union {
73 struct {
74 Heap::Base *h1;
75 Heap::Base *h2;
76 quintptr unused;
77 quintptr unused2;
78 } markDef;
79 struct {
80 Heap::InternalClass *ic;
81 quintptr unused;
82 uint index;
83 uint offset;
84 } objectLookup;
85 struct {
86 quintptr protoId;
87 quintptr _unused;
88 const Value *data;
89 } protoLookup;
90 struct {
91 Heap::InternalClass *ic;
92 Heap::InternalClass *ic2;
93 uint offset;
94 uint offset2;
95 } objectLookupTwoClasses;
96 struct {
97 quintptr protoId;
98 quintptr protoId2;
99 const Value *data;
100 const Value *data2;
101 } protoLookupTwoClasses;
102 struct {
103 // Make sure the next two values are in sync with protoLookup
104 quintptr protoId;
105 Heap::Object *proto;
106 const Value *data;
107 quintptr type;
108 } primitiveLookup;
109 struct {
110 Heap::InternalClass *newClass;
111 quintptr protoId;
112 uint offset;
113 uint unused;
114 } insertionLookup;
115 struct {
116 quintptr _unused;
117 quintptr _unused2;
118 uint index;
119 uint unused;
120 } indexedLookup;
121 struct {
122 Heap::InternalClass *ic;
123 Heap::InternalClass *qmlTypeIc; // only used when lookup goes through QQmlTypeWrapper
124 QQmlPropertyCache *propertyCache;
125 QQmlPropertyData *propertyData;
126 } qobjectLookup;
127 struct {
128 Heap::InternalClass *ic;
129 quintptr unused;
130 QQmlPropertyCache *propertyCache;
131 QQmlPropertyData *propertyData;
132 } qgadgetLookup;
133 struct {
134 quintptr unused1;
135 quintptr unused2;
136 int scriptIndex;
137 } qmlContextScriptLookup;
138 struct {
139 Heap::Object *singleton;
140 quintptr unused;
141 } qmlContextSingletonLookup;
142 struct {
143 quintptr unused1;
144 quintptr unused2;
145 int objectId;
146 } qmlContextIdObjectLookup;
147 struct {
148 // Same as protoLookup, as used for global lookups
149 quintptr reserved1;
150 quintptr reserved2;
151 quintptr reserved3;
152 ReturnedValue (*getterTrampoline)(Lookup *l, ExecutionEngine *engine);
153 } qmlContextGlobalLookup;
154 };
155 uint nameIndex;
156
157 ReturnedValue resolveGetter(ExecutionEngine *engine, const Object *object);
158 ReturnedValue resolvePrimitiveGetter(ExecutionEngine *engine, const Value &object);
159 ReturnedValue resolveGlobalGetter(ExecutionEngine *engine);
160 void resolveProtoGetter(PropertyKey name, const Heap::Object *proto);
161
162 static ReturnedValue getterGeneric(Lookup *l, ExecutionEngine *engine, const Value &object);
163 static ReturnedValue getterTwoClasses(Lookup *l, ExecutionEngine *engine, const Value &object);
164 static ReturnedValue getterFallback(Lookup *l, ExecutionEngine *engine, const Value &object);
165
166 static ReturnedValue getter0MemberData(Lookup *l, ExecutionEngine *engine, const Value &object);
167 static ReturnedValue getter0Inline(Lookup *l, ExecutionEngine *engine, const Value &object);
168 static ReturnedValue getterProto(Lookup *l, ExecutionEngine *engine, const Value &object);
169 static ReturnedValue getter0Inlinegetter0Inline(Lookup *l, ExecutionEngine *engine, const Value &object);
170 static ReturnedValue getter0Inlinegetter0MemberData(Lookup *l, ExecutionEngine *engine, const Value &object);
171 static ReturnedValue getter0MemberDatagetter0MemberData(Lookup *l, ExecutionEngine *engine, const Value &object);
172 static ReturnedValue getterProtoTwoClasses(Lookup *l, ExecutionEngine *engine, const Value &object);
173 static ReturnedValue getterAccessor(Lookup *l, ExecutionEngine *engine, const Value &object);
174 static ReturnedValue getterProtoAccessor(Lookup *l, ExecutionEngine *engine, const Value &object);
175 static ReturnedValue getterProtoAccessorTwoClasses(Lookup *l, ExecutionEngine *engine, const Value &object);
176 static ReturnedValue getterIndexed(Lookup *l, ExecutionEngine *engine, const Value &object);
177
178 static ReturnedValue primitiveGetterProto(Lookup *l, ExecutionEngine *engine, const Value &object);
179 static ReturnedValue primitiveGetterAccessor(Lookup *l, ExecutionEngine *engine, const Value &object);
180 static ReturnedValue stringLengthGetter(Lookup *l, ExecutionEngine *engine, const Value &object);
181
182 static ReturnedValue globalGetterGeneric(Lookup *l, ExecutionEngine *engine);
183 static ReturnedValue globalGetterProto(Lookup *l, ExecutionEngine *engine);
184 static ReturnedValue globalGetterProtoAccessor(Lookup *l, ExecutionEngine *engine);
185
186 bool resolveSetter(ExecutionEngine *engine, Object *object, const Value &value);
187 static bool setterGeneric(Lookup *l, ExecutionEngine *engine, Value &object, const Value &value);
188 Q_NEVER_INLINE static bool setterTwoClasses(Lookup *l, ExecutionEngine *engine, Value &object, const Value &value);
189 static bool setterFallback(Lookup *l, ExecutionEngine *engine, Value &object, const Value &value);
190 static bool setter0MemberData(Lookup *l, ExecutionEngine *engine, Value &object, const Value &value);
191 static bool setter0Inline(Lookup *l, ExecutionEngine *engine, Value &object, const Value &value);
192 static bool setter0setter0(Lookup *l, ExecutionEngine *engine, Value &object, const Value &value);
193 static bool setterInsert(Lookup *l, ExecutionEngine *engine, Value &object, const Value &value);
194 static bool arrayLengthSetter(Lookup *l, ExecutionEngine *engine, Value &object, const Value &value);
195
196 void markObjects(MarkStack *stack) {
197 if (markDef.h1 && !(reinterpret_cast<quintptr>(markDef.h1) & 1))
198 markDef.h1->mark(stack);
199 if (markDef.h2 && !(reinterpret_cast<quintptr>(markDef.h2) & 1))
200 markDef.h2->mark(stack);
201 }
202
203 void clear() {
204 memset(&markDef, 0, sizeof(markDef));
205 }
206};
207
208Q_STATIC_ASSERT(std::is_standard_layout<Lookup>::value);
209// Ensure that these offsets are always at this point to keep generated code compatible
210// across 32-bit and 64-bit (matters when cross-compiling).
211Q_STATIC_ASSERT(offsetof(Lookup, getter) == 0);
212
213}
214
215QT_END_NAMESPACE
216
217#endif
218