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
27
28namespace QV4 {
29
30struct CppStackFrame;
69
70struct 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.
76
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; }
96
97 int argc() const { return originalArgumentsCount; }
98
99 inline ExecutionContext *context() const;
100
101 Heap::CallContext *callContext() const { return callContext(context()->d()); }
103
104protected:
105 CppStackFrame() = default;
106
108 {
109 Q_ASSERT(kind == Kind::JS || kind == Kind::Meta);
112 }
113
118
120 {
122 ctx = ctx->outer;
123 return static_cast<Heap::CallContext *>(ctx);
124 }
125};
126
127struct Q_QML_EXPORT MetaTypesStackFrame : public CppStackFrame
128{
129 using CppStackFrame::push;
130 using CppStackFrame::pop;
131
143
144 QMetaType returnType() const { return metaTypes[0]; }
145 void *returnValue() const { return returnAndArgs[0]; }
146
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
157
160
166
171};
172
173struct Q_QML_EXPORT JSTypesStackFrame : public CppStackFrame
174{
175 using CppStackFrame::jsFrame;
176
177 // The JIT needs to poke directly into those using offsetof
181
196
197 const Value *argv() const { return originalArguments; }
198
208
210 {
211 const CallData *constFrame = jsFrame;
217
218 // First argc of those are actually arguments, but after that there are
219 // other local registers.
221
222 for (int i = 0, end = v4Function->compiledFunction->nRegisters; i != end; ++i)
224 }
225
232
266
268 {
269 return static_cast<ExecutionContext *>(&jsFrame->context);
270 }
271
276
278 {
279 return CppStackFrame::callContext(static_cast<ExecutionContext &>(jsFrame->context).d());
280 }
281
282 bool isTailCalling() const { return CppStackFrame::isTailCalling; }
284
287
288 const char *yield() const { return CppStackFrame::yield; }
289 void setYield(const char *yield) { CppStackFrame::yield = yield; }
290
293
295
297 {
299 }
300
301 Value *framePointer() const { return savedStackTop; }
302
307
312};
313
315{
316 if (isJSTypesFrame())
317 return static_cast<const JSTypesStackFrame *>(this)->context();
318
320 return static_cast<const MetaTypesStackFrame *>(this)->context();
321}
322
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
338 {
339 frame.pop(engine);
340 }
341
342private:
343 ExecutionEngine *engine = nullptr;
344 MetaTypesStackFrame frame;
345};
346
352
353}
354
355QT_END_NAMESPACE
356
357#endif
Combined button and popup list for selecting options.
Definition qjsvalue.h:24
Q_STATIC_ASSERT(sizeof(CppStackFrame)==sizeof(JSTypesStackFrame))
DEFINE_MANAGED_VTABLE(ExecutionContext)
DEFINE_MANAGED_VTABLE(CallContext)
static bool unscopable(ExecutionEngine *engine, Heap::Object *withObject, PropertyKey id)
ScopedStackFrame(const Scope &scope, ExecutionContext *context)