diff options
author | Chris Adams <christopher.adams@nokia.com> | 2011-08-22 15:04:01 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-09-30 10:37:05 +0200 |
commit | 5d62a90fe129b09ecc6526ccd815469ef4ff774d (patch) | |
tree | b09d2e2f6bcb07fbb07aefbddbc0a58fbb4bc096 /tests/auto/declarative/qdeclarativeecmascript/testtypes.h | |
parent | bc2f2c56296a77b215ccdf2ee907ef669e6ab609 (diff) |
Ensure JS-owned QObjects are cleaned up on v8engine dtor
This commit ensures that the garbage collector is invoked during
engine destruction. This commit also adds a unit test which
ensures that the JS GC destroys JS-owned C++ objects correctly
when the QDeclarativeEngine is destroyed.
Task-number: QTBUG-20377
Change-Id: I2de1f2dfd1e60cc2f76abb523b99bf169d2a5a13
Reviewed-on: http://codereview.qt-project.org/3285
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
Diffstat (limited to 'tests/auto/declarative/qdeclarativeecmascript/testtypes.h')
-rw-r--r-- | tests/auto/declarative/qdeclarativeecmascript/testtypes.h | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h index ebe8cc59b7..3fd6eaf02d 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h +++ b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h @@ -1072,6 +1072,47 @@ private: }; Q_DECLARE_METATYPE(CircularReferenceHandle*) +class MyDynamicCreationDestructionObject : public QObject +{ + Q_OBJECT + Q_PROPERTY (int intProperty READ intProperty WRITE setIntProperty NOTIFY intPropertyChanged) + +public: + MyDynamicCreationDestructionObject(QObject *parent = 0) : QObject(parent), m_intProperty(0), m_dtorCount(0) + { + } + + ~MyDynamicCreationDestructionObject() + { + if (m_dtorCount) { + (*m_dtorCount)++; + } + } + + int intProperty() const { return m_intProperty; } + void setIntProperty(int val) { m_intProperty = val; emit intPropertyChanged(); } + + Q_INVOKABLE MyDynamicCreationDestructionObject *createNew() + { + // no parent == ownership transfers to JS; same dtor counter. + MyDynamicCreationDestructionObject *retn = new MyDynamicCreationDestructionObject; + retn->setDtorCount(m_dtorCount); + return retn; + } + + void setDtorCount(int *dtorCount) + { + m_dtorCount = dtorCount; + } + +signals: + void intPropertyChanged(); + +private: + int m_intProperty; + int *m_dtorCount; +}; + void registerTypes(); #endif // TESTTYPES_H |