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 static_assert(std::is_trivially_copyable_v<QV4::Heap::DataClass>);
64 static_assert(std::is_trivially_default_constructible_v<QV4::Heap::DataClass>);
65
66#define Q_MANAGED_TYPE(type)
67 public:
68 enum { MyType = Type_##type };
69
70#define V4_INTERNALCLASS(c)
71 static Heap::InternalClass *defaultInternalClass(QV4::EngineBase *e)
72 { return e->internalClasses(QV4::EngineBase::Class_##c); }
73
75{
77 enum {
79 IsString = false,
81 IsObject = false,
85 };
86private:
87 void *operator new(size_t);
88 Managed() = delete;
90
91public:
92 enum { NInlineProperties = 0 };
93
136
137 static QString typeToString(Type);
138
140 const VTable *vtable() const { return d()->internalClass->vtable; }
141 inline ExecutionEngine *engine() const { return internalClass()->engine; }
142
147
148 bool isArrayObject() const { return d()->internalClass->vtable->type == Type_ArrayObject; }
151
152 QString className() const;
153
154 bool isEqualTo(const Managed *other) const
155 { return d()->internalClass->vtable->isEqualTo(const_cast<Managed *>(this), const_cast<Managed *>(other)); }
156
157 bool inUse() const { return d()->inUse(); }
158 bool markBit() const { return d()->isMarked(); }
159 inline void mark(MarkStack *markStack);
160
162 return m();
163 }
164
165 template<typename T> inline T *cast() {
166 return static_cast<T *>(this);
167 }
168 template<typename T> inline const T *cast() const {
169 return static_cast<const T *>(this);
170 }
171
172protected:
173 static bool virtualIsEqualTo(Managed *m, Managed *other);
174
175private:
176 friend class MemoryManager;
177 friend struct Identifiers;
178 friend struct ObjectIterator;
179};
180
182{
183 Q_ASSERT(m());
184 m()->mark(markStack);
185}
186
187template<>
188inline const Managed *Value::as() const {
189 return managed();
190}
191
192template<>
193inline const Object *Value::as() const {
194 return objectValue();
195}
196
197
223
224}
225
226
227QT_END_NAMESPACE
228
229#endif
Combined button and popup list for selecting options.
DECLARE_HEAP_OBJECT(StrictArgumentsObject, Object)
DECLARE_EXPORTED_HEAP_OBJECT(Object, Base)
Definition qv4object_p.h:37
DECLARE_HEAP_OBJECT(ArgumentsObject, Object)
Definition qjsvalue.h:24
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