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
qv4function_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 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 QV4FUNCTION_H
5#define QV4FUNCTION_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 <qqmlprivate.h>
19#include "qv4global_p.h"
20#include <private/qv4executablecompilationunit_p.h>
21#include <private/qv4context_p.h>
22#include <private/qv4string_p.h>
23
24namespace JSC {
25class MacroAssemblerCodeRef;
26}
27
28QT_BEGIN_NAMESPACE
29
30struct QQmlSourceLocation;
31
32namespace QV4 {
33
34struct Q_QML_EXPORT FunctionData
35{
37
38 // Intentionally require an ExecutableCompilationUnit but save only a pointer to
39 // CompilationUnitBase. This is so that we can take advantage of the standard layout
40 // of CompilationUnitBase in the JIT. Furthermore we can safely static_cast to
41 // ExecutableCompilationUnit where we need it.
43};
44// Make sure this class can be accessed through offsetof (done by the assemblers):
45Q_STATIC_ASSERT(std::is_standard_layout< FunctionData >::value);
46
47struct Q_QML_EXPORT Function : public FunctionData {
48protected:
49 Function(ExecutionEngine *engine, ExecutableCompilationUnit *unit,
50 const CompiledData::Function *function, const QQmlPrivate::AOTCompiledFunction *aotFunction);
51 ~Function();
52
53public:
54 struct JSTypedFunction {
55 QVarLengthArray<QQmlType, 4> types;
56 };
57
58 struct AOTCompiledFunction {
59 QVarLengthArray<QMetaType, 4> types;
60 };
61
62 QV4::ExecutableCompilationUnit *executableCompilationUnit() const
63 {
64 // This is safe: We require an ExecutableCompilationUnit in the ctor.
65 return static_cast<QV4::ExecutableCompilationUnit *>(compilationUnit.get());
66 }
67
68 QV4::Heap::String *runtimeString(uint i) const
69 {
70 return compilationUnit->runtimeStrings[i];
71 }
72
73 bool call(QObject *thisObject, void **a, const QMetaType *types, int argc,
74 ExecutionContext *context);
75 ReturnedValue call(const Value *thisObject, const Value *argv, int argc,
76 ExecutionContext *context);
77
78 const CompiledData::Function *compiledFunction = nullptr;
79 const char *codeData = nullptr;
80 JSC::MacroAssemblerCodeRef *codeRef = nullptr;
81
82 typedef ReturnedValue (*JittedCode)(CppStackFrame *, ExecutionEngine *);
83 typedef void (*AotCompiledCode)(const QQmlPrivate::AOTCompiledContext *context, void **argv);
84
85 union {
86 void *noFunction = nullptr;
87 JSTypedFunction jsTypedFunction;
88 AOTCompiledFunction aotCompiledFunction;
89 };
90
91 union {
92 JittedCode jittedCode = nullptr;
93 AotCompiledCode aotCompiledCode;
94 };
95
96 // first nArguments names in internalClass are the actual arguments
97 QV4::WriteBarrier::Pointer<Heap::InternalClass> internalClass;
98 int interpreterCallCount = 0;
99 quint16 nFormals = 0;
100 enum Kind : quint8 { JsUntyped, JsTyped, AotCompiled, Eval };
101 Kind kind = JsUntyped;
102 bool detectedInjectedParameters = false;
103
104 static Function *create(ExecutionEngine *engine, ExecutableCompilationUnit *unit,
105 const CompiledData::Function *function,
106 const QQmlPrivate::AOTCompiledFunction *aotFunction);
107 void destroy();
108
109 void mark(QV4::MarkStack *ms);
110
111 // used when dynamically assigning signal handlers (QQmlConnection)
112 void updateInternalClass(ExecutionEngine *engine, const QList<QByteArray> &parameters);
113
114 inline Heap::String *name() const {
115 return runtimeString(compiledFunction->nameIndex);
116 }
117
118 static QString prettyName(const Function *function, const void *address);
119
120 inline QString sourceFile() const { return executableCompilationUnit()->fileName(); }
121 inline QUrl finalUrl() const { return executableCompilationUnit()->finalUrl(); }
122
123 inline bool isStrict() const { return compiledFunction->flags & CompiledData::Function::IsStrict; }
124 inline bool isArrowFunction() const { return compiledFunction->flags & CompiledData::Function::IsArrowFunction; }
125 inline bool isGenerator() const { return compiledFunction->flags & CompiledData::Function::IsGenerator; }
126 inline bool isClosureWrapper() const { return compiledFunction->flags & CompiledData::Function::IsClosureWrapper; }
127
128 QQmlSourceLocation sourceLocation() const;
129
130 Function *nestedFunction() const
131 {
132 if (compiledFunction->nestedFunctionIndex == std::numeric_limits<uint32_t>::max())
133 return nullptr;
134 return executableCompilationUnit()->runtimeFunctions[compiledFunction->nestedFunctionIndex];
135 }
136
137 bool isJittable() const { return kind != Function::AotCompiled && !isGenerator(); }
138};
139
140}
141
142QT_END_NAMESPACE
143
144#endif
Combined button and popup list for selecting options.
DECLARE_HEAP_OBJECT(DynamicFunctionObject, FunctionObject)
DECLARE_HEAP_OBJECT(BoundFunction, JavaScriptFunctionObject)
DECLARE_HEAP_OBJECT(ConstructorFunction, ScriptFunction)
DECLARE_HEAP_OBJECT(FunctionObject, Object)
DECLARE_HEAP_OBJECT(JavaScriptFunctionObject, FunctionObject)
DECLARE_HEAP_OBJECT(MemberFunction, ArrowFunction)
DECLARE_HEAP_OBJECT(ScriptFunction, ArrowFunction)
Definition qjsvalue.h:24
ReturnedValue checkedResult(QV4::ExecutionEngine *v4, ReturnedValue result)
DEFINE_OBJECT_VTABLE(SharedArrayBufferCtor)
DEFINE_OBJECT_VTABLE(ArrayBufferCtor)
DEFINE_OBJECT_VTABLE(ArrayBuffer)
DEFINE_OBJECT_VTABLE(SharedArrayBuffer)
#define V4_NEEDS_DESTROY
#define Q_MANAGED_TYPE(type)
#define V4_INTERNALCLASS(c)
#define RETURN_UNDEFINED()
static ReturnedValue virtualCallAsConstructor(const FunctionObject *f, const Value *argv, int argc, const Value *)
static ReturnedValue method_isView(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_get_byteLength(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_toString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_slice(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
void init(ExecutionEngine *engine, Object *ctor)
static void virtualCallWithMetaTypes(const FunctionObject *f, QObject *thisObject, void **a, const QMetaType *types, int argc)
static ReturnedValue virtualCall(const QV4::FunctionObject *f, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static ReturnedValue virtualCallAsConstructor(const FunctionObject *f, const Value *argv, int argc, const Value *)
Heap::FunctionObject * target() const
static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
Heap::MemberData * boundArgs() const
static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue virtualCallAsConstructor(const FunctionObject *, const Value *argv, int argc, const Value *)
static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
Heap::ExecutionContext * scope() const
static ReturnedValue virtualCallAsConstructor(const FunctionObject *, const Value *argv, int argc, const Value *)
static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue virtualCallAsConstructor(const FunctionObject *f, const Value *argv, int argc, const Value *)
static QQmlRefPointer< ExecutableCompilationUnit > parse(ExecutionEngine *engine, const Value *argv, int argc, Type t=Type_Function)
void init(ExecutionEngine *engine, Object *ctor)
static ReturnedValue method_bind(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_call(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_hasInstance(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_apply(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_toString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
void init(QV4::ExecutionEngine *engine)
void init(QV4::ExecutionContext *scope, Function *function, QV4::String *name=nullptr)
void init(QV4::ExecutionEngine *engine)
void init(QV4::ExecutionEngine *engine, qsizetype index, VTable::Call call)
void init(QV4::ExecutionEngine *engine)
Heap::InternalClass * classForConstructor() const
static ReturnedValue virtualCallAsConstructor(const FunctionObject *, const Value *argv, int argc, const Value *)
static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue virtualCallAsConstructor(const FunctionObject *f, const Value *argv, int argc, const Value *)
void init(ExecutionEngine *engine, Object *ctor)
static ReturnedValue method_get_byteLength(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_slice(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue slice(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc, bool shared)