/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
**
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
**
**
**
+**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qv8variantwrapper_p.h"
+#include "qv8variantresource_p.h"
#include "qv8engine_p.h"
#include <private/qdeclarativeengine_p.h>
QT_BEGIN_NAMESPACE
-class QV8VariantResource : public QV8ObjectResource,
- public QDeclarativeEnginePrivate::ScarceResourceData
+QV8VariantResource::QV8VariantResource(QV8Engine *engine, const QVariant &data)
+: QV8ObjectResource(engine), QDeclarativeEnginePrivate::ScarceResourceData(data), m_isScarceResource(false), m_vmePropertyReferenceCount(0)
{
- V8_RESOURCE_TYPE(VariantType);
-public:
- QV8VariantResource(QV8Engine *engine, const QVariant &data);
-};
+}
-QV8VariantResource::QV8VariantResource(QV8Engine *engine, const QVariant &data)
-: QV8ObjectResource(engine), QDeclarativeEnginePrivate::ScarceResourceData(data)
+void QV8VariantResource::addVmePropertyReference()
{
+ if (m_isScarceResource && ++m_vmePropertyReferenceCount == 1) {
+ // remove from the ep->scarceResources list
+ // since it is now no longer eligible to be
+ // released automatically by the engine.
+ node.remove();
+ }
+}
+
+void QV8VariantResource::removeVmePropertyReference()
+{
+ if (m_isScarceResource && --m_vmePropertyReferenceCount == 0) {
+ // and add to the ep->scarceResources list
+ // since it is now eligible to be released
+ // automatically by the engine.
+ QDeclarativeEnginePrivate::get(engine->engine())->scarceResources.insert(this);
+ }
}
QV8VariantWrapper::QV8VariantWrapper()
QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(m_engine->engine());
Q_ASSERT(ep->scarceResourcesRefCount);
rv = m_scarceConstructor->NewInstance();
+ r->m_isScarceResource = true;
ep->scarceResources.insert(r);
} else {
rv = m_constructor->NewInstance();