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
215
249
251 {
252 return static_cast<ExecutionContext *>(&jsFrame->context);
253 }
254
259
261 {
262 return CppStackFrame::callContext(static_cast<ExecutionContext &>(jsFrame->context).d());
263 }
264
265 bool isTailCalling() const { return CppStackFrame::isTailCalling; }
267
270
271 const char *yield() const { return CppStackFrame::yield; }
272 void setYield(const char *yield) { CppStackFrame::yield = yield; }
273
276
278
280 {
282 }
283
284 Value *framePointer() const { return savedStackTop; }
285
290
295};
296
298{
299 if (isJSTypesFrame())
300 return static_cast<const JSTypesStackFrame *>(this)->context();
301
303 return static_cast<const MetaTypesStackFrame *>(this)->context();
304}
305
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
321 {
322 frame.pop(engine);
323 }
324
325private:
326 ExecutionEngine *engine = nullptr;
327 MetaTypesStackFrame frame;
328};
329
335
336}
337
338QT_END_NAMESPACE
339
340#endif
Definition qjsvalue.h:23
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)