From ea74f0c68cddf706c950d3910cf7b363fe24885b Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 17 Apr 2019 12:35:42 +0200 Subject: Don't crash when accessing invalid properties through QObjectWrapper Change-Id: I613bf5dc685bb4235262b429d8f7318ea144fb9d Fixes: QTBUG-75203 Reviewed-by: Erik Verbruggen --- .../data/undefinedPropertiesInObjectWrapper.qml | 20 ++++++++++++++++++++ tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 10 ++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/auto/qml/qqmlecmascript/data/undefinedPropertiesInObjectWrapper.qml (limited to 'tests/auto/qml') diff --git a/tests/auto/qml/qqmlecmascript/data/undefinedPropertiesInObjectWrapper.qml b/tests/auto/qml/qqmlecmascript/data/undefinedPropertiesInObjectWrapper.qml new file mode 100644 index 0000000000..7e2f15fc23 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/undefinedPropertiesInObjectWrapper.qml @@ -0,0 +1,20 @@ +import QtQuick 2.12 + +QtObject { + property list entries: [ + QtObject { + readonly property color color: "green" + }, + QtObject { + } + ] + + property Row row: Row { + Repeater { + model: entries + Rectangle { + color: model.color ? model.color : "red" + } + } + } +} diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 0e8844d23f..85cad8f62c 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -367,6 +367,7 @@ private slots: void deleteSparseInIteration(); void saveAccumulatorBeforeToInt32(); void intMinDividedByMinusOne(); + void undefinedPropertiesInObjectWrapper(); private: // static void propertyVarWeakRefCallback(v8::Persistent object, void* parameter); @@ -8958,6 +8959,15 @@ void tst_qqmlecmascript::intMinDividedByMinusOne() QCOMPARE(object->property("doesNotFitInInt").toUInt(), 2147483648u); } +void tst_qqmlecmascript::undefinedPropertiesInObjectWrapper() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFile("undefinedPropertiesInObjectWrapper.qml")); + QVERIFY(component.isReady()); + QScopedPointer object(component.create()); + QVERIFY(!object.isNull()); +} + QTEST_MAIN(tst_qqmlecmascript) #include "tst_qqmlecmascript.moc" -- cgit v1.2.3 From c018df5b4075ae962966d4df7653d476dab02840 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 17 Apr 2019 08:38:20 +0200 Subject: QML: Remove static attchedPropertyIds map If the same object is available under two different names it should still have the same attached properties no matter which name you use. This was achieved by having a static map of metaobjects to attached property IDs that would always hold the first attached property ID registered for a given metaobject. This attached property ID was then used as key in the map of attached properties for the actual objects. The obvious downside to that is that we need a global static which gives us thread safety and static initialization (and destruction) problems. It turns out, all the attached properties are created by attached properties functions, registered by the user. Those functions only get the object to be amended as parameter. Therefore, no attached properties function can be registered for multiple attached properties on the same object as it wouldn't know which one to create for a given call. Thus, the whole ID dance is unnecessary as we can as well index the attached property objects by the function that created them. This nicely avoids creating two attached property objects for the same object and function and still makes the global static unnecessary. Fixes: QTBUG-75176 Change-Id: Ie8d53ef0a6f41c9b3d6b9d611cde1603a557901c Reviewed-by: Erik Verbruggen --- tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/auto/qml') diff --git a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp index 7f103dc5ed..a7805922a5 100644 --- a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp +++ b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp @@ -550,8 +550,8 @@ void tst_qqmlmetatype::unregisterAttachedProperties() c.setData("import QtQuick 2.2\n Item { }", dummy); const QQmlType attachedType = QQmlMetaType::qmlType("QtQuick/KeyNavigation", 2, 2); - QCOMPARE(attachedType.attachedPropertiesId(QQmlEnginePrivate::get(&e)), - attachedType.index()); + QCOMPARE(attachedType.attachedPropertiesType(QQmlEnginePrivate::get(&e)), + attachedType.metaObject()); QVERIFY(c.create()); } @@ -569,8 +569,8 @@ void tst_qqmlmetatype::unregisterAttachedProperties() "Item { KeyNavigation.up: null }", dummy); const QQmlType attachedType = QQmlMetaType::qmlType("QtQuick/KeyNavigation", 2, 2); - QCOMPARE(attachedType.attachedPropertiesId(QQmlEnginePrivate::get(&e)), - attachedType.index()); + QCOMPARE(attachedType.attachedPropertiesType(QQmlEnginePrivate::get(&e)), + attachedType.metaObject()); QVERIFY(c.create()); } -- cgit v1.2.3 From 561a2cec9b95b22783a00b48078b532010357066 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 17 Apr 2019 15:15:52 +0200 Subject: Transform V4_ENABLE_JIT into a feature This way you can enable or disable the JIT when configuring Qt. The conditions for the availability of the JIT have also been cleaned up. There is no reason anymore to artificially restrict availability on x86 and x86_64. The reason for the existence of those clauses are old problems on windows that have been fixed by now. However, on arm and arm64, we need a specialization of the cacheFlush() function for each OS to be supported. Therefore, restrict to the systems for which such a specialization exists. iOS and tvOS are technically supported and you can enable the JIT via the feature flag now. Due to Apple's policy we disable it by default, though. Change-Id: I5fe2a2bf6799b2d11b7ae7c7a85962bcbf44f919 Reviewed-by: Simon Hausmann --- tests/auto/qml/qv4assembler/tst_qv4assembler.cpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'tests/auto/qml') diff --git a/tests/auto/qml/qv4assembler/tst_qv4assembler.cpp b/tests/auto/qml/qv4assembler/tst_qv4assembler.cpp index fd50ff5020..392ce16880 100644 --- a/tests/auto/qml/qv4assembler/tst_qv4assembler.cpp +++ b/tests/auto/qml/qv4assembler/tst_qv4assembler.cpp @@ -140,23 +140,17 @@ void tst_QV4Assembler::functionTable() #endif } -#ifdef V4_ENABLE_JIT -#define JIT_ENABLED 1 -#else -#define JIT_ENABLED 0 -#endif - void tst_QV4Assembler::jitEnabled() { #if defined(Q_OS_IOS) || defined(Q_OS_TVOS) /* JIT should be disabled on iOS and tvOS. */ - QCOMPARE(JIT_ENABLED, 0); + QVERIFY(!QT_CONFIG(qml_jit)); #elif defined(Q_OS_WIN) && defined(Q_PROCESSOR_ARM) /* JIT should be disabled Windows on ARM/ARM64 for now. */ - QCOMPARE(JIT_ENABLED, 0); + QVERIFY(!QT_CONFIG(qml_jit)); #else /* JIT should be enabled on all other architectures/OSes tested in CI. */ - QCOMPARE(JIT_ENABLED, 1); + QVERIFY(QT_CONFIG(qml_jit)); #endif } -- cgit v1.2.3 From dbbbbe569da0aa3900a17ca22bd2be2708fb76f7 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 25 Apr 2019 15:21:19 +0200 Subject: Allow creation of variants from non-singleton QQmlTypeWrappers I don't see any reason why this should be prohibited. Change-Id: I4a54c55eff4b9151691d0587627efad4a06485f1 Fixes: QTBUG-74815 Reviewed-by: Simon Hausmann --- tests/auto/qml/qqmllanguage/data/typeWrapperToVariant.qml | 15 +++++++++++++++ tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 15 +++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/auto/qml/qqmllanguage/data/typeWrapperToVariant.qml (limited to 'tests/auto/qml') diff --git a/tests/auto/qml/qqmllanguage/data/typeWrapperToVariant.qml b/tests/auto/qml/qqmllanguage/data/typeWrapperToVariant.qml new file mode 100644 index 0000000000..8a1535ff50 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/typeWrapperToVariant.qml @@ -0,0 +1,15 @@ +import QtQml 2.0 + +QtObject { + id: root + + property QtObject target: QtObject { + Component.onCompleted: { + root.connections.target = root.target.Component + } + } + + property Connections connections: Connections { + ignoreUnknownSignals: true + } +} diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 85dddbcb54..87468c329c 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -301,6 +301,8 @@ private slots: void polymorphicFunctionLookup(); void anchorsToParentInPropertyChanges(); + void typeWrapperToVariant(); + private: QQmlEngine engine; QStringList defaultImportPathList; @@ -5085,6 +5087,19 @@ void tst_qqmllanguage::anchorsToParentInPropertyChanges() QTRY_COMPARE(o->property("edgeWidth").toInt(), 200); } +void tst_qqmllanguage::typeWrapperToVariant() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("typeWrapperToVariant.qml")); + VERIFY_ERRORS(0); + QScopedPointer o(component.create()); + QVERIFY(!o.isNull()); + QObject *connections = qvariant_cast(o->property("connections")); + QVERIFY(connections); + QObject *target = qvariant_cast(connections->property("target")); + QVERIFY(target); +} + QTEST_MAIN(tst_qqmllanguage) #include "tst_qqmllanguage.moc" -- cgit v1.2.3 From 9e5ca92712da3392d1f2957dc1e546cdddd1ce0a Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 18 Apr 2019 14:22:10 +0200 Subject: Remove tracing JIT infrastructure The tracing JIT won't be finished. Therefore, remove the parts that have already been integrated. Change-Id: If72036be904bd7fc17ba9bcba0a317f8ed6cb30d Reviewed-by: Erik Verbruggen --- tests/auto/qml/qml.pro | 4 - tests/auto/qml/v4traced/tst_v4traced.cpp | 325 ------------------------------- tests/auto/qml/v4traced/v4traced.pro | 5 - 3 files changed, 334 deletions(-) delete mode 100644 tests/auto/qml/v4traced/tst_v4traced.cpp delete mode 100644 tests/auto/qml/v4traced/v4traced.pro (limited to 'tests/auto/qml') diff --git a/tests/auto/qml/qml.pro b/tests/auto/qml/qml.pro index 86f36286d9..db9bb52010 100644 --- a/tests/auto/qml/qml.pro +++ b/tests/auto/qml/qml.pro @@ -105,7 +105,3 @@ qtConfig(private_tests): \ qtNomakeTools( \ qmlplugindump \ ) - -QtConfig(qml_tracing) { - PRIVATETESTS += v4traced -} diff --git a/tests/auto/qml/v4traced/tst_v4traced.cpp b/tests/auto/qml/v4traced/tst_v4traced.cpp deleted file mode 100644 index f82cc0ed5e..0000000000 --- a/tests/auto/qml/v4traced/tst_v4traced.cpp +++ /dev/null @@ -1,325 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include -#include - -class EnvVarSaver -{ -public: - EnvVarSaver(const char *name, const QByteArray &newValue) - : _name(name) - { - _wasSet = qEnvironmentVariableIsSet(name); - if (_wasSet) - _oldValue = qgetenv(name); - qputenv(name, newValue); - } - - ~EnvVarSaver() - { - if (_wasSet) - qputenv(_name, _oldValue); - else - qunsetenv(_name); - } - -private: - const char *_name; - bool _wasSet; - QByteArray _oldValue; -}; - -class tst_v4traced : public QObject -{ - Q_OBJECT - -private slots: - void collectTraces_data(); - void collectTraces(); - - void binopI32deopt_data(); - void binopI32deopt(); - - void calls_data(); - void calls(); - - void setLookup(); - void construct(); -}; - -void tst_v4traced::collectTraces_data() -{ - QTest::addColumn("code"); - QTest::addColumn("tracePointCount"); - QTest::addColumn("interestingTracePoint"); - QTest::addColumn("expectedBits"); - - QTest::newRow("int+") << "var a = 4; a + 2" << 2 << 1 << quint8(QV4::ObservedTraceValues::Integer); - QTest::newRow("double+") << "var a = 4.1; a + 1.9" << 2 << 1 << quint8(QV4::ObservedTraceValues::Double); - QTest::newRow("object+") << "var a = '4'; a + '2'" << 2 << 1 << quint8(QV4::ObservedTraceValues::Other); -} - -void tst_v4traced::collectTraces() -{ - QFETCH(QString, code); - QFETCH(int, tracePointCount); - QFETCH(int, interestingTracePoint); - QFETCH(quint8, expectedBits); - - EnvVarSaver forceInterpreter("QV4_FORCE_INTERPRETER", "1"); - EnvVarSaver forceTracing("QV4_FORCE_TRACING", "1"); - - QV4::ExecutionEngine vm; - QV4::Scope scope(&vm); - QV4::ScopedContext ctx(scope, vm.rootContext()); - QV4::ScopedValue result(scope); - QScopedPointer script; - script.reset(new QV4::Script(ctx, QV4::Compiler::ContextType::Global, code, "collectTraces")); - script->parseAsBinding = false; - - QVERIFY(!scope.engine->hasException); - script->parse(); - QVERIFY(!scope.engine->hasException); - - QVERIFY(script->function()->tracingEnabled()); - result = script->run(); - QVERIFY(!scope.engine->hasException); - - QCOMPARE(int(script->function()->compiledFunction->nTraceInfos), tracePointCount); - QCOMPARE(*script->function()->traceInfo(interestingTracePoint), expectedBits); -} - -void tst_v4traced::binopI32deopt_data() -{ - QTest::addColumn("operand"); - QTest::addColumn("int_arg1"); - QTest::addColumn("int_arg2"); - QTest::addColumn("int_result"); - QTest::addColumn("other_arg1"); - QTest::addColumn("other_arg2"); - QTest::addColumn("other_result"); - - QTest::newRow("+") << "+" << 1 << 2 << 3 << "1.1" << "1.9" << 3.0; - QTest::newRow("-") << "-" << 3 << 2 << 1 << "3.1" << "2.1" << 1.0; - QTest::newRow("*") << "*" << 2 << 3 << 6 << "2.1" << "1.9" << 3.99; - QTest::newRow("/") << "/" << 6 << 3 << 2 << "6.6" << "3.3" << 2.0; - - QTest::newRow("&") << "&" << 6 << 3 << 2 << "'6'" << "'3'" << 2.0; - QTest::newRow("|") << "|" << 6 << 3 << 7 << "'6'" << "'3'" << 7.0; - QTest::newRow("^") << "^" << 6 << 3 << 5 << "'6'" << "'3'" << 5.0; - - QTest::newRow("<<") << "<<" << 5 << 1 << 10 << "'5'" << "'1'" << 10.0; - QTest::newRow(">>") << ">>" << -1 << 1 << -1 << "'-1'" << "'1'" << -1.0; - QTest::newRow(">>>") << ">>>" << -1 << 1 << 0x7FFFFFFF << "'-1'" << "'1'" << 2147483647.0; - - QTest::newRow("==") << "==" << 2 << 1 << 0 << "'2'" << "'1'" << 0.0; - QTest::newRow("!=") << "!=" << 2 << 1 << 1 << "'2'" << "'1'" << 1.0; - QTest::newRow("<" ) << "<" << 2 << 1 << 0 << "'2'" << "'1'" << 0.0; - QTest::newRow("<=") << "<=" << 2 << 1 << 0 << "'2'" << "'1'" << 0.0; - QTest::newRow(">" ) << ">" << 2 << 1 << 1 << "'2'" << "'1'" << 1.0; - QTest::newRow(">=") << ">=" << 2 << 1 << 1 << "'2'" << "'1'" << 1.0; -} - -void tst_v4traced::binopI32deopt() -{ - QFETCH(QString, operand); - QFETCH(int, int_arg1); - QFETCH(int, int_arg2); - QFETCH(int, int_result); - QFETCH(QString, other_arg1); - QFETCH(QString, other_arg2); - QFETCH(double, other_result); - - QString func = QStringLiteral("function binopI32(a, b) { return a %1 b }").arg(operand); - QString intCall = QStringLiteral("binopI32(%1, %2)").arg(int_arg1).arg(int_arg2); - QString otherCall = QStringLiteral("binopI32(%1, %2)").arg(other_arg1).arg(other_arg2); - - QJSEngine engine; - engine.evaluate(func); - - QCOMPARE(engine.evaluate(intCall).toInt(), int_result); // interpret + trace - QCOMPARE(engine.evaluate(intCall).toInt(), int_result); // jit - QCOMPARE(engine.evaluate(otherCall).toNumber(), other_result); // deopt - QCOMPARE(engine.evaluate(otherCall).toNumber(), other_result); // retrace - QCOMPARE(engine.evaluate(otherCall).toNumber(), other_result); // rejit -} - -void tst_v4traced::calls_data() -{ - QTest::addColumn("call"); - - QTest::newRow("callGlobalLookup") << "globalLookup"; - QTest::newRow("callPropertyLookup") << "obj.propertyLookup"; -} - -class Calls -{ -public: - static int callCount; - - static QV4::ReturnedValue doSomething(const QV4::FunctionObject */*o*/, - const QV4::Value */*thiz*/, - const QV4::Value *argv, int argc) - { - ++callCount; - - if (argc == 0) - return QV4::Encode(42); - - int prod = 1; - for (int i = 0; i < argc; ++i) { - Q_ASSERT(argv[i].isInteger()); - prod *= argv[i].int_32(); - } - return QV4::Encode(prod); - } -}; - -int Calls::callCount = 0; - -void tst_v4traced::calls() -{ - QFETCH(QString, call); - - EnvVarSaver forceTracing("QV4_FORCE_TRACING", "1"); - EnvVarSaver jitCallThreshold("QV4_JIT_CALL_THRESHOLD", "1"); - - QV4::ExecutionEngine vm; - QV4::Scope scope(&vm); - QV4::ScopedContext ctx(scope, vm.rootContext()); - vm.globalObject->defineDefaultProperty(QLatin1String("globalLookup"), - Calls::doSomething); - QV4::ScopedObject obj(scope, vm.newObject()); - vm.globalObject->defineDefaultProperty(QLatin1String("obj"), obj); - obj->defineDefaultProperty("propertyLookup", Calls::doSomething); - - QString code = QStringLiteral( - "function doCalls() {\n" - " if (%1() != 42) return false\n" - " if (%1(21, 2) != 42) return false\n" - " if (%1(2, 3, 7) != 42) return false\n" - " return true\n" - "}\n" - "var result = true\n" - "for (var i = 0; i < 10; ++i) {\n" - " if (!doCalls()) { result = false; break }" - "}\n" - "result\n").arg(call); - QScopedPointer script; - script.reset(new QV4::Script(ctx, QV4::Compiler::ContextType::Global, code, "call")); - script->parseAsBinding = false; - - QVERIFY(!scope.engine->hasException); - script->parse(); - QVERIFY(!scope.engine->hasException); - - Calls::callCount = 0; - QV4::ScopedValue result(scope, script->run()); - QVERIFY(!scope.engine->hasException); - - QVERIFY(result->isBoolean()); - QVERIFY(result->booleanValue()); - QCOMPARE(Calls::callCount, 30); -} - -void tst_v4traced::setLookup() -{ - EnvVarSaver forceTracing("QV4_FORCE_TRACING", "1"); - EnvVarSaver jitCallThreshold("QV4_JIT_CALL_THRESHOLD", "1"); - - QV4::ExecutionEngine vm; - QV4::Scope scope(&vm); - QV4::ScopedContext ctx(scope, vm.rootContext()); - QV4::ScopedObject obj(scope, vm.newObject()); - vm.globalObject->defineDefaultProperty(QLatin1String("oracle"), obj); - obj->defineDefaultProperty("answer", QV4::Primitive::fromInt32(32)); - - QString code = QStringLiteral( - "function doit() {\n" - " ++oracle.answer\n" - "}\n" - "for (var i = 0; i < 10; ++i) doit()\n" - "oracle.answer\n"); - QScopedPointer script; - script.reset(new QV4::Script(ctx, QV4::Compiler::ContextType::Global, code, "setLookup")); - script->parseAsBinding = false; - - QVERIFY(!scope.engine->hasException); - script->parse(); - QVERIFY(!scope.engine->hasException); - - QV4::ScopedValue result(scope, script->run()); - QVERIFY(!scope.engine->hasException); - - QVERIFY(result->isInteger()); - QCOMPARE(result->int_32(), 42); -} - -void tst_v4traced::construct() -{ - EnvVarSaver forceTracing("QV4_FORCE_TRACING", "1"); - EnvVarSaver jitCallThreshold("QV4_JIT_CALL_THRESHOLD", "1"); - - QV4::ExecutionEngine vm; - QV4::Scope scope(&vm); - QV4::ScopedContext ctx(scope, vm.rootContext()); - QV4::ScopedObject obj(scope, vm.newObject()); - vm.globalObject->defineDefaultProperty(QLatin1String("oracle"), obj); - obj->defineDefaultProperty("answer", QV4::Primitive::fromInt32(32)); - - QString code = QStringLiteral( - "function doit() {\n" - " this.arr = new Array()\n" - " this.arr[0] = 0\n" - " this.arr[1] = 1\n" - " this.arr[2] = 2\n" - "}\n" - "var o\n" - "for (var i = 0; i < 10; ++i) o = new doit()\n" - "o.arr\n"); - QScopedPointer script; - script.reset(new QV4::Script(ctx, QV4::Compiler::ContextType::Global, code, "setLookup")); - script->parseAsBinding = false; - - QVERIFY(!scope.engine->hasException); - script->parse(); - QVERIFY(!scope.engine->hasException); - - QV4::ScopedValue result(scope, script->run()); - QVERIFY(!scope.engine->hasException); - - QVERIFY(result->as()); -} - -QTEST_MAIN(tst_v4traced) - -#include "tst_v4traced.moc" diff --git a/tests/auto/qml/v4traced/v4traced.pro b/tests/auto/qml/v4traced/v4traced.pro deleted file mode 100644 index cbc8f38046..0000000000 --- a/tests/auto/qml/v4traced/v4traced.pro +++ /dev/null @@ -1,5 +0,0 @@ -CONFIG += testcase -TARGET = tst_v4traced -macos:CONFIG -= app_bundle -QT += core-private qml-private testlib -SOURCES += tst_v4traced.cpp -- cgit v1.2.3 From 4fea3ec29c9911522a379a01418394b5cad29ecc Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 29 Apr 2019 16:44:48 +0200 Subject: Skip block context within call contexts when searching for parameters Only the call context contains the signal parameters. However, there can be any number of nested block contexts in a function. This manifests itself when the function needs an execution context. The simplest way to trigger this is attaching a debugger. Fixes: QTBUG-75393 Change-Id: Iabdc06a9fe7bf88204525d6940b626575fee1579 Reviewed-by: Simon Hausmann --- .../qml/debugger/qv4debugger/tst_qv4debugger.cpp | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests/auto/qml') diff --git a/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp b/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp index b75fb6b895..497c721f50 100644 --- a/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp +++ b/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp @@ -322,6 +322,8 @@ private slots: void lastLineOfConditional(); void readThis(); + void signalParameters(); + private: QV4Debugger *debugger() const { @@ -899,6 +901,31 @@ void tst_qv4debugger::readThis() QCOMPARE(a.value("value").toInt(), 5); } +void tst_qv4debugger::signalParameters() +{ + QQmlEngine engine; + QV4::ExecutionEngine *v4 = engine.handle(); + v4->setDebugger(new QV4Debugger(v4)); + + QQmlComponent component(&engine); + component.setData("import QtQml 2.12\n" + "QtObject {\n" + " id: root\n" + " property string result\n" + " signal signalWithArg(string textArg)\n" + " property Connections connections : Connections {\n" + " target: root\n" + " onSignalWithArg: { root.result = textArg; }\n" + " }\n" + " Component.onCompleted: signalWithArg('something')\n" + "}", QUrl("test.qml")); + + QVERIFY(component.isReady()); + QScopedPointer obj(component.create()); + QVERIFY(obj); + QCOMPARE(obj->property("result").toString(), QLatin1String("something")); +} + QTEST_MAIN(tst_qv4debugger) #include "tst_qv4debugger.moc" -- cgit v1.2.3 From ac0d313ab15aa78c444d00ed6a1a202a1351dfa1 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 30 Apr 2019 13:29:45 +0200 Subject: Yarr: Reject quantifiers larger than 16M Nobody needs those and we run into integer overflows later on if we accept them. Fixes: QTBUG-74048 Change-Id: Ib8ccd05e4bd6f662c38fbe95bf1350f81982e1b8 Reviewed-by: Simon Hausmann --- tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests/auto/qml') diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 85cad8f62c..007ad99655 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -368,6 +368,7 @@ private slots: void saveAccumulatorBeforeToInt32(); void intMinDividedByMinusOne(); void undefinedPropertiesInObjectWrapper(); + void hugeRegexpQuantifiers(); private: // static void propertyVarWeakRefCallback(v8::Persistent object, void* parameter); @@ -8968,6 +8969,16 @@ void tst_qqmlecmascript::undefinedPropertiesInObjectWrapper() QVERIFY(!object.isNull()); } +void tst_qqmlecmascript::hugeRegexpQuantifiers() +{ + QJSEngine engine; + QJSValue value = engine.evaluate("/({3072140529})?{3072140529}/"); + + // It's a regular expression, but it won't match anything. + // The RegExp compiler also shouldn't crash. + QVERIFY(value.isRegExp()); +} + QTEST_MAIN(tst_qqmlecmascript) #include "tst_qqmlecmascript.moc" -- cgit v1.2.3 From 9b6c20cb719542cfcf3e031afd5b2b0b1cd3833e Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 18 Apr 2019 15:37:17 +0200 Subject: Make JavaScript execution interruptible Add an atomic isInterrupted flag to BaseEngine and check that in addition to the hasException flag on checkException(). Add some more exception checks to cover all possible infinite loops. Also, remove the writeBarrierActive member from QV4::EngineBase. It isn't used. Fixes: QTBUG-49080 Change-Id: I86b3114e3e61aff3e5eb9b020749a908ed801c2b Reviewed-by: Simon Hausmann --- tests/auto/qml/qjsengine/tst_qjsengine.cpp | 79 ++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) (limited to 'tests/auto/qml') diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp index 9c3316e39f..6ca2663f30 100644 --- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp +++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp @@ -245,6 +245,9 @@ private slots: void equality(); void aggressiveGc(); + void interrupt_data(); + void interrupt(); + public: Q_INVOKABLE QJSValue throwingCppMethod1(); Q_INVOKABLE void throwingCppMethod2(); @@ -4839,6 +4842,82 @@ void tst_QJSEngine::aggressiveGc() qputenv("QV4_MM_AGGRESSIVE_GC", origAggressiveGc); } +void tst_QJSEngine::interrupt_data() +{ + QTest::addColumn("jitThreshold"); + QTest::addColumn("code"); + + const int big = (1 << 24); + for (int i = 0; i <= big; i += big) { + const char *mode = i ? "interpret" : "jit"; + QTest::addRow("for with content / %s", mode) << i << "var a = 0; for (;;) { a += 2; }"; + QTest::addRow("for empty / %s", mode) << i << "for (;;) {}"; + QTest::addRow("for continue / %s", mode) << i << "for (;;) { continue; }"; + QTest::addRow("while with content / %s", mode) << i << "var a = 0; while (true) { a += 2; }"; + QTest::addRow("while empty / %s", mode) << i << "while (true) {}"; + QTest::addRow("while continue / %s", mode) << i << "while (true) { continue; }"; + QTest::addRow("do with content / %s", mode) << i << "var a = 0; do { a += 2; } while (true);"; + QTest::addRow("do empty / %s", mode) << i << "do {} while (true);"; + QTest::addRow("do continue / %s", mode) << i << "do { continue; } while (true);"; + QTest::addRow("nested loops / %s", mode) << i << "while (true) { for (;;) {} }"; + QTest::addRow("labeled continue / %s", mode) << i << "a: while (true) { for (;;) { continue a; } }"; + QTest::addRow("labeled break / %s", mode) << i << "while (true) { a: for (;;) { break a; } }"; + QTest::addRow("tail call / %s", mode) << i << "'use strict';\nfunction x() { return x(); }; x();"; + } +} + +class TemporaryJitThreshold +{ + Q_DISABLE_COPY_MOVE(TemporaryJitThreshold) +public: + TemporaryJitThreshold(int threshold) { + m_wasSet = qEnvironmentVariableIsSet(m_envVar); + m_value = qgetenv(m_envVar); + qputenv(m_envVar, QByteArray::number(threshold)); + } + + ~TemporaryJitThreshold() + { + if (m_wasSet) + qputenv(m_envVar, m_value); + else + qunsetenv(m_envVar); + } + +private: + const char *m_envVar = "QV4_JIT_CALL_THRESHOLD"; + bool m_wasSet = false; + QByteArray m_value; +}; + +void tst_QJSEngine::interrupt() +{ + QFETCH(int, jitThreshold); + QFETCH(QString, code); + + TemporaryJitThreshold threshold(jitThreshold); + Q_UNUSED(threshold); + + QJSEngine *engineInThread = nullptr; + QScopedPointer worker(QThread::create([&engineInThread, &code, jitThreshold](){ + QJSEngine jsEngine; + engineInThread = &jsEngine; + QJSValue result = jsEngine.evaluate(code); + QVERIFY(jsEngine.isInterrupted()); + QVERIFY(result.isError()); + QCOMPARE(result.toString(), QString::fromLatin1("Error: Interrupted")); + engineInThread = nullptr; + })); + worker->start(); + + QTRY_VERIFY(engineInThread); + + engineInThread->setInterrupted(true); + + QVERIFY(worker->wait()); + QVERIFY(!engineInThread); +} + QTEST_MAIN(tst_QJSEngine) #include "tst_qjsengine.moc" -- cgit v1.2.3 From 325e6305b418ffe1dfb9a36c2516c6a8a3de5733 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 3 Apr 2019 15:22:22 +0200 Subject: Move model types into their own library The model types are not part of the core QML runtime and should only be loaded if you explicitly import them. We cannot enforce that in Qt5 as some of them are available from the QtQml import, but we can change it in Qt6. Change-Id: I1e49e84d748e352537ec2d4af901c034c91d038f Reviewed-by: Erik Verbruggen --- tests/auto/qml/qqmlchangeset/qqmlchangeset.pro | 2 +- tests/auto/qml/qqmlinstantiator/qqmlinstantiator.pro | 2 +- tests/auto/qml/qqmlinstantiator/tst_qqmlinstantiator.cpp | 2 +- tests/auto/qml/qqmllistcompositor/qqmllistcompositor.pro | 2 +- tests/auto/qml/qqmllistmodel/qqmllistmodel.pro | 2 +- tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp | 2 +- .../auto/qml/qqmllistmodelworkerscript/qqmllistmodelworkerscript.pro | 2 +- .../qml/qqmllistmodelworkerscript/tst_qqmllistmodelworkerscript.cpp | 2 +- tests/auto/qml/qqmlobjectmodel/qqmlobjectmodel.pro | 2 +- tests/auto/qml/qqmlobjectmodel/tst_qqmlobjectmodel.cpp | 4 ++-- tests/auto/qml/qqmltablemodel/qqmltablemodel.pro | 2 +- tests/auto/qml/qqmltablemodel/tst_qqmltablemodel.cpp | 2 +- 12 files changed, 13 insertions(+), 13 deletions(-) (limited to 'tests/auto/qml') diff --git a/tests/auto/qml/qqmlchangeset/qqmlchangeset.pro b/tests/auto/qml/qqmlchangeset/qqmlchangeset.pro index 9f854f1fa2..cdac5c0ff9 100644 --- a/tests/auto/qml/qqmlchangeset/qqmlchangeset.pro +++ b/tests/auto/qml/qqmlchangeset/qqmlchangeset.pro @@ -4,4 +4,4 @@ macx:CONFIG -= app_bundle SOURCES += tst_qqmlchangeset.cpp -QT += core-private gui-private qml-private testlib +QT += core-private gui-private qml-private testlib qmlmodels-private diff --git a/tests/auto/qml/qqmlinstantiator/qqmlinstantiator.pro b/tests/auto/qml/qqmlinstantiator/qqmlinstantiator.pro index 542ec44736..e8ed8e91b1 100644 --- a/tests/auto/qml/qqmlinstantiator/qqmlinstantiator.pro +++ b/tests/auto/qml/qqmlinstantiator/qqmlinstantiator.pro @@ -9,4 +9,4 @@ include (../../shared/util.pri) TESTDATA = data/* -QT += core-private gui-private qml-private testlib +QT += core-private gui-private qml-private testlib qmlmodels-private diff --git a/tests/auto/qml/qqmlinstantiator/tst_qqmlinstantiator.cpp b/tests/auto/qml/qqmlinstantiator/tst_qqmlinstantiator.cpp index a66f13e6bb..9c5e09c77c 100644 --- a/tests/auto/qml/qqmlinstantiator/tst_qqmlinstantiator.cpp +++ b/tests/auto/qml/qqmlinstantiator/tst_qqmlinstantiator.cpp @@ -31,7 +31,7 @@ #include #include -#include +#include #include #include #include "../../shared/util.h" diff --git a/tests/auto/qml/qqmllistcompositor/qqmllistcompositor.pro b/tests/auto/qml/qqmllistcompositor/qqmllistcompositor.pro index 4ada590a2a..62ad85547e 100644 --- a/tests/auto/qml/qqmllistcompositor/qqmllistcompositor.pro +++ b/tests/auto/qml/qqmllistcompositor/qqmllistcompositor.pro @@ -4,4 +4,4 @@ macx:CONFIG -= app_bundle SOURCES += tst_qqmllistcompositor.cpp -QT += core-private gui-private qml-private quick-private testlib +QT += core-private gui-private qml-private quick-private testlib qmlmodels-private diff --git a/tests/auto/qml/qqmllistmodel/qqmllistmodel.pro b/tests/auto/qml/qqmllistmodel/qqmllistmodel.pro index 8e3aed0baf..4d44d6b22b 100644 --- a/tests/auto/qml/qqmllistmodel/qqmllistmodel.pro +++ b/tests/auto/qml/qqmllistmodel/qqmllistmodel.pro @@ -8,4 +8,4 @@ include (../../shared/util.pri) TESTDATA = data/* -QT += core-private gui-private qml-private quick-private testlib +QT += core-private gui-private qml-private quick-private testlib qmlmodels-private diff --git a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp index 2022a0d892..77ab0ecbc0 100644 --- a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp +++ b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include diff --git a/tests/auto/qml/qqmllistmodelworkerscript/qqmllistmodelworkerscript.pro b/tests/auto/qml/qqmllistmodelworkerscript/qqmllistmodelworkerscript.pro index 9e1cea9867..de58c0c075 100644 --- a/tests/auto/qml/qqmllistmodelworkerscript/qqmllistmodelworkerscript.pro +++ b/tests/auto/qml/qqmllistmodelworkerscript/qqmllistmodelworkerscript.pro @@ -8,4 +8,4 @@ include (../../shared/util.pri) TESTDATA = data/* -QT += core-private gui-private qml-private quick-private testlib +QT += core-private gui-private qml-private quick-private testlib qmlmodels-private diff --git a/tests/auto/qml/qqmllistmodelworkerscript/tst_qqmllistmodelworkerscript.cpp b/tests/auto/qml/qqmllistmodelworkerscript/tst_qqmllistmodelworkerscript.cpp index 236a13a6f8..b5e8800d0e 100644 --- a/tests/auto/qml/qqmllistmodelworkerscript/tst_qqmllistmodelworkerscript.cpp +++ b/tests/auto/qml/qqmllistmodelworkerscript/tst_qqmllistmodelworkerscript.cpp @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include diff --git a/tests/auto/qml/qqmlobjectmodel/qqmlobjectmodel.pro b/tests/auto/qml/qqmlobjectmodel/qqmlobjectmodel.pro index 88bb630e29..5746ff754a 100644 --- a/tests/auto/qml/qqmlobjectmodel/qqmlobjectmodel.pro +++ b/tests/auto/qml/qqmlobjectmodel/qqmlobjectmodel.pro @@ -5,4 +5,4 @@ osx:CONFIG -= app_bundle SOURCES += tst_qqmlobjectmodel.cpp QT += qml testlib -QT += core-private qml-private +QT += core-private qml-private qmlmodels-private diff --git a/tests/auto/qml/qqmlobjectmodel/tst_qqmlobjectmodel.cpp b/tests/auto/qml/qqmlobjectmodel/tst_qqmlobjectmodel.cpp index fb63d811a8..6691fa43a0 100644 --- a/tests/auto/qml/qqmlobjectmodel/tst_qqmlobjectmodel.cpp +++ b/tests/auto/qml/qqmlobjectmodel/tst_qqmlobjectmodel.cpp @@ -25,8 +25,8 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include -#include +#include +#include #include #include diff --git a/tests/auto/qml/qqmltablemodel/qqmltablemodel.pro b/tests/auto/qml/qqmltablemodel/qqmltablemodel.pro index 11b11132aa..9d298dfdf2 100644 --- a/tests/auto/qml/qqmltablemodel/qqmltablemodel.pro +++ b/tests/auto/qml/qqmltablemodel/qqmltablemodel.pro @@ -7,4 +7,4 @@ include (../../shared/util.pri) TESTDATA = data/* -QT += core gui qml-private qml quick-private quick testlib +QT += core gui qml-private qml quick-private quick testlib qmlmodels-private diff --git a/tests/auto/qml/qqmltablemodel/tst_qqmltablemodel.cpp b/tests/auto/qml/qqmltablemodel/tst_qqmltablemodel.cpp index 113a27494d..d913bcdf9a 100644 --- a/tests/auto/qml/qqmltablemodel/tst_qqmltablemodel.cpp +++ b/tests/auto/qml/qqmltablemodel/tst_qqmltablemodel.cpp @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include #include -- cgit v1.2.3