aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2023-06-12 16:33:28 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-08-30 15:54:00 +0000
commit2a24f5fa1205cd3c39e01287929a27c73e69b16c (patch)
treed5433b1a799ba2875eacc05c58ef00d00af04b31
parentc567489e73b244594f26e1d8babaa8801fadf7da (diff)
QQmlJSTypePropagator: Support StoreNameStrict
As far as the type propagator is concerned, it is the the same as StoreNameSloppy. This allows the unqualified id check to work in strict functions, too. Change-Id: Ie4ca823c996e058e4cdde632acaa1caa146b77bc Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit f9d74e8326b11b39b3bdbcb1ff87a9c8f8bc0d34) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/qmlcompiler/qqmljstypepropagator.cpp22
-rw-r--r--src/qmlcompiler/qqmljstypepropagator_p.h1
-rw-r--r--tests/auto/qml/qmllint/data/UnqualifiedInStoreStrict.qml12
-rw-r--r--tests/auto/qml/qmllint/tst_qmllint.cpp3
4 files changed, 34 insertions, 4 deletions
diff --git a/src/qmlcompiler/qqmljstypepropagator.cpp b/src/qmlcompiler/qqmljstypepropagator.cpp
index 4ea5cedd1f..a61a6e5743 100644
--- a/src/qmlcompiler/qqmljstypepropagator.cpp
+++ b/src/qmlcompiler/qqmljstypepropagator.cpp
@@ -577,7 +577,18 @@ void QQmlJSTypePropagator::generate_LoadQmlContextPropertyLookup(int index)
m_attachedContext = QQmlJSScope::ConstPtr();
}
-void QQmlJSTypePropagator::generate_StoreNameSloppy(int nameIndex)
+/*!
+ \internal
+ As far as type propagation is involved, StoreNameSloppy and
+ StoreNameStrict are completely the same
+ StoreNameStrict is rejecting a few writes (where the variable was not
+ defined before) that would work in a sloppy context in JS, but the
+ compiler would always reject this. And for type propagation, this does
+ not matter at all.
+ \a nameIndex is the index in the string table corresponding to
+ the name which we are storing
+ */
+void QQmlJSTypePropagator::generate_StoreNameCommon(int nameIndex)
{
const QString name = m_jsUnitGenerator->stringForIndex(nameIndex);
const QQmlJSRegisterContent type = m_typeResolver->scopedType(m_function->qmlScope, name);
@@ -634,11 +645,14 @@ void QQmlJSTypePropagator::generate_StoreNameSloppy(int nameIndex)
}
}
+void QQmlJSTypePropagator::generate_StoreNameSloppy(int nameIndex)
+{
+ return generate_StoreNameCommon(nameIndex);
+}
+
void QQmlJSTypePropagator::generate_StoreNameStrict(int name)
{
- m_state.setHasSideEffects(true);
- Q_UNUSED(name)
- INSTR_PROLOGUE_NOT_IMPLEMENTED();
+ return generate_StoreNameCommon(name);
}
bool QQmlJSTypePropagator::checkForEnumProblems(
diff --git a/src/qmlcompiler/qqmljstypepropagator_p.h b/src/qmlcompiler/qqmljstypepropagator_p.h
index be72d03d94..0360671535 100644
--- a/src/qmlcompiler/qqmljstypepropagator_p.h
+++ b/src/qmlcompiler/qqmljstypepropagator_p.h
@@ -56,6 +56,7 @@ struct Q_QMLCOMPILER_PRIVATE_EXPORT QQmlJSTypePropagator : public QQmlJSCompileP
void generate_LoadName(int nameIndex) override;
void generate_LoadGlobalLookup(int index) override;
void generate_LoadQmlContextPropertyLookup(int index) override;
+ void generate_StoreNameCommon(int nameIndex);
void generate_StoreNameSloppy(int nameIndex) override;
void generate_StoreNameStrict(int name) override;
void generate_LoadElement(int base) override;
diff --git a/tests/auto/qml/qmllint/data/UnqualifiedInStoreStrict.qml b/tests/auto/qml/qmllint/data/UnqualifiedInStoreStrict.qml
new file mode 100644
index 0000000000..198e2146f5
--- /dev/null
+++ b/tests/auto/qml/qmllint/data/UnqualifiedInStoreStrict.qml
@@ -0,0 +1,12 @@
+import QtQuick 2.15
+import QtQuick.Window 2.15
+
+Window {
+ Rectangle {
+ property real divisor: 0
+
+ Timer {
+ onTriggered: function() {"use strict"; divisor = 1 }
+ }
+ }
+}
diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp
index 724d2d792d..daccda852a 100644
--- a/tests/auto/qml/qmllint/tst_qmllint.cpp
+++ b/tests/auto/qml/qmllint/tst_qmllint.cpp
@@ -266,6 +266,9 @@ void TestQmllint::testUnqualified_data()
QTest::newRow("storeSloppy")
<< QStringLiteral("UnqualifiedInStoreSloppy.qml")
<< Result{ { Message{ QStringLiteral("Unqualified access"), 9, 26} } };
+ QTest::newRow("storeStrict")
+ << QStringLiteral("UnqualifiedInStoreStrict.qml")
+ << Result{ { Message{ QStringLiteral("Unqualified access"), 9, 52} } };
}
void TestQmllint::testUnknownCausesFail()