Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qv4lookup_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant
4#ifndef QV4LOOKUP_H
5#define QV4LOOKUP_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qv4engine_p.h"
19#include "qv4object_p.h"
22#include <private/qqmltypewrapper_p.h>
23#include <private/qv4mm_p.h>
24
26
27namespace QV4 {
28
29namespace Heap {
30 struct QObjectMethod;
31}
32
33template <typename T, int PhantomTag>
35
36// Note: We cannot hide the copy ctor and assignment operator of this class because it needs to
37// be trivially copyable. But you should never ever copy it. There are refcounted members
38// in there.
39struct Q_QML_EXPORT Lookup {
96
97 // NOTE: gc assumes the first two entries in the struct are pointers to heap objects or null
98 // or that the least significant bit is 1 (see the Lookup::markObjects function)
99 union {
100 struct {
101 Heap::Base *h1;
102 Heap::Base *h2;
105 } markDef;
112 struct {
115 const Value *data;
117 } protoLookup;
124 struct {
127 const Value *data;
128 const Value *data2;
130 struct {
131 // Make sure the next two values are in sync with protoLookup
134 const Value *data;
143 struct {
146 uint index;
147 uint unused;
149 struct {
151 HeapObjectWrapper<Heap::InternalClass, 6> qmlTypeIc; // only used when lookup goes through QQmlTypeWrapper
161 struct {
162 // NB: None of this is actually cache-able. The metaobject may change at any time.
163 // We invalidate this data every time the lookup is invoked and thereby force a
164 // re-initialization next time.
165
166 quintptr metaObject; // a (const QMetaObject* | 1) or nullptr
167 quintptr metaType; // a (const QtPrivate::QMetaTypeInterface* | 1) or nullptr
168
169 // If it was negative it would be invalid. So 31 bits are enough
170 uint coreIndex: 31;
171
172 // isConstant for getter lookups, isResettable for setter ones
174
175 int notifyIndex;
177 struct {
179 quintptr metaObject; // a (const QMetaObject* & 1) or nullptr
180 const QtPrivate::QMetaTypeInterface *metaType; // cannot use QMetaType; class must be trivial
182 bool isFunction;
183 bool isEnum;
201 struct {
202 // Same as protoLookup, as used for global lookups
222 };
223
226
227 uint nameIndex: 28; // Same number of bits we store in the compilation unit for name indices
228 uint forCall: 1; // Whether we are looking up a value in order to call it right away
229 uint asVariant: 1; // Whether all types are to be converted from/to QVariant
231
236
240
255
257
261
265
276
278 if (markDef.h1 && !(reinterpret_cast<quintptr>(markDef.h1) & 1))
280 if (markDef.h2 && !(reinterpret_cast<quintptr>(markDef.h2) & 1))
282 }
283
285 {
286 switch (call) {
313 default:
314 break;
315 }
316
318 }
319
335
340
342 {
343 switch (call) {
344 case Call::Getter0Inline:
345 return getter0Inline(this, engine, object);
351 return getter0MemberData(this, engine, object);
354 case Call::GetterAccessor:
355 return getterAccessor(this, engine, object);
358 case Call::GetterEnumValue:
361 return getterFallback(this, engine, object);
363 return getterFallbackMethod(this, engine, object);
364 case Call::GetterGeneric:
365 return getterGeneric(this, engine, object);
366 case Call::GetterIndexed:
367 return getterIndexed(this, engine, object);
368 case Call::GetterProto:
369 return getterProto(this, engine, object);
371 return getterProtoAccessor(this, engine, object);
375 return primitiveGetterProto(this, engine, object);
377 return getterProtoTwoClasses(this, engine, object);
379 return getterQObject(this, engine, object);
381 // TODO: more specific implementation for interpreter / JIT
382 return getterGeneric(this, engine, object);
384 return getterQObjectMethod(this, engine, object);
390 return stringLengthGetter(this, engine, object);
392 return getterValueType(this, engine, object);
393 case Call::GetterEnum:
394 return QQmlTypeWrapper::lookupEnum(this, engine, object);
395 default:
396 break;
397 }
398
400 }
401
403 {
404 switch (call) {
405 case Call::Setter0Inline:
406 return setter0Inline(this, engine, object, value);
408 return setter0MemberData(this, engine, object, value);
409 case Call::Setter0Setter0:
410 return setter0setter0(this, engine, object, value);
412 return arrayLengthSetter(this, engine, object, value);
414 return setterFallback(this, engine, object, value);
415 case Call::SetterGeneric:
416 return setterGeneric(this, engine, object, value);
417 case Call::SetterInsert:
418 return setterInsert(this, engine, object, value);
420 return setterQObject(this, engine, object, value);
422 // TODO: more specific implementation for interpreter / JIT
423 return setterFallback(this, engine, object, value);
424 default:
425 break;
426 }
427
429 }
430
453};
454
456
458 Lookup *lookup, const QQmlData *ddata, const QQmlPropertyData *propertyData)
459{
460 lookup->releasePropertyCache();
461 Q_ASSERT(!ddata->propertyCache.isNull());
462 lookup->qobjectLookup.propertyCache = ddata->propertyCache.data();
463 lookup->qobjectLookup.propertyCache->addref();
464 lookup->qobjectLookup.propertyData = propertyData;
465}
466
468 Lookup *lookup, const QQmlData *ddata, const QQmlPropertyData *propertyData,
469 const Object *self)
470{
471 setupQObjectLookup(lookup, ddata, propertyData);
472 lookup->qobjectLookup.ic.set(self->engine(), self->internalClass());
473}
474
475
477 Lookup *lookup, const QQmlData *ddata, const QQmlPropertyData *propertyData,
478 const Object *self, const Object *qmlType)
479{
480 setupQObjectLookup(lookup, ddata, propertyData, self);
481 lookup->qobjectLookup.qmlTypeIc.set(self->engine(), qmlType->internalClass());
482}
483
484// template parameter is an ugly trick to avoid pulling in the QObjectMethod header here
485template<typename QObjectMethod = Heap::QObjectMethod>
487 Lookup *lookup, const QQmlPropertyCache::ConstPtr &propertyCache,
488 const QQmlPropertyData *propertyData, const Object *self, QObjectMethod *method)
489{
490 lookup->releasePropertyCache();
491 Q_ASSERT(!propertyCache.isNull());
492 auto engine = self->engine();
493 lookup->qobjectMethodLookup.method.set(engine, method);
494 lookup->qobjectMethodLookup.ic.set(engine, self->internalClass());
495 lookup->qobjectMethodLookup.propertyCache = propertyCache.data();
496 lookup->qobjectMethodLookup.propertyCache->addref();
497 lookup->qobjectMethodLookup.propertyData = propertyData;
498}
499
500inline bool qualifiesForMethodLookup(const QQmlPropertyData *propertyData)
501{
502 return propertyData->isFunction()
503 && !propertyData->isSignalHandler() // TODO: Optimize SignalHandler, too
504 && !propertyData->isVMEFunction() // Handled by QObjectLookup
505 && !propertyData->isVarProperty();
506}
507
508}
509
510QT_END_NAMESPACE
511
512#endif
Combined button and popup list for selecting options.
Definition qjsvalue.h:24
void setupQObjectLookup(Lookup *lookup, const QQmlData *ddata, const QQmlPropertyData *propertyData, const Object *self, const Object *qmlType)
void setupQObjectLookup(Lookup *lookup, const QQmlData *ddata, const QQmlPropertyData *propertyData)
bool qualifiesForMethodLookup(const QQmlPropertyData *propertyData)
void setupQObjectMethodLookup(Lookup *lookup, const QQmlPropertyCache::ConstPtr &propertyCache, const QQmlPropertyData *propertyData, const Object *self, QObjectMethod *method)
void setupQObjectLookup(Lookup *lookup, const QQmlData *ddata, const QQmlPropertyData *propertyData, const Object *self)
static void setupProtoLookupTwoClasses(Lookup *lookup, const Lookup &first, const Lookup &second)
static void setupObjectLookupTwoClasses(Lookup *lookup, const Lookup &first, const Lookup &second)