diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-07-11 14:51:40 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-07-11 17:24:39 +0200 |
commit | 13374ceb165c44658aa97890c37b206859c9a31c (patch) | |
tree | 562362b196a459ee3449a5a1e60e5216a9dd6984 /tests/auto/qml/qjsvalue/tst_qjsvalue.cpp | |
parent | ae47deba4c943c496412530a8d2a5a688ae12038 (diff) | |
parent | b5d18be5a03406d0aac83856dd41e1525fd14a28 (diff) |
Merge remote-tracking branch 'origin/wip/qt6' into wip/cmake
Change-Id: I2963c1209316fb6755f572969f368970450d7991
Diffstat (limited to 'tests/auto/qml/qjsvalue/tst_qjsvalue.cpp')
-rw-r--r-- | tests/auto/qml/qjsvalue/tst_qjsvalue.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
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) |