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
qv4stackframe_p.h
Go to the documentation of this file.
1
// Copyright (C) 2018 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
QV4STACKFRAME_H
5
#
define
QV4STACKFRAME_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
/
qv4scopedvalue_p
.
h
>
19
#
include
<
private
/
qv4context_p
.
h
>
20
#
include
<
private
/
qv4enginebase_p
.
h
>
21
#
include
<
private
/
qv4calldata_p
.
h
>
22
#
include
<
private
/
qv4function_p
.
h
>
23
24
#
include
<
type_traits
>
25
26
QT_BEGIN_NAMESPACE
27
28
namespace
QV4
{
29
30
struct
CppStackFrame;
31
struct
Q_QML_EXPORT
CppStackFrameBase
32
{
33
enum
class
Kind
:
quint8
{
JS
,
Meta
};
34
35
CppStackFrame
*
parent
;
36
Function
*
v4Function
;
37
int
originalArgumentsCount
;
38
int
instructionPointer
;
39
40
QT_WARNING_PUSH
41
QT_WARNING_DISABLE_MSVC
(4201)
// nonstandard extension used: nameless struct/union
42
union
{
43
struct
{
44
Value
*
savedStackTop
;
45
CallData
*
jsFrame
;
46
const
Value
*
originalArguments
;
47
const
char
*
yield
;
48
const
char
*
unwindHandler
;
49
const
char
*
unwindLabel
;
50
int
unwindLevel
;
51
bool
yieldIsIterator
;
52
bool
callerCanHandleTailCall
;
53
bool
pendingTailCall
;
54
bool
isTailCalling
;
55
};
56
struct
{
57
ExecutionContext
*
context
;
58
QObject
*
thisObject
;
59
const
QMetaType
*
metaTypes
;
60
const
QQmlPrivate
::
AOTTrackedLocalsStorage
*
locals
;
61
void
**
returnAndArgs
;
62
bool
returnValueIsUndefined
;
63
};
64
};
65
QT_WARNING_POP
66
67
Kind
kind
;
68
};
69
70
struct
Q_QML_EXPORT
CppStackFrame
:
protected
CppStackFrameBase
71
{
72
// We want to have those public but we can't declare them as public without making the struct
73
// non-standard layout. So we have this other struct with "using" in between.
74
using
CppStackFrameBase
::
instructionPointer
;
75
using
CppStackFrameBase
::
v4Function
;
76
77
void
init
(
Function
*
v4Function
,
int
argc
,
Kind
kind
) {
78
this
->
v4Function
=
v4Function
;
79
originalArgumentsCount
=
argc
;
80
instructionPointer
= 0;
81
this
->
kind
=
kind
;
82
}
83
84
bool
isJSTypesFrame
()
const
{
return
kind
==
Kind
::
JS
; }
85
bool
isMetaTypesFrame
()
const
{
return
kind
==
Kind
::
Meta
; }
86
87
QString
source
()
const
;
88
QString
function
()
const
;
89
int
lineNumber
()
const
;
90
int
statementNumber
()
const
;
91
92
int
missingLineNumber
()
const
;
93
94
CppStackFrame
*
parentFrame
()
const
{
return
parent
; }
95
void
setParentFrame
(
CppStackFrame
*
parentFrame
) {
parent
=
parentFrame
; }
96
97
int
argc
()
const
{
return
originalArgumentsCount
; }
98
99
inline
ExecutionContext
*
context
()
const
;
100
101
Heap
::
CallContext
*
callContext
()
const
{
return
callContext
(
context
()->
d
()); }
102
ReturnedValue
thisObject
()
const
;
103
104
protected
:
105
CppStackFrame
() =
default
;
106
107
void
push
(
EngineBase
*
engine
)
108
{
109
Q_ASSERT
(
kind
==
Kind
::
JS
||
kind
==
Kind
::
Meta
);
110
parent
=
engine
->
currentStackFrame
;
111
engine
->
currentStackFrame
=
this
;
112
}
113
114
void
pop
(
EngineBase
*
engine
)
115
{
116
engine
->
currentStackFrame
=
parent
;
117
}
118
119
Heap
::
CallContext
*
callContext
(
Heap
::
ExecutionContext
*
ctx
)
const
120
{
121
while
(
ctx
->
type
!=
Heap
::
ExecutionContext
::
Type_CallContext
)
122
ctx
=
ctx
->
outer
;
123
return
static_cast
<
Heap
::
CallContext
*>(
ctx
);
124
}
125
};
126
127
struct
Q_QML_EXPORT
MetaTypesStackFrame
:
public
CppStackFrame
128
{
129
using
CppStackFrame
::
push
;
130
using
CppStackFrame
::
pop
;
131
132
void
init
(
Function
*
v4Function
,
QObject
*
thisObject
,
ExecutionContext
*
context
,
133
void
**
returnAndArgs
,
const
QMetaType
*
metaTypes
,
int
argc
)
134
{
135
CppStackFrame
::
init
(
v4Function
,
argc
,
Kind
::
Meta
);
136
CppStackFrameBase
::
context
=
context
;
137
CppStackFrameBase
::
thisObject
=
thisObject
;
138
CppStackFrameBase
::
metaTypes
=
metaTypes
;
139
CppStackFrameBase
::
locals
=
nullptr
;
140
CppStackFrameBase
::
returnAndArgs
=
returnAndArgs
;
141
CppStackFrameBase
::
returnValueIsUndefined
=
false
;
142
}
143
144
QMetaType
returnType
()
const
{
return
metaTypes
[0]; }
145
void
*
returnValue
()
const
{
return
returnAndArgs
[0]; }
146
147
bool
isReturnValueUndefined
()
const
{
return
CppStackFrameBase
::
returnValueIsUndefined
; }
148
void
setReturnValueUndefined
() {
CppStackFrameBase
::
returnValueIsUndefined
=
true
; }
149
150
const
QMetaType
*
argTypes
()
const
{
return
metaTypes
+ 1; }
151
void
**
argv
()
const
{
return
returnAndArgs
+ 1; }
152
153
const
QMetaType
*
returnAndArgTypes
()
const
{
return
metaTypes
; }
154
void
**
returnAndArgValues
()
const
{
return
returnAndArgs
; }
155
156
QObject
*
thisObject
()
const
{
return
CppStackFrameBase
::
thisObject
; }
157
158
ExecutionContext
*
context
()
const
{
return
CppStackFrameBase
::
context
; }
159
void
setContext
(
ExecutionContext
*
context
) {
CppStackFrameBase
::
context
=
context
; }
160
161
const
QQmlPrivate
::
AOTTrackedLocalsStorage
*
locals
()
const
{
return
CppStackFrameBase
::
locals
; }
162
void
setLocals
(
const
QQmlPrivate
::
AOTTrackedLocalsStorage
*
locals
)
163
{
164
CppStackFrameBase
::
locals
=
locals
;
165
}
166
167
Heap
::
CallContext
*
callContext
()
const
168
{
169
return
CppStackFrame
::
callContext
(
CppStackFrameBase
::
context
->
d
());
170
}
171
};
172
173
struct
Q_QML_EXPORT
JSTypesStackFrame
:
public
CppStackFrame
174
{
175
using
CppStackFrame
::
jsFrame
;
176
177
// The JIT needs to poke directly into those using offsetof
178
using
CppStackFrame
::
unwindHandler
;
179
using
CppStackFrame
::
unwindLabel
;
180
using
CppStackFrame
::
unwindLevel
;
181
182
void
init
(
Function
*
v4Function
,
const
Value
*
argv
,
int
argc
,
183
bool
callerCanHandleTailCall
=
false
)
184
{
185
CppStackFrame
::
init
(
v4Function
,
argc
,
Kind
::
JS
);
186
CppStackFrame
::
originalArguments
=
argv
;
187
CppStackFrame
::
yield
=
nullptr
;
188
CppStackFrame
::
unwindHandler
=
nullptr
;
189
CppStackFrame
::
yieldIsIterator
=
false
;
190
CppStackFrame
::
callerCanHandleTailCall
=
callerCanHandleTailCall
;
191
CppStackFrame
::
pendingTailCall
=
false
;
192
CppStackFrame
::
isTailCalling
=
false
;
193
CppStackFrame
::
unwindLabel
=
nullptr
;
194
CppStackFrame
::
unwindLevel
= 0;
195
}
196
197
const
Value
*
argv
()
const
{
return
originalArguments
; }
198
199
static
uint
requiredJSStackFrameSize
(
uint
nRegisters
) {
200
return
CallData
::
HeaderSize
() +
nRegisters
;
201
}
202
static
uint
requiredJSStackFrameSize
(
Function
*
v4Function
) {
203
return
CallData
::
HeaderSize
() +
v4Function
->
compiledFunction
->
nRegisters
;
204
}
205
uint
requiredJSStackFrameSize
()
const
{
206
return
requiredJSStackFrameSize
(
v4Function
);
207
}
208
209
void
markJSFrame
(
MarkStack
*
markStack
)
const
210
{
211
const
CallData
*
constFrame
=
jsFrame
;
212
constFrame
->
function
.
asValue
<
Value
>().
mark
(
markStack
);
213
constFrame
->
context
.
asValue
<
Value
>().
mark
(
markStack
);
214
constFrame
->
accumulator
.
asValue
<
Value
>().
mark
(
markStack
);
215
constFrame
->
thisObject
.
asValue
<
Value
>().
mark
(
markStack
);
216
constFrame
->
newTarget
.
asValue
<
Value
>().
mark
(
markStack
);
217
218
// First argc of those are actually arguments, but after that there are
219
// other local registers.
220
const
Value
*
registers
=
constFrame
->
argValues
<
Value
>();
221
222
for
(
int
i
= 0,
end
=
v4Function
->
compiledFunction
->
nRegisters
;
i
!=
end
; ++
i
)
223
registers
[
i
].
mark
(
markStack
);
224
}
225
226
void
setupJSFrame
(
Value
*
stackSpace
,
const
Value
&
function
,
const
Heap
::
ExecutionContext
*
scope
,
227
const
Value
&
thisObject
,
const
Value
&
newTarget
=
Value
::
undefinedValue
()) {
228
setupJSFrame
(
stackSpace
,
function
,
scope
,
thisObject
,
newTarget
,
229
v4Function
->
compiledFunction
->
nFormals
,
230
v4Function
->
compiledFunction
->
nRegisters
);
231
}
232
233
void
setupJSFrame
(
234
Value
*
stackSpace
,
const
Value
&
function
,
const
Heap
::
ExecutionContext
*
scope
,
235
const
Value
&
thisObject
,
const
Value
&
newTarget
,
uint
nFormals
,
uint
nRegisters
)
236
{
237
jsFrame
=
reinterpret_cast
<
CallData
*>(
stackSpace
);
238
jsFrame
->
function
=
function
;
239
jsFrame
->
context
=
scope
->
asReturnedValue
();
240
jsFrame
->
accumulator
=
Encode
::
undefined
();
241
jsFrame
->
thisObject
=
thisObject
;
242
jsFrame
->
newTarget
=
newTarget
;
243
244
uint
argc
=
uint
(
originalArgumentsCount
);
245
if
(
argc
>
nFormals
)
246
argc
=
nFormals
;
247
jsFrame
->
setArgc
(
argc
);
248
249
// memcpy requires non-null ptr, even if argc * sizeof(Value) == 0
250
if
(
originalArguments
)
251
memcpy
(
jsFrame
->
args
,
originalArguments
,
argc
*
sizeof
(
Value
));
252
Q_STATIC_ASSERT
(
Encode
::
undefined
() == 0);
253
memset
(
jsFrame
->
args
+
argc
, 0, (
nRegisters
-
argc
) *
sizeof
(
Value
));
254
255
if
(
v4Function
&&
v4Function
->
compiledFunction
) {
256
const
int
firstDeadZoneRegister
257
=
v4Function
->
compiledFunction
->
firstTemporalDeadZoneRegister
;
258
const
int
registerDeadZoneSize
259
=
v4Function
->
compiledFunction
->
sizeOfRegisterTemporalDeadZone
;
260
261
const
Value
*
tdzEnd
=
stackSpace
+
firstDeadZoneRegister
+
registerDeadZoneSize
;
262
for
(
Value
*
v
=
stackSpace
+
firstDeadZoneRegister
;
v
<
tdzEnd
; ++
v
)
263
*
v
=
Value
::
emptyValue
().
asReturnedValue
();
264
}
265
}
266
267
ExecutionContext
*
context
()
const
268
{
269
return
static_cast
<
ExecutionContext
*>(&
jsFrame
->
context
);
270
}
271
272
void
setContext
(
ExecutionContext
*
context
)
273
{
274
jsFrame
->
context
=
context
;
275
}
276
277
Heap
::
CallContext
*
callContext
()
const
278
{
279
return
CppStackFrame
::
callContext
(
static_cast
<
ExecutionContext
&>(
jsFrame
->
context
).
d
());
280
}
281
282
bool
isTailCalling
()
const
{
return
CppStackFrame
::
isTailCalling
; }
283
void
setTailCalling
(
bool
tailCalling
) {
CppStackFrame
::
isTailCalling
=
tailCalling
; }
284
285
bool
pendingTailCall
()
const
{
return
CppStackFrame
::
pendingTailCall
; }
286
void
setPendingTailCall
(
bool
pending
) {
CppStackFrame
::
pendingTailCall
=
pending
; }
287
288
const
char
*
yield
()
const
{
return
CppStackFrame
::
yield
; }
289
void
setYield
(
const
char
*
yield
) {
CppStackFrame
::
yield
=
yield
; }
290
291
bool
yieldIsIterator
()
const
{
return
CppStackFrame
::
yieldIsIterator
; }
292
void
setYieldIsIterator
(
bool
isIter
) {
CppStackFrame
::
yieldIsIterator
=
isIter
; }
293
294
bool
callerCanHandleTailCall
()
const
{
return
CppStackFrame
::
callerCanHandleTailCall
; }
295
296
ReturnedValue
thisObject
()
const
297
{
298
return
jsFrame
->
thisObject
.
asReturnedValue
();
299
}
300
301
Value
*
framePointer
()
const
{
return
savedStackTop
; }
302
303
void
push
(
EngineBase
*
engine
) {
304
CppStackFrame
::
push
(
engine
);
305
savedStackTop
=
engine
->
jsStackTop
;
306
}
307
308
void
pop
(
EngineBase
*
engine
) {
309
CppStackFrame
::
pop
(
engine
);
310
engine
->
jsStackTop
=
savedStackTop
;
311
}
312
};
313
314
inline
ExecutionContext
*
CppStackFrame
::
context
()
const
315
{
316
if
(
isJSTypesFrame
())
317
return
static_cast
<
const
JSTypesStackFrame
*>(
this
)->
context
();
318
319
Q_ASSERT
(
isMetaTypesFrame
());
320
return
static_cast
<
const
MetaTypesStackFrame
*>(
this
)->
context
();
321
}
322
323
struct
ScopedStackFrame
324
{
325
ScopedStackFrame
(
const
Scope
&scope, ExecutionContext *context)
326
: engine(scope.engine)
327
{
328
if
(
auto
currentFrame = engine->currentStackFrame) {
329
frame.init(currentFrame->v4Function,
nullptr
, context,
nullptr
,
nullptr
, 0);
330
frame.instructionPointer = currentFrame->instructionPointer;
331
}
else
{
332
frame.init(
nullptr
,
nullptr
, context,
nullptr
,
nullptr
, 0);
333
}
334
frame.push(engine);
335
}
336
337
~
ScopedStackFrame
()
338
{
339
frame.pop(engine);
340
}
341
342
private
:
343
ExecutionEngine *engine =
nullptr
;
344
MetaTypesStackFrame frame;
345
};
346
347
Q_STATIC_ASSERT
(
sizeof
(
CppStackFrame
) ==
sizeof
(
JSTypesStackFrame
));
348
Q_STATIC_ASSERT
(
sizeof
(
CppStackFrame
) ==
sizeof
(
MetaTypesStackFrame
));
349
Q_STATIC_ASSERT
(
std
::
is_standard_layout_v
<
CppStackFrame
>);
350
Q_STATIC_ASSERT
(
std
::
is_standard_layout_v
<
JSTypesStackFrame
>);
351
Q_STATIC_ASSERT
(
std
::
is_standard_layout_v
<
MetaTypesStackFrame
>);
352
353
}
354
355
QT_END_NAMESPACE
356
357
#
endif
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
QV4
Definition
qjsvalue.h:24
QV4::Q_STATIC_ASSERT
Q_STATIC_ASSERT(sizeof(CppStackFrame)==sizeof(JSTypesStackFrame))
DEFINE_MANAGED_VTABLE
DEFINE_MANAGED_VTABLE(ExecutionContext)
DEFINE_MANAGED_VTABLE
DEFINE_MANAGED_VTABLE(CallContext)
unscopable
static bool unscopable(ExecutionEngine *engine, Heap::Object *withObject, PropertyKey id)
Definition
qv4context.cpp:165
QV4::CppStackFrameBase
Definition
qv4stackframe_p.h:32
QV4::CppStackFrame
Definition
qv4stackframe_p.h:71
QV4::JSTypesStackFrame
Definition
qv4stackframe_p.h:174
QV4::MetaTypesStackFrame
Definition
qv4stackframe_p.h:128
QV4::Scope
Definition
qv4scopedvalue_p.h:61
QV4::ScopedStackFrame
Definition
qv4stackframe_p.h:324
QV4::ScopedStackFrame::ScopedStackFrame
ScopedStackFrame(const Scope &scope, ExecutionContext *context)
Definition
qv4stackframe_p.h:325
QV4::ScopedStackFrame::~ScopedStackFrame
~ScopedStackFrame()
Definition
qv4stackframe_p.h:337
qtdeclarative
src
qml
jsruntime
qv4stackframe_p.h
Generated on
for Qt by
1.16.1