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
qv4managed_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 QMLJS_MANAGED_H
5#define QMLJS_MANAGED_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 "qv4global_p.h"
19#include "qv4value_p.h"
21#include <private/qv4heap_p.h>
22#include <private/qv4vtable_p.h>
23
25
26namespace QV4 {
27
28#define Q_MANAGED_CHECK
29 template <typename Type> inline void qt_check_for_QMANAGED_macro(const Type *_q_argument) const
30 { int i = qYouForgotTheQ_MANAGED_Macro(this, _q_argument); i = i + 1; }
31
32template <typename T>
33inline int qYouForgotTheQ_MANAGED_Macro(T, T) { return 0; }
34
35template <typename T1, typename T2>
36inline void qYouForgotTheQ_MANAGED_Macro(T1, T2) {}
37
38#define V4_MANAGED_SIZE_TEST void __dataTest() { static_assert (sizeof(*this) == sizeof(Managed), "Classes derived from Managed can't have own data members."); }
39
40#define V4_NEEDS_DESTROY static void virtualDestroy(QV4::Heap::Base *b) { static_cast<Data *>(b)->destroy(); }
41
42
43#define V4_MANAGED_ITSELF(DataClass, superClass)
44 public:
46 typedef QV4::Heap::DataClass Data;
47 typedef superClass SuperClass;
48 static const QV4::VTable static_vtbl;
49 static inline const QV4::VTable *staticVTable() { return &static_vtbl; }
51 QV4::Heap::DataClass *d_unchecked() const { return static_cast<QV4::Heap::DataClass *>(m()); }
52 QV4::Heap::DataClass *d() const {
53 QV4::Heap::DataClass *dptr = d_unchecked();
54 dptr->_checkIsInitialized();
55 return dptr;
56 }
57
58#define V4_MANAGED(DataClass, superClass)
59 private:
60 DataClass() = delete;
61 Q_DISABLE_COPY(DataClass)
62 V4_MANAGED_ITSELF(DataClass, superClass)
63 Q_STATIC_ASSERT(std::is_trivial_v<QV4::Heap::DataClass>);
64
65#define Q_MANAGED_TYPE(type)
66 public:
67 enum { MyType = Type_##type };
68
69#define V4_INTERNALCLASS(c)
70 static Heap::InternalClass *defaultInternalClass(QV4::EngineBase *e)
71 { return e->internalClasses(QV4::EngineBase::Class_##c); }
72
74{
76 enum {
78 IsString = false,
80 IsObject = false,
84 };
85private:
86 void *operator new(size_t);
87 Managed() = delete;
89
90public:
91 enum { NInlineProperties = 0 };
92
135
136 static QString typeToString(Type);
137
139 const VTable *vtable() const { return d()->internalClass->vtable; }
140 inline ExecutionEngine *engine() const { return internalClass()->engine; }
141
146
147 bool isArrayObject() const { return d()->internalClass->vtable->type == Type_ArrayObject; }
150
151 QString className() const;
152
153 bool isEqualTo(const Managed *other) const
154 { return d()->internalClass->vtable->isEqualTo(const_cast<Managed *>(this), const_cast<Managed *>(other)); }
155
156 bool inUse() const { return d()->inUse(); }
157 bool markBit() const { return d()->isMarked(); }
158 inline void mark(MarkStack *markStack);
159
161 return m();
162 }
163
164 template<typename T> inline T *cast() {
165 return static_cast<T *>(this);
166 }
167 template<typename T> inline const T *cast() const {
168 return static_cast<const T *>(this);
169 }
170
171protected:
172 static bool virtualIsEqualTo(Managed *m, Managed *other);
173
174private:
175 friend class MemoryManager;
176 friend struct Identifiers;
177 friend struct ObjectIterator;
178};
179
181{
182 Q_ASSERT(m());
183 m()->mark(markStack);
184}
185
186template<>
187inline const Managed *Value::as() const {
188 return managed();
189}
190
191template<>
192inline const Object *Value::as() const {
193 return objectValue();
194}
195
196
222
223}
224
225
226QT_END_NAMESPACE
227
228#endif
DECLARE_HEAP_OBJECT(StrictArgumentsObject, Object)
DECLARE_EXPORTED_HEAP_OBJECT(Object, Base)
Definition qv4object_p.h:37
DECLARE_HEAP_OBJECT(ArgumentsObject, Object)
Definition qjsvalue.h:23
int qYouForgotTheQ_MANAGED_Macro(T, T)
void qYouForgotTheQ_MANAGED_Macro(T1, T2)
DEFINE_OBJECT_VTABLE(StrictArgumentsObject)
DEFINE_OBJECT_VTABLE(ArgumentsObject)
#define V4_MANAGED_SIZE_TEST
#define V4_NEEDS_DESTROY
#define V4_MANAGED_ITSELF(DataClass, superClass)
#define Q_MANAGED_TYPE(type)
#define V4_INTERNALCLASS(c)
#define Q_MANAGED_CHECK
static qint64 virtualGetLength(const Managed *m)
static bool virtualDefineOwnProperty(Managed *m, PropertyKey id, const Property *desc, PropertyAttributes attrs)
Heap::CallContext * context() const
static ReturnedValue virtualGet(const Managed *m, PropertyKey id, const Value *receiver, bool *hasProperty)
static OwnPropertyKeyIterator * virtualOwnPropertyKeys(const Object *m, Value *target)
static bool isNonStrictArgumentsObject(Managed *m)
static bool virtualDeleteProperty(Managed *m, PropertyKey id)
static PropertyAttributes virtualGetOwnProperty(const Managed *m, PropertyKey id, Property *p)
bool isMapped(uint arg) const
static bool virtualPut(Managed *m, PropertyKey id, const Value &value, Value *receiver)
static bool virtualDefineOwnProperty(Managed *m, PropertyKey id, const Property *p, PropertyAttributes attrs)
static qint64 virtualGetLength(const Managed *m)
QStringList toQStringList() const
void init(const QStringList &list)
void init(double val)
PropertyKey next(const Object *o, Property *pd=nullptr, PropertyAttributes *attrs=nullptr) override