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#ifndef QMLJS_MANAGED_H
4#define QMLJS_MANAGED_H
5
6//
7// W A R N I N G
8// -------------
9//
10// This file is not part of the Qt API. It exists purely as an
11// implementation detail. This header file may change from version to
12// version without notice, or even be removed.
13//
14// We mean it.
15//
16
17#include "qv4global_p.h"
18#include "qv4value_p.h"
20#include <private/qv4heap_p.h>
21#include <private/qv4vtable_p.h>
22
24
25namespace QV4 {
26
27#define Q_MANAGED_CHECK
28 template <typename Type> inline void qt_check_for_QMANAGED_macro(const Type *_q_argument) const
29 { int i = qYouForgotTheQ_MANAGED_Macro(this, _q_argument); i = i + 1; }
30
31template <typename T>
32inline int qYouForgotTheQ_MANAGED_Macro(T, T) { return 0; }
33
34template <typename T1, typename T2>
35inline void qYouForgotTheQ_MANAGED_Macro(T1, T2) {}
36
37#define V4_MANAGED_SIZE_TEST void __dataTest() { static_assert (sizeof(*this) == sizeof(Managed), "Classes derived from Managed can't have own data members."); }
38
39#define V4_NEEDS_DESTROY static void virtualDestroy(QV4::Heap::Base *b) { static_cast<Data *>(b)->destroy(); }
40
41
42#define V4_MANAGED_ITSELF(DataClass, superClass)
43 public:
45 typedef QV4::Heap::DataClass Data;
46 typedef superClass SuperClass;
47 static const QV4::VTable static_vtbl;
48 static inline const QV4::VTable *staticVTable() { return &static_vtbl; }
50 QV4::Heap::DataClass *d_unchecked() const { return static_cast<QV4::Heap::DataClass *>(m()); }
51 QV4::Heap::DataClass *d() const {
52 QV4::Heap::DataClass *dptr = d_unchecked();
53 dptr->_checkIsInitialized();
54 return dptr;
55 }
56
57#define V4_MANAGED(DataClass, superClass)
58 private:
59 DataClass() = delete;
60 Q_DISABLE_COPY(DataClass)
61 V4_MANAGED_ITSELF(DataClass, superClass)
62 Q_STATIC_ASSERT(std::is_trivial_v<QV4::Heap::DataClass>);
63
64#define Q_MANAGED_TYPE(type)
65 public:
66 enum { MyType = Type_##type };
67
68#define V4_INTERNALCLASS(c)
69 static Heap::InternalClass *defaultInternalClass(QV4::EngineBase *e)
70 { return e->internalClasses(QV4::EngineBase::Class_##c); }
71
73{
75 enum {
77 IsString = false,
79 IsObject = false,
82 IsArrayData = false
83 };
84private:
85 void *operator new(size_t);
86 Managed() = delete;
88
89public:
90 enum { NInlineProperties = 0 };
91
128
130 const VTable *vtable() const { return d()->internalClass->vtable; }
131 inline ExecutionEngine *engine() const { return internalClass()->engine; }
132
136
137 bool isArrayObject() const { return d()->internalClass->vtable->type == Type_ArrayObject; }
140
141 QString className() const;
142
143 bool isEqualTo(const Managed *other) const
144 { return d()->internalClass->vtable->isEqualTo(const_cast<Managed *>(this), const_cast<Managed *>(other)); }
145
146 bool inUse() const { return d()->inUse(); }
147 bool markBit() const { return d()->isMarked(); }
148 inline void mark(MarkStack *markStack);
149
151 return m();
152 }
153
154 template<typename T> inline T *cast() {
155 return static_cast<T *>(this);
156 }
157 template<typename T> inline const T *cast() const {
158 return static_cast<const T *>(this);
159 }
160
161protected:
162 static bool virtualIsEqualTo(Managed *m, Managed *other);
163
164private:
165 friend class MemoryManager;
166 friend struct Identifiers;
167 friend struct ObjectIterator;
168};
169
171{
172 Q_ASSERT(m());
173 m()->mark(markStack);
174}
175
176template<>
177inline const Managed *Value::as() const {
178 return managed();
179}
180
181template<>
182inline const Object *Value::as() const {
183 return objectValue();
184}
185
186
212
213}
214
215
216QT_END_NAMESPACE
217
218#endif
\inmodule QtQml
bool isString() const
Returns true if the type of this QJSManagedValue is string, or false otherwise.
QJSEngine * engine() const
Returns the QJSEngine this QJSManagedValue belongs to.
bool deleteProperty(quint32 arrayIndex)
Deletes the value stored at arrayIndex from this QJSManagedValue.
friend class QJSEngine
QJSValue toJSValue() const
Copies this QJSManagedValue into a new QJSValue.
QJSManagedValue jsMetaType() const
bool isBoolean() const
Returns true if the type of this QJSManagedValue is boolean, or false otherwise.
const QMetaObject * toQMetaObject() const
If this QJSManagedValue holds a QMetaObject pointer, returns it.
QStringList jsMetaMembers() const
bool isArray() const
Returns true if this value represents a JavaScript Array object, or false otherwise.
bool isError() const
Returns true if this value represents a JavaScript Error object, or false otherwise.
bool strictlyEquals(const QJSManagedValue &other) const
Invokes the JavaScript '===' operator on this QJSManagedValue and other, and returns the result.
bool hasProperty(const QString &name) const
Returns true if this QJSManagedValue has a property name, otherwise returns false.
QJSValue call(const QJSValueList &arguments={}) const
If this QJSManagedValue represents a JavaScript FunctionObject, calls it with the given arguments,...
QObject * toQObject() const
If this QJSManagedValue holds a QObject pointer, returns it.
bool isRegularExpression() const
Returns true if this value represents a JavaScript regular expression object, or false otherwise.
QJSValue property(const QString &name) const
Returns the property name of this QJSManagedValue.
QJSManagedValue jsMetaInstantiate(const QJSValueList &values={}) const
bool hasOwnProperty(quint32 arrayIndex) const
Returns true if this QJSManagedValue has an array index arrayIndex, otherwise returns false.
QVariant toVariant() const
Copies this QJSManagedValue into a new QVariant.
bool hasProperty(quint32 arrayIndex) const
Returns true if this QJSManagedValue has an array index arrayIndex, otherwise returns false.
double toNumber() const
Converts the manged value to a number.
QJSManagedValue & operator=(QJSManagedValue &&other)
Move-assigns a QJSManagedValue from other.
QJSValue callAsConstructor(const QJSValueList &arguments={}) const
If this QJSManagedValue represents a JavaScript FunctionObject, calls it as constructor with the give...
bool isVariant() const
Returns true if this value represents a QVariant managed on the JavaScript heap, or false otherwise.
bool isFunction() const
Returns true if the type of this QJSManagedValue is function, false otherwise.
QRegularExpression toRegularExpression() const
If this QJSManagedValue holds a JavaScript regular expression object, returns an equivalent QRegularE...
QJSManagedValue prototype() const
Returns the prototype for this QJSManagedValue.
bool isUndefined() const
Returns true if the type of this QJSManagedValue is undefined, or false otherwise.
bool isDate() const
Returns true if this value represents a JavaScript Date object, or false otherwise.
bool equals(const QJSManagedValue &other) const
Invokes the JavaScript '==' operator on this QJSManagedValue and other, and returns the result.
~QJSManagedValue()
Destroys the QJSManagedValue.
QJSPrimitiveValue toPrimitive() const
Converts the manged value to a QJSPrimitiveValue.
bool deleteProperty(const QString &name)
Deletes the property name from this QJSManagedValue.
bool isQMetaObject() const
Returns true if this value represents a QMetaObject pointer managed on the JavaScript heap,...
QDateTime toDateTime() const
If this QJSManagedValue holds a JavaScript Date object, returns an equivalent QDateTime.
int toInteger() const
Converts the manged value to an integer.
QString toString() const
Converts the manged value to a string.
QUrl toUrl() const
If this QJSManagedValue holds a JavaScript Url object, returns an equivalent QUrl.
bool isQObject() const
Returns true if this value represents a QObject pointer managed on the JavaScript heap,...
bool hasOwnProperty(const QString &name) const
Returns true if this QJSManagedValue has a property name, otherwise returns false.
void setPrototype(const QJSManagedValue &prototype)
Sets the prototype of this QJSManagedValue to prototype.
bool isUrl() const
Returns true if this value represents a JavaScript Url object, or false otherwise.
bool isInteger() const
Returns true if this QJSManagedValue holds an integer value, or false otherwise.
bool isNumber() const
Returns true if the type of this QJSManagedValue is number, or false otherwise.
bool isNull() const
Returns true if this QJSManagedValue holds the JavaScript null value, or false otherwise.
bool isSymbol() const
Returns true if the type of this QJSManagedValue is symbol, or false otherwise.
bool isObject() const
Returns true if the type of this QJSManagedValue is object, or false otherwise.
void setProperty(const QString &name, const QJSValue &value)
Sets the property name to value on this QJSManagedValue.
void setProperty(quint32 arrayIndex, const QJSValue &value)
Stores the value at arrayIndex in this QJSManagedValue.
bool toBoolean() const
Converts the manged value to a boolean.
QJSValue callWithInstance(const QJSValue &instance, const QJSValueList &arguments={}) const
If this QJSManagedValue represents a JavaScript FunctionObject, calls it on instance with the given a...
bool isJsMetaType() const
The QJSPrimitiveValue class operates on primitive types in JavaScript semantics.
static QV4::ExecutionEngine * engine(const QJSValue *jsval)
Definition qjsvalue_p.h:321
The QJSValue class acts as a container for Qt/JavaScript data types.
Definition qjsvalue.h:31
virtual Type type() const =0
Reimplement this function to return the paint engine \l{Type}.
virtual QVariant property(QPrintDevice::PrintDevicePropertyKey key) const
ReturnedValue operator*() const
Definition qv4value_p.h:471
OptionalReturnedValue(ReturnedValue v)
Definition qv4value_p.h:464
ReturnedValue operator->() const
Definition qv4value_p.h:470
Combined button and popup list for selecting options.
DECLARE_EXPORTED_HEAP_OBJECT(Object, Base)
Definition qv4object_p.h:36
CallResultDestination
Definition qjsvalue.h:23
Scoped< FunctionObject > ScopedFunctionObject
QVector< StackFrame > StackTrace
int qYouForgotTheQ_MANAGED_Macro(T, T)
Scoped< Object > ScopedObject
ReturnedValue value_convert(ExecutionEngine *e, const Value &v)
Scoped< ArrayObject > ScopedArrayObject
Scoped< String > ScopedString
Scoped< StringOrSymbol > ScopedStringOrSymbol
void qYouForgotTheQ_MANAGED_Macro(T1, T2)
PropertyFlag
@ Attr_Invalid
@ Attr_NotConfigurable
@ Attr_Data
@ Attr_NotEnumerable
@ Attr_ReadOnly
@ Attr_NotWritable
@ Attr_ReadOnly_ButConfigurable
@ Attr_Accessor
Q_STATIC_ASSERT(std::is_trivial_v< Value >)
Scoped< ExecutionContext > ScopedContext
T caughtResult(const QJSValue *v, T(QV4::Value::*convert)() const)
Definition qjsvalue.cpp:503
static bool js_equal(const QString &string, const QV4::Value &value)
Definition qjsvalue.cpp:958
QDataStream & operator<<(QDataStream &stream, const QJSValue &jsv)
QDataStream & operator>>(QDataStream &stream, QJSValue &jsv)
QList< QJSValue > QJSValueList
Definition qjsvalue.h:22
Q_DECLARE_TYPEINFO(QObjectPrivate::ConnectionList, Q_RELOCATABLE_TYPE)
#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
double d
[1]
static bool virtualDefineOwnProperty(Managed *m, PropertyKey id, const Property *p, PropertyAttributes attrs)
static qint64 virtualGetLength(const Managed *m)
QStringList toQStringList() const
static constexpr size_t offset
Definition qv4value_p.h:405
void set(EngineBase *e, HeapBasePtr b)
Definition qv4value_p.h:415
HeapBasePtr base()
Definition qv4value_p.h:406
void set(EngineBase *e, const Value &newVal)
Definition qv4value_p.h:412
void init(const QStringList &list)
void init(double val)
PropertyKey next(const Object *o, Property *pd=nullptr, PropertyAttributes *attrs=nullptr) override
Value::HeapBasePtr base()
Definition qv4value_p.h:427
void mark(MarkStack *markStack)
Definition qv4value_p.h:448
static constexpr size_t offset
Definition qv4value_p.h:422
void set(EngineBase *e, uint index, Value::HeapBasePtr b)
Definition qv4value_p.h:437
const Value * data() const
Definition qv4value_p.h:444
Value values[1]
Definition qv4value_p.h:425
void set(EngineBase *e, uint index, Value v)
Definition qv4value_p.h:434
const Value & operator[](uint index) const
Definition qv4value_p.h:440