diff options
author | Lars Knoll <lars.knoll@digia.com> | 2013-05-06 12:43:39 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2013-05-06 15:53:54 +0200 |
commit | 5694ac5bbed19b4a427a29fcd9bcacba480165c1 (patch) | |
tree | da0eb3dd87b1bb2d3ea3adfb60e57d4c14f13b7a /src/qml/qml | |
parent | 9a8dad0fcb2c3f6c7cf6fe1e8b38a18e1d90fd90 (diff) |
Convert QQmlPropertyCache to use QV4::persistentValue instead of the v8 version
The V4 persistent values are safer to use, as the v8 ones never
implemented proper semantics when the engine gets deleted.
Change-Id: I787f8c01c70828f22ac60f0ac25201cdfa5a617f
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/qml')
-rw-r--r-- | src/qml/qml/qqmlpropertycache.cpp | 7 | ||||
-rw-r--r-- | src/qml/qml/qqmlpropertycache_p.h | 4 | ||||
-rw-r--r-- | src/qml/qml/v4/qv4functionobject.cpp | 5 | ||||
-rw-r--r-- | src/qml/qml/v4/qv4functionobject_p.h | 2 | ||||
-rw-r--r-- | src/qml/qml/v4/qv4mm.cpp | 3 | ||||
-rw-r--r-- | src/qml/qml/v4/qv4value_p.h | 2 | ||||
-rw-r--r-- | src/qml/qml/v8/qv8qobjectwrapper.cpp | 10 |
7 files changed, 21 insertions, 12 deletions
diff --git a/src/qml/qml/qqmlpropertycache.cpp b/src/qml/qml/qqmlpropertycache.cpp index dee534dc69..c2ad069391 100644 --- a/src/qml/qml/qqmlpropertycache.cpp +++ b/src/qml/qml/qqmlpropertycache.cpp @@ -290,8 +290,8 @@ QQmlPropertyCache::~QQmlPropertyCache() void QQmlPropertyCache::destroy() { - Q_ASSERT(engine || constructor.IsEmpty()); - if (constructor.IsEmpty()) + Q_ASSERT(engine || constructor->isDeleted()); + if (constructor->isDeleted()) delete this; else QQmlEnginePrivate::deleteInEngineThread(engine, this); @@ -301,7 +301,6 @@ void QQmlPropertyCache::destroy() // that are tied to the specific QQmlEngine. void QQmlPropertyCache::clear() { - qPersistentDispose(constructor); engine = 0; } @@ -599,7 +598,7 @@ void QQmlPropertyCache::append(QQmlEngine *engine, const QMetaObject *metaObject QQmlPropertyData::Flag signalFlags) { Q_UNUSED(revision); - Q_ASSERT(constructor.IsEmpty()); // We should not be appending to an in-use property cache + Q_ASSERT(constructor->isDeleted()); // We should not be appending to an in-use property cache _metaObject = metaObject; diff --git a/src/qml/qml/qqmlpropertycache_p.h b/src/qml/qml/qqmlpropertycache_p.h index 960f3e55d8..c1c7cc236f 100644 --- a/src/qml/qml/qqmlpropertycache_p.h +++ b/src/qml/qml/qqmlpropertycache_p.h @@ -62,6 +62,8 @@ #include <QtCore/qvarlengtharray.h> #include <QtCore/qvector.h> +#include <private/qv4value_p.h> + QT_BEGIN_NAMESPACE class QV8Engine; @@ -390,7 +392,7 @@ private: IndexCache signalHandlerIndexCache; StringCache stringCache; AllowedRevisionCache allowedRevisionCache; - v8::Persistent<v8::Function> constructor; + QV4::PersistentValue constructor; bool _hasPropertyOverrides : 1; bool _ownMetaObject : 1; diff --git a/src/qml/qml/v4/qv4functionobject.cpp b/src/qml/qml/v4/qv4functionobject.cpp index 7e889a36ed..38284a36c8 100644 --- a/src/qml/qml/v4/qv4functionobject.cpp +++ b/src/qml/qml/v4/qv4functionobject.cpp @@ -111,6 +111,11 @@ FunctionObject::FunctionObject(ExecutionContext *scope, String *name) defineReadonlyProperty(scope->engine->id_name, Value::fromString(name)); } +Value FunctionObject::newInstance() +{ + return construct(internalClass->engine->current, 0, 0); +} + bool FunctionObject::hasInstance(Managed *that, ExecutionContext *ctx, const Value &value) { FunctionObject *f = static_cast<FunctionObject *>(that); diff --git a/src/qml/qml/v4/qv4functionobject_p.h b/src/qml/qml/v4/qv4functionobject_p.h index 50382a3ede..315f3dc3d9 100644 --- a/src/qml/qml/v4/qv4functionobject_p.h +++ b/src/qml/qml/v4/qv4functionobject_p.h @@ -157,6 +157,8 @@ struct Q_QML_EXPORT FunctionObject: Object { FunctionObject(ExecutionContext *scope, String *name = 0); + Value newInstance(); + static Value construct(Managed *that, ExecutionContext *context, Value *args, int argc); static Value call(Managed *that, ExecutionContext *, const Value &, Value *, int); inline Value construct(ExecutionContext *context, Value *args, int argc) { diff --git a/src/qml/qml/v4/qv4mm.cpp b/src/qml/qml/v4/qv4mm.cpp index b59100dd28..f71f7a8c99 100644 --- a/src/qml/qml/v4/qv4mm.cpp +++ b/src/qml/qml/v4/qv4mm.cpp @@ -399,8 +399,7 @@ MemoryManager::~MemoryManager() { PersistentValuePrivate *persistent = m_persistentValues; while (persistent) { - if (Managed *m = persistent->value.asManaged()) - persistent->value = Value::deletedValue(); + persistent->value = Value::deletedValue(); PersistentValuePrivate *n = persistent->next; persistent->next = 0; persistent = n; diff --git a/src/qml/qml/v4/qv4value_p.h b/src/qml/qml/v4/qv4value_p.h index fb6393588c..29fc68b5e5 100644 --- a/src/qml/qml/v4/qv4value_p.h +++ b/src/qml/qml/v4/qv4value_p.h @@ -552,7 +552,7 @@ inline Value Managed::call(ExecutionContext *context, const Value &thisObject, V struct PersistentValuePrivate { PersistentValuePrivate() - : value(Value::undefinedValue()) + : value(Value::deletedValue()) , refcount(1) , next(0) {} diff --git a/src/qml/qml/v8/qv8qobjectwrapper.cpp b/src/qml/qml/v8/qv8qobjectwrapper.cpp index e863747c92..e7f87ade35 100644 --- a/src/qml/qml/v8/qv8qobjectwrapper.cpp +++ b/src/qml/qml/v8/qv8qobjectwrapper.cpp @@ -53,6 +53,8 @@ #include <private/qqmlexpression_p.h> #include <private/qqmlglobal_p.h> +#include <private/qv4functionobject_p.h> + #include <QtQml/qjsvalue.h> #include <QtCore/qjsonarray.h> #include <QtCore/qjsonobject.h> @@ -959,7 +961,7 @@ v8::Local<v8::Object> QQmlPropertyCache::newQObject(QObject *object, QV8Engine * Q_ASSERT(QQmlData::get(object, false)->propertyCache == this); // Setup constructor - if (constructor.IsEmpty()) { + if (constructor->isDeleted()) { v8::Local<v8::FunctionTemplate> ft; const QHashedString toString(QStringLiteral("toString")); @@ -1034,7 +1036,7 @@ v8::Local<v8::Object> QQmlPropertyCache::newQObject(QObject *object, QV8Engine * } if (ft.IsEmpty()) { - constructor = qPersistentNew<v8::Function>(engine->qobjectWrapper()->m_constructor); + constructor = engine->qobjectWrapper()->m_constructor->v4Value(); } else { ft->InstanceTemplate()->SetFallbackPropertyHandler(QV8QObjectWrapper::Getter, QV8QObjectWrapper::Setter, @@ -1042,13 +1044,13 @@ v8::Local<v8::Object> QQmlPropertyCache::newQObject(QObject *object, QV8Engine * 0, QV8QObjectWrapper::Enumerator); ft->InstanceTemplate()->SetHasExternalResource(true); - constructor = qPersistentNew<v8::Function>(ft->GetFunction()); + constructor = ft->GetFunction()->v4Value(); } QQmlCleanup::addToEngine(this->engine); } - v8::Local<v8::Object> result = constructor->NewInstance(); + v8::Local<v8::Object> result = v8::Local<v8::Object>::New(constructor->asFunctionObject()->newInstance()); QV8QObjectResource *r = new QV8QObjectResource(engine, object); result->SetExternalResource(r); return result; |