From c18e04b2e61f174a4883f6884cf9a0712c5725e3 Mon Sep 17 00:00:00 2001 From: Philip Lorenz Date: Sat, 1 Dec 2012 12:58:39 +0100 Subject: 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 --- .../auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'tests/auto/qml') 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 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 qmlglobal, ctxt->importedScripts) { + QQmlContextData *scriptContext, *newContext; + + if (qmlglobal.IsEmpty()) + continue; + + scriptContext = engine->contextWrapper()->context(qmlglobal); + + { + v8::HandleScope handle_scope; + v8::Persistent context = v8::Context::New(); + v8::Context::Scope context_scope(context); + v8::Local 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("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; -- cgit v1.2.3