diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2024-04-16 17:03:01 +0200 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2024-04-26 12:18:15 +0000 |
| commit | 8bf5aae19b77b618f3f7a55a59e87c8a319475a8 (patch) | |
| tree | d331328f478ac13593524eaaeb3a874691ccadd2 /src/qmlcompiler/qqmljscompiler.cpp | |
| parent | 23fc22e16022e355f2a1aff8705c09b807fbe024 (diff) | |
QtQml: Properly enforce signatures of AOT-compiled functions
Pass the metatypes of the contained types rather than the stored types.
[ChangeLog][QtQml][Important Behavior Changes] The AOT compiled code for
type-annotated JavaScript functions does not let you pass or return
values of the wrong type anymore.
Fixes: QTBUG-119885
Change-Id: I685d398c0745d32a999a3abd76c622a2c0d6651f
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qmlcompiler/qqmljscompiler.cpp')
| -rw-r--r-- | src/qmlcompiler/qqmljscompiler.cpp | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/src/qmlcompiler/qqmljscompiler.cpp b/src/qmlcompiler/qqmljscompiler.cpp index cca05380c9..8ecc69d1c9 100644 --- a/src/qmlcompiler/qqmljscompiler.cpp +++ b/src/qmlcompiler/qqmljscompiler.cpp @@ -560,7 +560,7 @@ bool qSaveQmlJSUnitAsCpp(const QString &inputFileName, const QString &outputFile if (aotFunctions.size() <= 1) { // FileScopeCodeIndex is always there, but it may be the only one. writeStr("extern const QQmlPrivate::AOTCompiledFunction aotBuiltFunctions[];\n" - "extern const QQmlPrivate::AOTCompiledFunction aotBuiltFunctions[] = { { 0, QMetaType::fromType<void>(), {}, nullptr } };\n"); + "extern const QQmlPrivate::AOTCompiledFunction aotBuiltFunctions[] = { { 0, 0, nullptr, nullptr } };\n"); } else { writeStr("extern const QQmlPrivate::AOTCompiledFunction aotBuiltFunctions[];\n" "extern const QQmlPrivate::AOTCompiledFunction aotBuiltFunctions[] = {\n"); @@ -574,25 +574,18 @@ bool qSaveQmlJSUnitAsCpp(const QString &inputFileName, const QString &outputFile if (func.key() == FileScopeCodeIndex) continue; - QString function = QString::fromUtf8(funcHeaderCode) + func.value().code + footer; + const QString function = QString::fromUtf8(funcHeaderCode) + func.value().code + footer; - QString argumentTypes = func.value().argumentTypes.join( - QStringLiteral(">(), QMetaType::fromType<")); - if (!argumentTypes.isEmpty()) { - argumentTypes = QStringLiteral("QMetaType::fromType<") - + argumentTypes + QStringLiteral(">()"); - } - - writeStr(QStringLiteral("{ %1, QMetaType::fromType<%2>(), { %3 }, %4 },") + writeStr(QStringLiteral("{ %1, %2, [](QV4::ExecutableCompilationUnit *unit, " + "QMetaType *argTypes) {\n%3}, %4 },") .arg(func.key()) - .arg(func.value().returnType) - .arg(argumentTypes) - .arg(function) + .arg(func->numArguments) + .arg(func->signature, function) .toUtf8().constData()); } // Conclude the list with a nullptr - writeStr("{ 0, QMetaType::fromType<void>(), {}, nullptr }"); + writeStr("{ 0, 0, nullptr, nullptr }"); writeStr("};\n"); } |
