aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qjsvalue
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-06-14 01:01:31 +0200
committerUlf Hermann <ulf.hermann@qt.io>2019-06-14 09:50:21 +0200
commit82ca44ca1a4abb2bcfee5f8ff41df72d02cf4491 (patch)
tree1795638fbf3ad02c16a69dd69efb8738976f7a07 /tests/auto/qml/qjsvalue
parent6d5a0a55d862c78b185a077171a0b46a94d5a599 (diff)
parent15b90204fa5126f339db551cf7429534f1359322 (diff)
Merge remote-tracking branch 'origin/5.13' into dev
Conflicts: tests/auto/qml/qjsengine/tst_qjsengine.cpp Change-Id: I34df194046a91ee8a076ce28022eb99d68e7f362
Diffstat (limited to 'tests/auto/qml/qjsvalue')
-rw-r--r--tests/auto/qml/qjsvalue/qjsvalue.pro2
-rw-r--r--tests/auto/qml/qjsvalue/tst_qjsvalue.cpp37
-rw-r--r--tests/auto/qml/qjsvalue/tst_qjsvalue.h4
3 files changed, 40 insertions, 3 deletions
diff --git a/tests/auto/qml/qjsvalue/qjsvalue.pro b/tests/auto/qml/qjsvalue/qjsvalue.pro
index 3bbbbd4787..a01cffa100 100644
--- a/tests/auto/qml/qjsvalue/qjsvalue.pro
+++ b/tests/auto/qml/qjsvalue/qjsvalue.pro
@@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qjsvalue
macx:CONFIG -= app_bundle
-QT += qml widgets testlib gui-private
+QT += qml widgets testlib gui-private qml-private
SOURCES += tst_qjsvalue.cpp
HEADERS += tst_qjsvalue.h
diff --git a/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp b/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp
index a57cd3113c..4de72ae7a1 100644
--- a/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp
+++ b/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp
@@ -27,7 +27,14 @@
****************************************************************************/
#include "tst_qjsvalue.h"
+
+#include <private/qv4engine_p.h>
+#include <private/qjsvalue_p.h>
+
#include <QtWidgets/QPushButton>
+#include <QtCore/qthread.h>
+
+#include <memory>
tst_QJSValue::tst_QJSValue()
: engine(nullptr)
@@ -2650,4 +2657,34 @@ void tst_QJSValue::nestedObjectToVariant()
QCOMPARE(o.toVariant(), expected);
}
+void tst_QJSValue::deleteFromDifferentThread()
+{
+#if !QT_CONFIG(thread)
+ QSKIP("Need thread support to destroy QJSValues from different threads");
+#else
+ QV4::PersistentValueStorage storage(engine->handle());
+ QCOMPARE(storage.firstPage, nullptr);
+ QJSValue jsval;
+ QJSValuePrivate::setRawValue(&jsval, storage.allocate());
+ QVERIFY(storage.firstPage != nullptr);
+
+ QMutex mutex;
+ QWaitCondition condition;
+
+ std::unique_ptr<QThread> thread(QThread::create([&]() {
+ QMutexLocker locker(&mutex);
+ QJSValuePrivate::free(&jsval);
+ QJSValuePrivate::setRawValue(&jsval, nullptr);
+ QVERIFY(storage.firstPage != nullptr);
+ condition.wakeOne();
+ }));
+
+ QMutexLocker locker(&mutex);
+ thread->start();
+ condition.wait(&mutex);
+ QTRY_VERIFY(thread->isFinished());
+ QTRY_COMPARE(storage.firstPage, nullptr);
+#endif
+}
+
QTEST_MAIN(tst_QJSValue)
diff --git a/tests/auto/qml/qjsvalue/tst_qjsvalue.h b/tests/auto/qml/qjsvalue/tst_qjsvalue.h
index 9532b1f10e..f704169d43 100644
--- a/tests/auto/qml/qjsvalue/tst_qjsvalue.h
+++ b/tests/auto/qml/qjsvalue/tst_qjsvalue.h
@@ -35,8 +35,6 @@
#include <qjsvalue.h>
#include <QtTest/QtTest>
-Q_DECLARE_METATYPE(QVariant)
-
class tst_QJSValue : public QObject
{
Q_OBJECT
@@ -144,6 +142,8 @@ private slots:
void nestedObjectToVariant_data();
void nestedObjectToVariant();
+ void deleteFromDifferentThread();
+
private:
void newEngine()
{