QmlCompiler: Mark StoreElement on JS values has having side effects
A StoreElement on a JS value can do pretty much anything you can imagine, after all. Pick-to: 6.5 6.4 6.4.2 Fixes: QTBUG-109196 Change-Id: Ic638d94b55e6340eb9fe56abc663a6f0f2277f5e Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
parent
83bf594fbd
commit
07d2a80d01
|
@ -681,6 +681,10 @@ void QQmlJSTypePropagator::generate_StoreElement(int base, int index)
|
|||
addReadAccumulator(jsValue);
|
||||
addReadRegister(base, jsValue);
|
||||
addReadRegister(index, jsValue);
|
||||
|
||||
// Writing to a JS array can have side effects all over the place since it's
|
||||
// passed by reference.
|
||||
m_state.setHasSideEffects(true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -161,6 +161,7 @@ set(qml_files
|
|||
signalIndexMismatch.qml
|
||||
signatureIgnored.qml
|
||||
specificParent.qml
|
||||
storeElementSideEffects.qml
|
||||
stringArg.qml
|
||||
stringLength.qml
|
||||
stringToByteArray.qml
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
import QtQml
|
||||
|
||||
QtObject {
|
||||
property var myItem: []
|
||||
Component.onCompleted: myItem[0] = 10
|
||||
}
|
|
@ -155,6 +155,7 @@ private slots:
|
|||
void ambiguousSignals();
|
||||
void fileImportsContainCxxTypes();
|
||||
void lengthAccessArraySequenceCompat();
|
||||
void storeElementSideEffects();
|
||||
};
|
||||
|
||||
void tst_QmlCppCodegen::initTestCase()
|
||||
|
@ -2917,6 +2918,21 @@ void tst_QmlCppCodegen::enumConversion()
|
|||
QVERIFY(o);
|
||||
QCOMPARE(o->property("test").toInt(), 0x04);
|
||||
QCOMPARE(o->property("test_1").toBool(), true);
|
||||
}
|
||||
|
||||
void tst_QmlCppCodegen::storeElementSideEffects()
|
||||
{
|
||||
QQmlEngine engine;
|
||||
|
||||
QQmlComponent c(&engine, QUrl(u"qrc:/qt/qml/TestTypes/storeElementSideEffects.qml"_s));
|
||||
QVERIFY2(c.isReady(), qPrintable(c.errorString()));
|
||||
|
||||
QScopedPointer<QObject> o(c.create());
|
||||
QVERIFY(o);
|
||||
|
||||
const QJSValue prop = o->property("myItem").value<QJSValue>();
|
||||
QVERIFY(prop.isArray());
|
||||
QCOMPARE(prop.property(0).toInt(), 10);
|
||||
};
|
||||
|
||||
void tst_QmlCppCodegen::ambiguousSignals()
|
||||
|
|
Loading…
Reference in New Issue