aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
diff options
context:
space:
mode:
authorPhilip Lorenz <philip@bithub.de>2012-12-01 12:58:39 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-12-10 18:09:27 +0100
commitc18e04b2e61f174a4883f6884cf9a0712c5725e3 (patch)
tree1be41c4bd81b01519b0cf3d54fcbd17a10842fc7 /tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
parent22924ac4fe1962022ec12f40c66bf5cb988515b3 (diff)
Only free context if the owning QV8ContextResource gets destroyed
Since fdeee38b781376012c4f086276c3c376726c8839 QQmlXMLHttpRequest stores the calling context for later use. This leads to issues after the first request completes and the wrapping QV8ContextResource gets freed by garbage collection and therefore removes the associated QQmlDataContext which may still be required for later calls (e.g. if the calling context is part of a stateless library). This patch introduces an ownership flag for QV8ContextResource which indicates if the associated context should be cleared when the object is destroyed. Task-number: QTBUG-28351 Change-Id: I552ebb5c55b889eb33f3884283c8fdf037ac33be Reviewed-by: Alan Alpert <aalpert@rim.com>
Diffstat (limited to 'tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp')
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index a99c5fa8be..048fdb1e16 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -288,6 +288,7 @@ private slots:
private:
static void propertyVarWeakRefCallback(v8::Persistent<v8::Value> object, void* parameter);
+ static void verifyContextLifetime(QQmlContextData *ctxt);
QQmlEngine engine;
};
@@ -3783,6 +3784,41 @@ void tst_qqmlecmascript::singletonTypeResolution()
delete object;
}
+void tst_qqmlecmascript::verifyContextLifetime(QQmlContextData *ctxt) {
+ QQmlContextData *childCtxt = ctxt->childContexts;
+
+ if (!ctxt->importedScripts.isEmpty()) {
+ QV8Engine *engine = QV8Engine::get(ctxt->engine);
+ foreach (v8::Persistent<v8::Object> qmlglobal, ctxt->importedScripts) {
+ QQmlContextData *scriptContext, *newContext;
+
+ if (qmlglobal.IsEmpty())
+ continue;
+
+ scriptContext = engine->contextWrapper()->context(qmlglobal);
+
+ {
+ v8::HandleScope handle_scope;
+ v8::Persistent<v8::Context> context = v8::Context::New();
+ v8::Context::Scope context_scope(context);
+ v8::Local<v8::Object> temporaryScope = engine->qmlScope(scriptContext, NULL);
+
+ context.Dispose();
+ }
+
+ QV8Engine::gc();
+ newContext = engine->contextWrapper()->context(qmlglobal);
+ QVERIFY(scriptContext == newContext);
+ }
+ }
+
+ while (childCtxt) {
+ verifyContextLifetime(childCtxt);
+
+ childCtxt = childCtxt->nextChild;
+ }
+}
+
void tst_qqmlecmascript::importScripts_data()
{
QTest::addColumn<QUrl>("testfile");
@@ -4014,6 +4050,10 @@ void tst_qqmlecmascript::importScripts()
QVERIFY(object == 0);
} else {
QVERIFY(object != 0);
+
+ QQmlContextData *ctxt = QQmlContextData::get(engine.rootContext());
+ tst_qqmlecmascript::verifyContextLifetime(ctxt);
+
for (int i = 0; i < propertyNames.size(); ++i)
QCOMPARE(object->property(propertyNames.at(i).toLatin1().constData()), propertyValues.at(i));
delete object;