aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmljsscope
diff options
context:
space:
mode:
authorAndrei Golubev <andrei.golubev@qt.io>2022-07-01 13:51:12 +0200
committerAndrei Golubev <andrei.golubev@qt.io>2022-07-22 16:38:42 +0200
commit8d0adee3b3317f1fab03742bdf0f7cdbe57df914 (patch)
tree6c51c5ffb0c0542fb4f4db4bd7fcd2eaa59db4c4 /tests/auto/qml/qqmljsscope
parent76d992431e113c3df9b6f879e2889973d5093a44 (diff)
qqmltypecompiler: align runtime function table order to qmlcachegen
When we write runtime functions to compilation unit at run time, the order of the functions in the unit (often) differs from the order of functions in the unit produced ahead of time by qmlcachegen and friends. Additionally, the order also differs from what qmltc expects (and qmlcompiler library in general) Fix the order by simplifying the procedure of JS code generation when we create the compilation unit at run time: new logic just goes over the objects in the document linearly, instead of relying on bindings (which are known to be out of order w.r.t. AST) Change-Id: I4070b9d061f03c4c76d03120654ad3f30725493a Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmljsscope')
-rw-r--r--tests/auto/qml/qqmljsscope/data/compilationUnitsCompatibility.qml6
-rw-r--r--tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp53
2 files changed, 59 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmljsscope/data/compilationUnitsCompatibility.qml b/tests/auto/qml/qqmljsscope/data/compilationUnitsCompatibility.qml
new file mode 100644
index 0000000000..bcc49537bb
--- /dev/null
+++ b/tests/auto/qml/qqmljsscope/data/compilationUnitsCompatibility.qml
@@ -0,0 +1,6 @@
+import QtQuick
+
+Text {
+ anchors.bottomMargin: Math.max(32, 31) + 10 // == 42
+ font.letterSpacing: Math.max(2, 3)
+}
diff --git a/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp b/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp
index 72ce3ab488..0c8eb0d227 100644
--- a/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp
+++ b/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp
@@ -23,6 +23,7 @@
#include <private/qqmljstyperesolver_p.h>
#include <QtQml/private/qqmljslexer_p.h>
#include <QtQml/private/qqmljsparser_p.h>
+#include <private/qqmlcomponent_p.h>
using namespace Qt::StringLiterals;
@@ -107,6 +108,7 @@ private Q_SLOTS:
void emptyBlockBinding();
void qualifiedName();
void resolvedNonUniqueScopes();
+ void compilationUnitsAreCompatible();
public:
tst_qqmljsscope()
@@ -733,5 +735,56 @@ void tst_qqmljsscope::resolvedNonUniqueScopes()
}
}
+static void
+getRuntimeInfoFromCompilationUnit(const QV4::CompiledData::Unit *unit,
+ QList<const QV4::CompiledData::Function *> &runtimeFunctions)
+{
+ QVERIFY(unit);
+ for (uint i = 0; i < unit->functionTableSize; ++i) {
+ const QV4::CompiledData::Function *function = unit->functionAt(i);
+ QVERIFY(function);
+ runtimeFunctions << function;
+ }
+}
+
+// Note: this test is here because we never explicitly test qCompileQmlFile()
+void tst_qqmljsscope::compilationUnitsAreCompatible()
+{
+ const QString url = u"compilationUnitsCompatibility.qml"_s;
+ QList<const QV4::CompiledData::Function *> componentFunctions;
+ QList<const QV4::CompiledData::Function *> cachegenFunctions;
+
+ QQmlEngine engine;
+ QQmlComponent component(&engine);
+ component.loadUrl(testFileUrl(url));
+ QVERIFY2(component.isReady(), qPrintable(component.errorString()));
+ QScopedPointer<QObject> root(component.create());
+ QVERIFY2(root, qPrintable(component.errorString()));
+ QQmlComponentPrivate *cPriv = QQmlComponentPrivate::get(&component);
+ QVERIFY(cPriv);
+ auto unit = cPriv->compilationUnit;
+ QVERIFY(unit);
+ QVERIFY(unit->unitData());
+ getRuntimeInfoFromCompilationUnit(unit->unitData(), componentFunctions);
+
+ if (QTest::currentTestFailed())
+ return;
+
+ QmlIR::Document document(false); // we need QmlIR information here
+ QVERIFY(run(url, &document));
+ QVERIFY(document.javaScriptCompilationUnit.unitData());
+ getRuntimeInfoFromCompilationUnit(document.javaScriptCompilationUnit.unitData(),
+ cachegenFunctions);
+ if (QTest::currentTestFailed())
+ return;
+
+ QCOMPARE(cachegenFunctions.size(), componentFunctions.size());
+ // name index should be fairly unique to distinguish different functions
+ // within a document. their order must be the same for both qmlcachegen and
+ // qqmltypecompiler (runtime)
+ for (qsizetype i = 0; i < cachegenFunctions.size(); ++i)
+ QCOMPARE(uint(cachegenFunctions[i]->nameIndex), uint(componentFunctions[i]->nameIndex));
+}
+
QTEST_MAIN(tst_qqmljsscope)
#include "tst_qqmljsscope.moc"