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// Qt-Security score:significant
4
6
7#include <private/qqmlpropertycachecreator_p.h>
8#include <private/qqmltype_p_p.h>
9
10#include <private/qv4engine_p.h>
11#include <private/qv4functiontable_p.h>
12#include <private/qv4identifiertable_p.h>
13#include <private/qv4jscall_p.h>
14#include <private/qv4vme_moth_p.h>
15
16#include <assembler/MacroAssemblerCodeRef.h>
17
19
20namespace QV4 {
21
22bool Function::call(QObject *thisObject, void **a, const QMetaType *types, int argc,
24{
25 if (kind != AotCompiled) {
26 return QV4::convertAndCall(
28 [this, context](const Value *thisObject, const Value *argv, int argc) {
29 return call(thisObject, argv, argc, context);
30 });
31 }
32
40}
41
57
59 const Value *thisObject, const Value *argv, int argc, ExecutionContext *context) {
60 switch (kind) {
61 case AotCompiled: {
62 const auto &types = aotCompiledFunction.types;
63 return QV4::convertAndCall(
65 [this, context, thisObject](void **a, const QMetaType *types, int argc) {
67 });
68 }
69 case JsTyped:
70 return QV4::coerceAndCall(
72 [this, context, thisObject](const Value *argv, int argc) {
73 return doCall(this, thisObject, argv, argc, context);
74 });
75 default:
76 break;
77 }
78
79 return doCall(this, thisObject, argv, argc, context);
80}
81
88
90{
91 delete this;
92}
93
99
100static bool isSpecificType(const CompiledData::ParameterType &type)
101{
102 return type.typeNameIndexOrCommonType()
103 != (type.indexIsCommonType() ? quint32(CompiledData::CommonType::Invalid) : 0);
104}
105
112{
115
116 // first locals
118 for (quint32 i = 0; i < compiledFunction->nLocals; ++i)
120
123
124 for (quint32 i = 0; i < compiledFunction->nFormals; ++i) {
127 enforceJsTypes = false;
128 }
130
132
133 if (!enforceJsTypes)
134 return;
135
136 if (aotFunction) {
142 return;
143 }
144
145 // If a function has any typed arguments, but an untyped return value, the return value is void.
146 // If it doesn't have any arguments at all and the return value is untyped, the function is
147 // untyped. Users can specifically set the return type to "void" to have it enforced.
149 return;
150
152
153 const auto isEnumUsedAsType = [&](const QV4::ExecutableCompilationUnit *unit,
155 const quint16 *parameter = nullptr) {
157 const auto split = name.tokenize(u'.').toContainer<QVarLengthArray<QStringView, 4>>();
158 if (split.size() != 2)
159 return false;
160
161 const QStringView scopeName = split[0];
162 const QStringView enumName = split[1];
163
165 const auto warn = [&] {
167 auto where = parameter ? QStringLiteral("parameter ") + QString::number(*parameter)
168 : QStringLiteral("return type");
169 auto msg = QStringLiteral("Type annotation for %1 of function %2: Enumerations are "
170 "not types. Use underlying type (int or double) instead.")
171 .arg(where, this->name()->toQString());
178 };
179
180 bool ok;
181 if (scopeName == QStringLiteral("Qt")) {
183 for (int i = 0; i < mo->enumeratorCount(); ++i) {
184 if (mo->enumerator(i).name() == enumName.toLatin1()) {
185 warn();
186 return true;
187 }
188 }
189 return false;
190 }
191
194 if (!scope.isValid())
195 return false;
196
198 if (ok) {
199 warn();
200 return true;
201 }
203 if (ok) {
204 warn();
205 return true;
206 }
207
208 return false;
209 };
210
211 auto findQmlType = [&](const CompiledData::ParameterType &param,
212 const quint16 *parameter = nullptr) {
214 if (param.indexIsCommonType()) {
217 }
218
219 if (type == 0 || !typeLoader)
220 return QQmlType();
221
223 return QQmlType();
224
226 return qmltype.typeId().isValid() ? qmltype : QQmlType();
227 };
228
230 kind = JsTyped;
233 for (quint16 i = 0; i < nFormals; ++i)
235}
236
238{
239 if (codeRef) {
241 delete codeRef;
242 }
243
244 switch (kind) {
245 case JsTyped:
247 break;
248 case AotCompiled:
250 break;
251 case JsUntyped:
252 case Eval:
253 break;
254 }
255}
256
258{
260
261 // Resolve duplicate parameter names:
262 for (int i = 0, ei = parameters.size(); i != ei; ++i) {
263 const QByteArray &param = parameters.at(i);
264 int duplicate = -1;
265
266 for (int j = i - 1; j >= 0; --j) {
268 if (param == prevParam) {
269 duplicate = j;
270 break;
271 }
272 }
273
274 if (duplicate == -1) {
276 } else {
280 QString(QChar(0xfffe)) + QString::number(duplicate) + dup;
281 }
282
283 }
284
287
288 // first locals
290 for (quint32 i = 0; i < compiledFunction->nLocals; ++i) {
291 ic = ic->addMember(
294 }
295
297 for (const QString &parameterName : parameterNames) {
300 }
303}
304
306{
308 if (prettyName.isEmpty()) {
309 prettyName = QString::number(reinterpret_cast<quintptr>(code), 16);
310 prettyName.prepend(QLatin1String("QV4::Function(0x"));
312 }
313 return prettyName;
314}
315
321
326
327} // namespace QV4
328
329QT_END_NAMESPACE
Combined button and popup list for selecting options.
Definition qjsvalue.h:24
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)