diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2009-11-30 13:15:50 (GMT) |
---|---|---|
committer | Kent Hansen <kent.hansen@nokia.com> | 2009-11-30 14:53:12 (GMT) |
commit | 132eccca92a90e4d67ba8b5a4052384a2b2cfdf9 (patch) | |
tree | cff488b3d812dcb077771aafd51be979797c63fa /tests/auto | |
parent | 634a2c456732903b116a73e674f1391f77d530d8 (diff) | |
download | Qt-132eccca92a90e4d67ba8b5a4052384a2b2cfdf9.zip Qt-132eccca92a90e4d67ba8b5a4052384a2b2cfdf9.tar.gz Qt-132eccca92a90e4d67ba8b5a4052384a2b2cfdf9.tar.bz2 |
Fix garbage collection issue with script-owned objects with connections
This reinstates the pre-4.6 behavior: A script-owned C++ object
that's not referenced anymore should be garbage collected, even
if it has connections. In order to achieve this, the "weak"
reference to the C++ object's wrapper must be invalidated.
Task-number: QTBUG-6366
Reviewed-by: Simon Hausmann
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qscriptengine/tst_qscriptengine.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp index 3bc2443..2d629b7 100644 --- a/tests/auto/qscriptengine/tst_qscriptengine.cpp +++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp @@ -154,6 +154,7 @@ private slots: void functionScopes(); void nativeFunctionScopes(); void evaluateProgram(); + void collectGarbageAfterConnect(); void qRegExpInport_data(); void qRegExpInport(); @@ -4443,6 +4444,23 @@ void tst_QScriptEngine::evaluateProgram() } } +void tst_QScriptEngine::collectGarbageAfterConnect() +{ + // QTBUG-6366 + QScriptEngine engine; + QPointer<QWidget> widget = new QWidget; + engine.globalObject().setProperty( + "widget", engine.newQObject(widget, QScriptEngine::ScriptOwnership)); + QVERIFY(engine.evaluate("widget.customContextMenuRequested.connect(\n" + " function() { print('hello'); }\n" + ");") + .isUndefined()); + QVERIFY(widget != 0); + engine.evaluate("widget = null;"); + collectGarbage_helper(engine); + QVERIFY(widget == 0); +} + static QRegExp minimal(QRegExp r) { r.setMinimal(true); return r; } void tst_QScriptEngine::qRegExpInport_data() |