diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2011-12-13 10:04:40 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-12-15 12:05:08 +0100 |
commit | a401d0756f6ac3cee5597d5528515061326c3bfa (patch) | |
tree | 4c5b5ec54d856dc188da54bc8faf0d9de37c9ee7 /tests/auto/declarative/qjsengine/tst_qjsengine.cpp | |
parent | 4bb5b4f01c1b38fce9f1a11346de5bd4ee3c6fd4 (diff) |
Fix that QJSEngine cannot be used from threads other than the gui thread
Implicitly allocate & enter an isolate per thread if needed, store it in TLS and
exit it upon thread destruction. As the code that represents QObject
dependencies in the GC through implicit dependencies uses its own context,
its per-thread data is folded into the v8engine TLS to ensure that it is
destructed before the isolate is exited.
Task-number: QTBUG-23099
Change-Id: I86538b54939b2fe64db843052eac04c7fd31813e
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
Diffstat (limited to 'tests/auto/declarative/qjsengine/tst_qjsengine.cpp')
-rw-r--r-- | tests/auto/declarative/qjsengine/tst_qjsengine.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/auto/declarative/qjsengine/tst_qjsengine.cpp b/tests/auto/declarative/qjsengine/tst_qjsengine.cpp index e806a658cd..88385265e8 100644 --- a/tests/auto/declarative/qjsengine/tst_qjsengine.cpp +++ b/tests/auto/declarative/qjsengine/tst_qjsengine.cpp @@ -315,6 +315,7 @@ private slots: void dateConversionJSQt(); void dateConversionQtJS(); void functionPrototypeExtensions(); + void threadedEngine(); }; tst_QJSEngine::tst_QJSEngine() @@ -6488,6 +6489,35 @@ void tst_QJSEngine::functionPrototypeExtensions() QCOMPARE(props.property("length").toInt32(), 0); } +class ThreadedTestEngine : public QThread { + Q_OBJECT; + +public: + int result; + + ThreadedTestEngine() + : result(0) {} + + void run() { + QJSEngine firstEngine; + QJSEngine secondEngine; + QJSValue value = firstEngine.evaluate("1"); + result = secondEngine.evaluate("1 + " + QString::number(value.toInteger())).toInteger(); + } +}; + +void tst_QJSEngine::threadedEngine() +{ + ThreadedTestEngine thread1; + ThreadedTestEngine thread2; + thread1.start(); + thread2.start(); + thread1.wait(); + thread2.wait(); + QCOMPARE(thread1.result, 2); + QCOMPARE(thread2.result, 2); +} + QTEST_MAIN(tst_QJSEngine) #include "tst_qjsengine.moc" |