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() const { return static_cast<QV4::Heap::DataClass *>(m()); }
52
53#define V4_MANAGED(DataClass, superClass)
54 private:
55 DataClass() = delete;
56 Q_DISABLE_COPY(DataClass)
57 V4_MANAGED_ITSELF(DataClass, superClass)
58 static_assert(std::is_trivially_copyable_v<QV4::Heap::DataClass>);
59 static_assert(std::is_trivially_default_constructible_v<QV4::Heap::DataClass>);
60
61#define Q_MANAGED_TYPE(type)
62 public:
63 enum { MyType = Type_##type };
64
65#define V4_INTERNALCLASS(c)
66 static Heap::InternalClass *defaultInternalClass(QV4::EngineBase *e)
67 { return e->internalClasses(QV4::EngineBase::Class_##c); }
68
70{
72 enum {
74 IsString = false,
76 IsObject = false,
80 };
81private:
82 void *operator new(size_t);
83 Managed() = delete;
85
86public:
87 enum { NInlineProperties = 0 };
88
131
132 static QString typeToString(Type);
133
135 const VTable *vtable() const { return d()->internalClass->vtable; }
136 inline ExecutionEngine *engine() const { return internalClass()->engine; }
137
142
143 bool isArrayObject() const { return d()->internalClass->vtable->type == Type_ArrayObject; }
146
147 QString className() const;
148
149 bool isEqualTo(const Managed *other) const
150 { return d()->internalClass->vtable->isEqualTo(const_cast<Managed *>(this), const_cast<Managed *>(other)); }
151
152 bool inUse() const { return d()->inUse(); }
153 bool markBit() const { return d()->isMarked(); }
154 inline void mark(MarkStack *markStack);
155
157 return m();
158 }
159
160 template<typename T> inline T *cast() {
161 return static_cast<T *>(this);
162 }
163 template<typename T> inline const T *cast() const {
164 return static_cast<const T *>(this);
165 }
166
167protected:
168 static bool virtualIsEqualTo(Managed *m, Managed *other);
169
170private:
171 friend class MemoryManager;
172 friend struct Identifiers;
173 friend struct ObjectIterator;
174};
175
177{
178 Q_ASSERT(m());
179 m()->mark(markStack);
180}
181
182template<>
183inline const Managed *Value::as() const {
184 return managed();
185}
186
187template<>
188inline const Object *Value::as() const {
189 return objectValue();
190}
191
192
218
219}
220
221
222QT_END_NAMESPACE
223
224#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