Qt
6.x
The Qt SDK
Loading...
Searching...
No Matches
qv4referenceobject_p.h
Go to the documentation of this file.
1
// Copyright (C) 2022 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
4
#ifndef QV4REFERENCEOBJECT_P_H
5
#define QV4REFERENCEOBJECT_P_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 <private/qv4object_p.h>
19
#include <private/qv4stackframe_p.h>
20
21
QT_BEGIN_NAMESPACE
22
23
namespace
QV4
{
24
namespace
Heap {
25
26
27
#define ReferenceObjectMembers(class, Member) \
28
Member(class, Pointer, Object *, m_object)
29
30
DECLARE_HEAP_OBJECT
(
ReferenceObject
,
Object
) {
31
DECLARE_MARKOBJECTS
(
ReferenceObject
);
32
33
enum
Flag :
quint8
{
34
NoFlag = 0,
35
CanWriteBack = 1 << 0,
36
IsVariant = 1 << 1,
37
EnforcesLocation = 1 << 2,
38
};
39
Q_DECLARE_FLAGS
(
Flags
, Flag);
40
41
void
init
(
Object
*
object
,
int
property
,
Flags
flags
)
42
{
43
setObject(
object
);
44
m_property =
property
;
45
m_flags =
flags
;
46
Object::init();
47
}
48
49
Flags
flags
()
const
{
return
Flags
(m_flags); }
50
51
Object
*
object
()
const
{
return
m_object.get(); }
52
void
setObject(
Object
*
object
) { m_object.set(internalClass->engine,
object
); }
53
54
int
property
()
const
{
return
m_property; }
55
56
bool
canWriteBack()
const
{
return
hasFlag(CanWriteBack); }
57
bool
isVariant()
const
{
return
hasFlag(IsVariant); }
58
bool
enforcesLocation()
const
{
return
hasFlag(EnforcesLocation); }
59
60
void
setLocation(
const
Function
*
function
,
quint16
statement)
61
{
62
m_function =
function
;
63
m_statementIndex = statement;
64
}
65
66
const
Function
*
function
()
const
{
return
m_function; }
67
quint16
statementIndex()
const
{
return
m_statementIndex; }
68
69
bool
isAttachedToProperty()
const
70
{
71
if
(enforcesLocation()) {
72
if
(
CppStackFrame
*
frame
= internalClass->engine->currentStackFrame) {
73
if
(
frame
->v4Function !=
function
() ||
frame
->statementNumber() != statementIndex())
74
return
false
;
75
}
else
{
76
return
false
;
77
}
78
}
79
80
return
true
;
81
}
82
83
bool
isReference()
const
{
return
m_object; }
84
85
private
:
86
87
bool
hasFlag(Flag flag)
const
88
{
89
return
m_flags &
quint8
(flag);
90
}
91
92
void
setFlag(Flag flag,
bool
set
)
93
{
94
m_flags =
set
? (m_flags |
quint8
(flag)) : (m_flags &
~quint8
(flag));
95
}
96
97
const
Function
*m_function;
98
int
m_property;
99
quint16
m_statementIndex;
100
quint8
m_flags;
101
};
102
103
Q_DECLARE_OPERATORS_FOR_FLAGS
(ReferenceObject::Flags)
104
105
}
// namespace Heap
106
107
108
struct
ReferenceObject
:
public
Object
109
{
110
V4_OBJECT2
(
ReferenceObject
,
Object
)
111
V4_NEEDS_DESTROY
112
113
public
:
114
static
constexpr
const
int
AllProperties
= -1;
115
116
template
<
typename
HeapObject>
117
static
bool
readReference
(HeapObject *
ref
)
118
{
119
if
(!
ref
->object())
120
return
false
;
121
122
QV4::Scope
scope(
ref
->internalClass->engine);
123
QV4::ScopedObject
object
(scope,
ref
->object());
124
125
if
(
ref
->isVariant()) {
126
QVariant
variant
;
127
void
*
a
[] = { &
variant
};
128
return
object
->metacall(
QMetaObject::ReadProperty
,
ref
->property(),
a
)
129
&&
ref
->setVariant(
variant
);
130
}
131
132
void
*
a
[] = {
ref
->storagePointer() };
133
return
object
->metacall(
QMetaObject::ReadProperty
,
ref
->property(),
a
);
134
}
135
136
template
<
typename
HeapObject>
137
static
bool
writeBack
(HeapObject *
ref
,
int
internalIndex =
AllProperties
)
138
{
139
if
(!
ref
->object() || !
ref
->canWriteBack())
140
return
false
;
141
142
QV4::Scope
scope(
ref
->internalClass->engine);
143
QV4::ScopedObject
object
(scope,
ref
->object());
144
145
int
flags
=
QQmlPropertyData::HasInternalIndex
;
146
int
status = -1;
147
if
(
ref
->isVariant()) {
148
QVariant
variant
=
ref
->toVariant();
149
void
*
a
[] = { &
variant
,
nullptr
, &status, &
flags
, &internalIndex };
150
return
object
->metacall(
QMetaObject::WriteProperty
,
ref
->property(),
a
);
151
}
152
153
void
*
a
[] = {
ref
->storagePointer(),
nullptr
, &status, &
flags
, &internalIndex };
154
return
object
->metacall(
QMetaObject::WriteProperty
,
ref
->property(),
a
);
155
}
156
157
template
<
typename
HeapObject>
158
static
HeapObject *
detached
(HeapObject *
ref
)
159
{
160
if
(
ref
->object() && !
ref
->enforcesLocation() && !
readReference
(
ref
))
161
return
ref
;
// It's dead. No point in detaching it anymore
162
163
return
ref
->detached();
164
}
165
};
166
167
}
// namespace QV4
168
169
QT_END_NAMESPACE
170
171
#endif
// QV4REFERENCEOBJECT_P_H
QQmlPropertyData::HasInternalIndex
@ HasInternalIndex
Definition
qqmlpropertydata_p.h:32
QVariant
\inmodule QtCore
Definition
qvariant.h:64
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qstandardpaths_haiku.cpp:21
QT_END_NAMESPACE
Definition
qsharedpointer.cpp:1545
QV4
\qmltype Particle \inqmlmodule QtQuick.Particles
Definition
qquickv4particledata.cpp:234
function
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction function
Definition
qdbus_symbols_p.h:170
Q_DECLARE_FLAGS
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition
qflags.h:174
Q_DECLARE_OPERATORS_FOR_FLAGS
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
Definition
qflags.h:194
Flags
Flags
Definition
qfontsubset.cpp:650
a
GLboolean GLboolean GLboolean GLboolean a
[7]
Definition
qopengles2ext.h:337
object
GLuint object
[3]
Definition
qopengles2ext.h:1248
flags
GLbitfield flags
Definition
qopengles2ext.h:1026
ref
GLint ref
Definition
qopengles2ext.h:3180
init
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
Definition
qtextboundaryfinder.cpp:10
quint16
unsigned short quint16
Definition
qtypes.h:43
quint8
unsigned char quint8
Definition
qtypes.h:41
V4_NEEDS_DESTROY
#define V4_NEEDS_DESTROY
Definition
qv4managed_p.h:39
DECLARE_HEAP_OBJECT
#define DECLARE_HEAP_OBJECT(name, base)
Definition
qv4mmdefs_p.h:313
DECLARE_MARKOBJECTS
#define DECLARE_MARKOBJECTS(class)
Definition
qv4mmdefs_p.h:320
V4_OBJECT2
#define V4_OBJECT2(DataClass, superClass)
Definition
qv4vtable_p.h:237
property
const char property[13]
Definition
qwizard.cpp:101
set
QFuture< QSet< QChar > > set
[10]
Definition
src_concurrent_qtconcurrentfilter.cpp:77
variant
QVariant variant
[1]
Definition
src_corelib_kernel_qvariant.cpp:30
frame
QFrame frame
[0]
Definition
src_gui_painting_qdrawutil.cpp:6
QMetaObject::WriteProperty
@ WriteProperty
Definition
qobjectdefs.h:470
QMetaObject::ReadProperty
@ ReadProperty
Definition
qobjectdefs.h:469
QV4::CppStackFrame
Definition
qv4stackframe_p.h:66
QV4::Function
Definition
qv4function_p.h:47
QV4::Object
Definition
qv4object_p.h:104
QV4::ReferenceObject
Definition
qv4referenceobject_p.h:109
QV4::ReferenceObject::writeBack
static bool writeBack(HeapObject *ref, int internalIndex=AllProperties)
Definition
qv4referenceobject_p.h:137
QV4::ReferenceObject::AllProperties
static constexpr const int AllProperties
Definition
qv4referenceobject_p.h:114
QV4::ReferenceObject::readReference
static bool readReference(HeapObject *ref)
Definition
qv4referenceobject_p.h:117
QV4::ReferenceObject::detached
static HeapObject * detached(HeapObject *ref)
Definition
qv4referenceobject_p.h:158
QV4::Scope
Definition
qv4scopedvalue_p.h:59
QV4::Scoped
Definition
qv4scopedvalue_p.h:266
qtdeclarative
src
qml
jsruntime
qv4referenceobject_p.h
Generated by
1.9.7