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.cpp
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
5
6#include <private/qqmlpropertycachecreator_p.h>
7#include <private/qqmltype_p_p.h>
8
9#include <private/qv4engine_p.h>
10#include <private/qv4functiontable_p.h>
11#include <private/qv4identifiertable_p.h>
12#include <private/qv4jscall_p.h>
13#include <private/qv4vme_moth_p.h>
14
15#include <assembler/MacroAssemblerCodeRef.h>
16
18
19namespace QV4 {
20
21bool Function::call(QObject *thisObject, void **a, const QMetaType *types, int argc,
23{
24 if (kind != AotCompiled) {
25 return QV4::convertAndCall(
27 [this, context](const Value *thisObject, const Value *argv, int argc) {
28 return call(thisObject, argv, argc, context);
29 });
30 }
31
39}
40
56
58 const Value *thisObject, const Value *argv, int argc, ExecutionContext *context) {
59 switch (kind) {
60 case AotCompiled:
61 return QV4::convertAndCall(
63 [this, context](
64 QObject *thisObject, void **a, const QMetaType *types, int argc) {
66 });
67 case JsTyped:
68 return QV4::coerceAndCall(
70 [this, context, thisObject](const Value *argv, int argc) {
71 return doCall(this, thisObject, argv, argc, context);
72 });
73 default:
74 break;
75 }
76
77 return doCall(this, thisObject, argv, argc, context);
78}
79
86
88{
89 delete this;
90}
91
97
98static bool isSpecificType(const CompiledData::ParameterType &type)
99{
100 return type.typeNameIndexOrCommonType()
101 != (type.indexIsCommonType() ? quint32(CompiledData::CommonType::Invalid) : 0);
102}
103
110{
113
114 // first locals
116 for (quint32 i = 0; i < compiledFunction->nLocals; ++i)
118
121
122 for (quint32 i = 0; i < compiledFunction->nFormals; ++i) {
125 enforceJsTypes = false;
126 }
128
130
131 if (!enforceJsTypes)
132 return;
133
134 if (aotFunction) {
140 return;
141 }
142
143 // If a function has any typed arguments, but an untyped return value, the return value is void.
144 // If it doesn't have any arguments at all and the return value is untyped, the function is
145 // untyped. Users can specifically set the return type to "void" to have it enforced.
147 return;
148
150
151 auto findQmlType = [&](const CompiledData::ParameterType &param) {
153 if (param.indexIsCommonType()) {
156 }
157
158 if (type == 0 || !typeLoader)
159 return QQmlType();
160
162 return qmltype.typeId().isValid() ? qmltype : QQmlType();
163 };
164
166 kind = JsTyped;
169 for (quint16 i = 0; i < nFormals; ++i)
171}
172
174{
175 if (codeRef) {
177 delete codeRef;
178 }
179
180 switch (kind) {
181 case JsTyped:
183 break;
184 case AotCompiled:
186 break;
187 case JsUntyped:
188 case Eval:
189 break;
190 }
191}
192
194{
196
197 // Resolve duplicate parameter names:
198 for (int i = 0, ei = parameters.size(); i != ei; ++i) {
199 const QByteArray &param = parameters.at(i);
200 int duplicate = -1;
201
202 for (int j = i - 1; j >= 0; --j) {
204 if (param == prevParam) {
205 duplicate = j;
206 break;
207 }
208 }
209
210 if (duplicate == -1) {
212 } else {
216 QString(QChar(0xfffe)) + QString::number(duplicate) + dup;
217 }
218
219 }
220
223
224 // first locals
226 for (quint32 i = 0; i < compiledFunction->nLocals; ++i) {
227 ic = ic->addMember(
230 }
231
233 for (const QString &parameterName : parameterNames) {
236 }
239}
240
242{
244 if (prettyName.isEmpty()) {
245 prettyName = QString::number(reinterpret_cast<quintptr>(code), 16);
246 prettyName.prepend(QLatin1String("QV4::Function(0x"));
248 }
249 return prettyName;
250}
251
257
262
263} // namespace QV4
264
265QT_END_NAMESPACE
Combined button and popup list for selecting options.
Definition qjsvalue.h:23
static ReturnedValue doCall(QV4::Function *self, const QV4::Value *thisObject, const QV4::Value *argv, int argc, QV4::ExecutionContext *context)
static bool isSpecificType(const CompiledData::ParameterType &type)