aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp')
-rw-r--r--tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp b/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp
index 5dfbd2e522..783b5cb786 100644
--- a/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp
+++ b/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp
@@ -33,6 +33,8 @@
#include <QQmlComponent>
#include <QQmlExpression>
#include <private/qqmlcontext_p.h>
+#include <private/qv4qmlcontext_p.h>
+#include <private/qv4object_p.h>
#include "../../shared/util.h"
class tst_qqmlcontext : public QQmlDataTest
@@ -64,6 +66,7 @@ private slots:
void qobjectDerived();
void qtbug_49232();
void contextViaClosureAfterDestruction();
+ void contextLeak();
private:
QQmlEngine engine;
@@ -778,6 +781,40 @@ void tst_qqmlcontext::contextViaClosureAfterDestruction()
QCOMPARE(subObject.toString(), QLatin1String("Error: Qt.createQmlObject(): Cannot create a component in an invalid context"));
}
+void tst_qqmlcontext::contextLeak()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl("contextLeak.qml"));
+
+ QQmlGuardedContextData scriptContext;
+
+ {
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY(!obj.isNull());
+ QCOMPARE(obj->property("value").toInt(), 42);
+
+ QQmlData *ddata = QQmlData::get(obj.data());
+ QVERIFY(ddata);
+ QQmlContextData *context = ddata->context;
+ QVERIFY(context);
+ QVERIFY(!context->importedScripts.isNullOrUndefined());
+ QCOMPARE(int(context->importedScripts.valueRef()->as<QV4::Object>()->getLength()), 1);
+
+ {
+ QV4::Scope scope(ddata->jsWrapper.engine());
+ QV4::ScopedValue scriptContextWrapper(scope);
+ scriptContextWrapper = context->importedScripts.valueRef()->as<QV4::Object>()->getIndexed(0);
+ scriptContext = scriptContextWrapper->as<QV4::QQmlContextWrapper>()->getContext();
+ }
+ }
+
+ engine.collectGarbage();
+
+ // Each time a JS file (non-pragma-shared) is imported, we create a QQmlContext(Data) for it.
+ // Make sure that context does not leak.
+ QVERIFY(scriptContext.isNull());
+}
+
QTEST_MAIN(tst_qqmlcontext)
#include "tst_qqmlcontext.moc"