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
setupJSFrame
(
Value
*
stackSpace
,
const
Value
&
function
,
const
Heap
::
ExecutionContext
*
scope
,
210
const
Value
&
thisObject
,
const
Value
&
newTarget
=
Value
::
undefinedValue
()) {
211
setupJSFrame
(
stackSpace
,
function
,
scope
,
thisObject
,
newTarget
,
212
v4Function
->
compiledFunction
->
nFormals
,
213
v4Function
->
compiledFunction
->
nRegisters
);
214
}
215
216
void
setupJSFrame
(
217
Value
*
stackSpace
,
const
Value
&
function
,
const
Heap
::
ExecutionContext
*
scope
,
218
const
Value
&
thisObject
,
const
Value
&
newTarget
,
uint
nFormals
,
uint
nRegisters
)
219
{
220
jsFrame
=
reinterpret_cast
<
CallData
*>(
stackSpace
);
221
jsFrame
->
function
=
function
;
222
jsFrame
->
context
=
scope
->
asReturnedValue
();
223
jsFrame
->
accumulator
=
Encode
::
undefined
();
224
jsFrame
->
thisObject
=
thisObject
;
225
jsFrame
->
newTarget
=
newTarget
;
226
227
uint
argc
=
uint
(
originalArgumentsCount
);
228
if
(
argc
>
nFormals
)
229
argc
=
nFormals
;
230
jsFrame
->
setArgc
(
argc
);
231
232
// memcpy requires non-null ptr, even if argc * sizeof(Value) == 0
233
if
(
originalArguments
)
234
memcpy
(
jsFrame
->
args
,
originalArguments
,
argc
*
sizeof
(
Value
));
235
Q_STATIC_ASSERT
(
Encode
::
undefined
() == 0);
236
memset
(
jsFrame
->
args
+
argc
, 0, (
nRegisters
-
argc
) *
sizeof
(
Value
));
237
238
if
(
v4Function
&&
v4Function
->
compiledFunction
) {
239
const
int
firstDeadZoneRegister
240
=
v4Function
->
compiledFunction
->
firstTemporalDeadZoneRegister
;
241
const
int
registerDeadZoneSize
242
=
v4Function
->
compiledFunction
->
sizeOfRegisterTemporalDeadZone
;
243
244
const
Value
*
tdzEnd
=
stackSpace
+
firstDeadZoneRegister
+
registerDeadZoneSize
;
245
for
(
Value
*
v
=
stackSpace
+
firstDeadZoneRegister
;
v
<
tdzEnd
; ++
v
)
246
*
v
=
Value
::
emptyValue
().
asReturnedValue
();
247
}
248
}
249
250
ExecutionContext
*
context
()
const
251
{
252
return
static_cast
<
ExecutionContext
*>(&
jsFrame
->
context
);
253
}
254
255
void
setContext
(
ExecutionContext
*
context
)
256
{
257
jsFrame
->
context
=
context
;
258
}
259
260
Heap
::
CallContext
*
callContext
()
const
261
{
262
return
CppStackFrame
::
callContext
(
static_cast
<
ExecutionContext
&>(
jsFrame
->
context
).
d
());
263
}
264
265
bool
isTailCalling
()
const
{
return
CppStackFrame
::
isTailCalling
; }
266
void
setTailCalling
(
bool
tailCalling
) {
CppStackFrame
::
isTailCalling
=
tailCalling
; }
267
268
bool
pendingTailCall
()
const
{
return
CppStackFrame
::
pendingTailCall
; }
269
void
setPendingTailCall
(
bool
pending
) {
CppStackFrame
::
pendingTailCall
=
pending
; }
270
271
const
char
*
yield
()
const
{
return
CppStackFrame
::
yield
; }
272
void
setYield
(
const
char
*
yield
) {
CppStackFrame
::
yield
=
yield
; }
273
274
bool
yieldIsIterator
()
const
{
return
CppStackFrame
::
yieldIsIterator
; }
275
void
setYieldIsIterator
(
bool
isIter
) {
CppStackFrame
::
yieldIsIterator
=
isIter
; }
276
277
bool
callerCanHandleTailCall
()
const
{
return
CppStackFrame
::
callerCanHandleTailCall
; }
278
279
ReturnedValue
thisObject
()
const
280
{
281
return
jsFrame
->
thisObject
.
asReturnedValue
();
282
}
283
284
Value
*
framePointer
()
const
{
return
savedStackTop
; }
285
286
void
push
(
EngineBase
*
engine
) {
287
CppStackFrame
::
push
(
engine
);
288
savedStackTop
=
engine
->
jsStackTop
;
289
}
290
291
void
pop
(
EngineBase
*
engine
) {
292
CppStackFrame
::
pop
(
engine
);
293
engine
->
jsStackTop
=
savedStackTop
;
294
}
295
};
296
297
inline
ExecutionContext
*
CppStackFrame
::
context
()
const
298
{
299
if
(
isJSTypesFrame
())
300
return
static_cast
<
const
JSTypesStackFrame
*>(
this
)->
context
();
301
302
Q_ASSERT
(
isMetaTypesFrame
());
303
return
static_cast
<
const
MetaTypesStackFrame
*>(
this
)->
context
();
304
}
305
306
struct
ScopedStackFrame
307
{
308
ScopedStackFrame
(
const
Scope
&scope, ExecutionContext *context)
309
: engine(scope.engine)
310
{
311
if
(
auto
currentFrame = engine->currentStackFrame) {
312
frame.init(currentFrame->v4Function,
nullptr
, context,
nullptr
,
nullptr
, 0);
313
frame.instructionPointer = currentFrame->instructionPointer;
314
}
else
{
315
frame.init(
nullptr
,
nullptr
, context,
nullptr
,
nullptr
, 0);
316
}
317
frame.push(engine);
318
}
319
320
~
ScopedStackFrame
()
321
{
322
frame.pop(engine);
323
}
324
325
private
:
326
ExecutionEngine *engine =
nullptr
;
327
MetaTypesStackFrame frame;
328
};
329
330
Q_STATIC_ASSERT
(
sizeof
(
CppStackFrame
) ==
sizeof
(
JSTypesStackFrame
));
331
Q_STATIC_ASSERT
(
sizeof
(
CppStackFrame
) ==
sizeof
(
MetaTypesStackFrame
));
332
Q_STATIC_ASSERT
(
std
::
is_standard_layout_v
<
CppStackFrame
>);
333
Q_STATIC_ASSERT
(
std
::
is_standard_layout_v
<
JSTypesStackFrame
>);
334
Q_STATIC_ASSERT
(
std
::
is_standard_layout_v
<
MetaTypesStackFrame
>);
335
336
}
337
338
QT_END_NAMESPACE
339
340
#
endif
QPlatformGraphicsBufferHelper
\inmodule QtGui
QV4
Definition
qjsvalue.h:23
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:307
QV4::ScopedStackFrame::ScopedStackFrame
ScopedStackFrame(const Scope &scope, ExecutionContext *context)
Definition
qv4stackframe_p.h:308
QV4::ScopedStackFrame::~ScopedStackFrame
~ScopedStackFrame()
Definition
qv4stackframe_p.h:320
qtdeclarative
src
qml
jsruntime
qv4stackframe_p.h
Generated on
for Qt by
1.14.0