summaryrefslogtreecommitdiffstats
path: root/tests/auto/qscriptengine
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2010-03-29 15:36:02 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2010-03-29 17:14:59 (GMT)
commit3e5745ea75d73869918889cb374c3d651bed0991 (patch)
treea67c644259d542131353a3ed68f83b32d3d3fb1c /tests/auto/qscriptengine
parent9e3304246acf5b58a2ce86eed082784da818a8f0 (diff)
downloadQt-3e5745ea75d73869918889cb374c3d651bed0991.zip
Qt-3e5745ea75d73869918889cb374c3d651bed0991.tar.gz
Qt-3e5745ea75d73869918889cb374c3d651bed0991.tar.bz2
QScriptEngine: Fix reentrency involving creation and desctructions of QScriptEngines
the currentIdentifierTable table, which is a static thread local variable, could be corrupted. The main change is to fix the QScriptEngine constructor not to alter the currentIdentifierTable This showed a lot of cases where APIShim guards where missings. The problem was seen with creator, related to QTBUG-9426 Reviewed-by: Jedrzej Nowacki
Diffstat (limited to 'tests/auto/qscriptengine')
-rw-r--r--tests/auto/qscriptengine/tst_qscriptengine.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp
index 0615b63..3c6c7b2 100644
--- a/tests/auto/qscriptengine/tst_qscriptengine.cpp
+++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp
@@ -161,6 +161,7 @@ private slots:
void qRegExpInport_data();
void qRegExpInport();
+ void reentrency();
};
tst_QScriptEngine::tst_QScriptEngine()
@@ -4577,5 +4578,25 @@ void tst_QScriptEngine::qRegExpInport()
}
}
+static QScriptValue createAnotherEngine(QScriptContext *, QScriptEngine *)
+{
+ QScriptEngine eng;
+ eng.evaluate("function foo(x, y) { return x + y; }" );
+ eng.evaluate("hello = 5; world = 6" );
+ return eng.evaluate("foo(hello,world)").toInt32();
+}
+
+
+void tst_QScriptEngine::reentrency()
+{
+ QScriptEngine eng;
+ eng.globalObject().setProperty("foo", eng.newFunction(createAnotherEngine));
+ eng.evaluate("function bar() { return foo(); } hello = 9; function getHello() { return hello; }");
+ QCOMPARE(eng.evaluate("foo() + getHello() + foo()").toInt32(), 5+6 + 9 + 5+6);
+ QCOMPARE(eng.evaluate("foo").call().toInt32(), 5+6);
+ QCOMPARE(eng.evaluate("hello").toInt32(), 9);
+ QCOMPARE(eng.evaluate("foo() + hello").toInt32(), 5+6+9);
+}
+
QTEST_MAIN(tst_QScriptEngine)
#include "tst_qscriptengine.moc"