From d5f3186bdcad470b7685bfd806acde51b71b152d Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Tue, 4 Jun 2013 12:02:29 +0200 Subject: [PATCH] Move internal QV8QObjectWrapper::newQObject helper to QV4::QObjectWrapper Change-Id: Ieb1a36ce240b894d19c410b94eccfa79150054c7 Reviewed-by: Lars Knoll --- src/qml/qml/v8/qv8qobjectwrapper.cpp | 34 ++++++++++++++++------------------ src/qml/qml/v8/qv8qobjectwrapper_p.h | 7 +++++-- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/qml/qml/v8/qv8qobjectwrapper.cpp b/src/qml/qml/v8/qv8qobjectwrapper.cpp index 9c76ba0..90c903b 100644 --- a/src/qml/qml/v8/qv8qobjectwrapper.cpp +++ b/src/qml/qml/v8/qv8qobjectwrapper.cpp @@ -176,6 +176,17 @@ Value QObjectWrapper::getQmlProperty(ExecutionContext *ctx, String *name, QObjec return QV4::Object::get(this, ctx, name, hasProperty); } +QV4::Value QObjectWrapper::wrap(ExecutionEngine *engine, QQmlData *ddata, QObject *object) +{ + QQmlEngine *qmlEngine = qobject_cast(engine->publicEngine); + if (!ddata->propertyCache && qmlEngine) { + ddata->propertyCache = QQmlEnginePrivate::get(qmlEngine)->cache(object); + if (ddata->propertyCache) ddata->propertyCache->addref(); + } + + return Value::fromObject(new (engine->memoryManager) QV4::QObjectWrapper(engine, object)); +} + QV4::Value QObjectWrapper::get(Managed *m, ExecutionContext *ctx, String *name, bool *hasProperty) { QObjectWrapper *that = static_cast(m); @@ -780,18 +791,6 @@ static void FastValueSetterReadOnly(v8::Handle property, v8::Handle< v8::ThrowException(v8::Exception::Error(v8engine->toString(error))); } -v8::Handle QV8QObjectWrapper::newQObject(QObject *object, QQmlData *ddata, QV8Engine *engine) -{ - if (!ddata->propertyCache && engine->engine()) { - ddata->propertyCache = QQmlEnginePrivate::get(engine->engine())->cache(object); - if (ddata->propertyCache) ddata->propertyCache->addref(); - } - - QV4::ExecutionEngine *v4 = QV8Engine::getV4(engine); - QV4::QObjectWrapper *wrapper = new (v4->memoryManager) QV4::QObjectWrapper(v4, object); - return QV4::Value::fromObject(wrapper); -} - /* As V8 doesn't support an equality callback, for QObject's we have to return exactly the same V8 handle for subsequent calls to newQObject for the same QObject. To do this we have a two @@ -826,8 +825,8 @@ v8::Handle QV8QObjectWrapper::newQObject(QObject *object) ddata->jsEngineId == 0 || // No one owns the QObject !ddata->hasTaintedV8Object)) { // Someone else has used the QObject, but it isn't tainted - v8::Handle rv = newQObject(object, ddata, m_engine); - ddata->jsWrapper = rv->v4Value(); + QV4::Value rv = QV4::QObjectWrapper::wrap(v4, ddata, object); + ddata->jsWrapper = rv; ddata->jsEngineId = v4->m_engineId; return rv; @@ -841,8 +840,8 @@ v8::Handle QV8QObjectWrapper::newQObject(QObject *object) // If our tainted handle doesn't exist or has been collected, and there isn't // a handle in the ddata, we can assume ownership of the ddata->v8object if ((!found || (*iter)->jsWrapper.isEmpty()) && ddata->jsWrapper.isEmpty()) { - v8::Handle rv = newQObject(object, ddata, m_engine); - ddata->jsWrapper = rv->v4Value(); + QV4::Value rv = QV4::QObjectWrapper::wrap(v4, ddata, object); + ddata->jsWrapper = rv; ddata->jsEngineId = v4->m_engineId; if (found) { @@ -858,8 +857,7 @@ v8::Handle QV8QObjectWrapper::newQObject(QObject *object) } if ((*iter)->jsWrapper.isEmpty()) { - v8::Handle rv = newQObject(object, ddata, m_engine); - (*iter)->jsWrapper = rv->v4Value(); + (*iter)->jsWrapper = QV4::QObjectWrapper::wrap(v4, ddata, object); } return (*iter)->jsWrapper.value(); diff --git a/src/qml/qml/v8/qv8qobjectwrapper_p.h b/src/qml/qml/v8/qv8qobjectwrapper_p.h index 5862a18..78db659 100644 --- a/src/qml/qml/v8/qv8qobjectwrapper_p.h +++ b/src/qml/qml/v8/qv8qobjectwrapper_p.h @@ -85,7 +85,6 @@ struct Q_QML_EXPORT QObjectWrapper : public QV4::Object enum RevisionMode { IgnoreRevision, CheckRevision }; - QObjectWrapper(ExecutionEngine *v8Engine, QObject *object); ~QObjectWrapper(); QV8Engine *v8Engine; // ### Remove again. @@ -96,7 +95,12 @@ struct Q_QML_EXPORT QObjectWrapper : public QV4::Object Value getQmlProperty(ExecutionContext *ctx, String *name, RevisionMode revisionMode, bool *hasProperty = 0, bool includeImports = false); + // ### Make private when QV8QObjectWrapper is gone. + static Value wrap(ExecutionEngine *engine, QQmlData *ddata, QObject *object); + private: + QObjectWrapper(ExecutionEngine *v8Engine, QObject *object); + QQmlGuard m_object; String *m_destroy; String *m_toString; @@ -185,7 +189,6 @@ private: friend class QV8QObjectInstance; friend struct QV4::QObjectWrapper; - v8::Handle newQObject(QObject *, QQmlData *, QV8Engine *); static QV4::Value GetProperty(QV8Engine *, QObject *, const QHashedV4String &, QQmlContextData *, QV4::QObjectWrapper::RevisionMode); static bool SetProperty(QV8Engine *, QObject *, const QHashedV4String &, QQmlContextData *, -- 2.7.4