diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2011-06-08 14:32:39 +1000 |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2011-06-08 14:32:39 +1000 |
commit | 8902609a7e6cc27fceff15aa80547f1137efd7c9 (patch) | |
tree | 5cceabf2176d66260a4e6a600fbdf7c8f4002c80 /src/declarative/qml/v8/qv8engine_p.h | |
parent | 96cfe77fa311e60a2dfb7967d7ad6c06d40b99fb (diff) |
Implement global handle tracking
This makes it easier to track down handles that have been double
Dispose()'d. See qv8engine_p.h for details.
Diffstat (limited to 'src/declarative/qml/v8/qv8engine_p.h')
-rw-r--r-- | src/declarative/qml/v8/qv8engine_p.h | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/declarative/qml/v8/qv8engine_p.h b/src/declarative/qml/v8/qv8engine_p.h index 5810b3e604..ee0b9115a3 100644 --- a/src/declarative/qml/v8/qv8engine_p.h +++ b/src/declarative/qml/v8/qv8engine_p.h @@ -70,6 +70,13 @@ QT_BEGIN_NAMESPACE + +// Uncomment the following line to enable global handle debugging. When enabled, all the persistent +// handles allocated using qPersistentNew() (or registered with qPersistentRegsiter()) and disposed +// with qPersistentDispose() are tracked. If you try and do something illegal, like double disposing +// a handle, qFatal() is called. +// #define QML_GLOBAL_HANDLE_DEBUGGING + #define V8_RESOURCE_TYPE(resourcetype) \ public: \ enum { V8ResourceType = QV8ObjectResource:: resourcetype }; \ @@ -240,6 +247,12 @@ public: static void gc(); +#ifdef QML_GLOBAL_HANDLE_DEBUGGING + // Used for handle debugging + static void registerHandle(void *); + static void releaseHandle(void *); +#endif + private: QDeclarativeEngine *m_engine; v8::Persistent<v8::Context> m_context; @@ -294,6 +307,42 @@ private: QDateTime qtDateTimeFromJsDate(double jsDate); }; +// Allocate a new Persistent handle. *ALL* persistent handles in QML must be allocated +// using this method. +template<class T> +v8::Persistent<T> qPersistentNew(v8::Handle<T> that) +{ + v8::Persistent<T> rv = v8::Persistent<T>::New(that); +#ifdef QML_GLOBAL_HANDLE_DEBUGGING + QV8Engine::registerHandle(*rv); +#endif + return rv; +} + +// Register a Persistent handle that was returned to you by V8 (such as by +// v8::Context::New). This allows us to do handle tracking on these handles too. +template<class T> +void qPersistentRegister(v8::Persistent<T> handle) +{ +#ifdef QML_GLOBAL_HANDLE_DEBUGGING + QV8Engine::registerHandle(*handle); +#else + Q_UNUSED(handle); +#endif +} + +// Dispose and clear a persistent handle. *ALL* persistent handles in QML must be +// disposed using this method. +template<class T> +void qPersistentDispose(v8::Persistent<T> &that) +{ +#ifdef QML_GLOBAL_HANDLE_DEBUGGING + QV8Engine::releaseHandle(*that); +#endif + that.Dispose(); + that.Clear(); +} + QString QV8Engine::toString(v8::Handle<v8::Value> string) { return m_stringWrapper.toString(string->ToString()); |