diff options
author | Lars Knoll <lars.knoll@digia.com> | 2013-05-30 22:09:46 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2013-05-31 07:05:33 +0200 |
commit | c9e178e4f202ff4d32248682ed5e2cf5de75d0f8 (patch) | |
tree | 1bbb46a8a9b8b7aa48d2d81564a6e5c93ee952d0 /src/qml/qml | |
parent | 80ec004e7c6411997e2476a2f2c9c9f4fb41217a (diff) |
Port the list wrapper over to v4
Also fix two places where we did a wrong type check.
Change-Id: Ibc988b1b38803ca6acf6914487415026910f744e
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/qml')
-rw-r--r-- | src/qml/qml/qml.pri | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmlcontextwrapper.cpp | 7 | ||||
-rw-r--r-- | src/qml/qml/qqmllistwrapper.cpp | 162 | ||||
-rw-r--r-- | src/qml/qml/qqmllistwrapper_p.h (renamed from src/qml/qml/v8/qv8listwrapper_p.h) | 56 | ||||
-rw-r--r-- | src/qml/qml/qqmltypewrapper.cpp | 3 | ||||
-rw-r--r-- | src/qml/qml/qqmlvaluetypewrapper.cpp | 1 | ||||
-rw-r--r-- | src/qml/qml/v4/qv4managed_p.h | 5 | ||||
-rw-r--r-- | src/qml/qml/v8/qv8engine.cpp | 9 | ||||
-rw-r--r-- | src/qml/qml/v8/qv8engine_p.h | 3 | ||||
-rw-r--r-- | src/qml/qml/v8/qv8listwrapper.cpp | 195 | ||||
-rw-r--r-- | src/qml/qml/v8/qv8objectresource_p.h | 3 | ||||
-rw-r--r-- | src/qml/qml/v8/qv8qobjectwrapper.cpp | 3 | ||||
-rw-r--r-- | src/qml/qml/v8/v8.pri | 2 |
13 files changed, 209 insertions, 242 deletions
diff --git a/src/qml/qml/qml.pri b/src/qml/qml/qml.pri index bae783105d..663cf2a609 100644 --- a/src/qml/qml/qml.pri +++ b/src/qml/qml/qml.pri @@ -52,6 +52,7 @@ SOURCES += \ $$PWD/qqmlplatform.cpp \ $$PWD/qqmlbinding.cpp \ $$PWD/qqmlapplicationengine.cpp \ + $$PWD/qqmllistwrapper.cpp \ $$PWD/qqmlcontextwrapper.cpp \ $$PWD/qqmlvaluetypewrapper.cpp \ $$PWD/qqmltypewrapper.cpp @@ -128,6 +129,7 @@ HEADERS += \ $$PWD/qqmlextensionplugin_p.h \ $$PWD/qqmlapplicationengine_p.h \ $$PWD/qqmlapplicationengine.h \ + $$PWD/qqmllistwrapper_p.h \ $$PWD/qqmlcontextwrapper_p.h \ $$PWD/qqmlvaluetypewrapper_p.h \ $$PWD/qqmltypewrapper_p.h diff --git a/src/qml/qml/qqmlcontextwrapper.cpp b/src/qml/qml/qqmlcontextwrapper.cpp index 493d55a30f..b7a236b2b8 100644 --- a/src/qml/qml/qqmlcontextwrapper.cpp +++ b/src/qml/qml/qqmlcontextwrapper.cpp @@ -51,6 +51,7 @@ #include <private/qv4objectproto_p.h> #include <private/qv4mm_p.h> #include <private/qqmltypewrapper_p.h> +#include <private/qqmllistwrapper_p.h> QT_BEGIN_NAMESPACE @@ -148,7 +149,7 @@ void QmlContextWrapper::takeContextOwnership(const Value &qmlglobal) Value QmlContextWrapper::get(Managed *m, ExecutionContext *ctx, String *name, bool *hasProperty) { QmlContextWrapper *resource = m->asQmlContext(); - if (!m) + if (!resource) ctx->throwTypeError(); bool hasProp; @@ -238,7 +239,7 @@ Value QmlContextWrapper::get(Managed *m, ExecutionContext *ctx, String *name, bo QQmlListProperty<QObject> prop(context->asQQmlContext(), (void*) qintptr(propertyIdx), QQmlContextPrivate::context_count, QQmlContextPrivate::context_at); - return engine->listWrapper()->newList(prop, qMetaTypeId<QQmlListProperty<QObject> >())->v4Value(); + return QmlListWrapper::create(engine, prop, qMetaTypeId<QQmlListProperty<QObject> >()); } else { return engine->fromVariant(cp->propertyValues.at(propertyIdx)); } @@ -284,7 +285,7 @@ Value QmlContextWrapper::get(Managed *m, ExecutionContext *ctx, String *name, bo void QmlContextWrapper::put(Managed *m, ExecutionContext *ctx, String *name, const Value &value) { QmlContextWrapper *wrapper = m->asQmlContext(); - if (!m) + if (!wrapper) ctx->throwTypeError(); PropertyAttributes attrs; diff --git a/src/qml/qml/qqmllistwrapper.cpp b/src/qml/qml/qqmllistwrapper.cpp new file mode 100644 index 0000000000..ff878c0d9c --- /dev/null +++ b/src/qml/qml/qqmllistwrapper.cpp @@ -0,0 +1,162 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qqmllistwrapper_p.h" +#include <private/qv8engine_p.h> +#include <private/qqmllist_p.h> + +#include <private/qv4functionobject_p.h> + +QT_BEGIN_NAMESPACE + +using namespace QV4; + +DEFINE_MANAGED_VTABLE(QmlListWrapper); + +QmlListWrapper::QmlListWrapper(QV8Engine *engine) + : Object(QV8Engine::getV4(engine)), + v8(engine) +{ + type = Type_QmlListWrapper; + vtbl = &static_vtbl; +} + +QmlListWrapper::~QmlListWrapper() +{ +} + +Value QmlListWrapper::create(QV8Engine *v8, QObject *object, int propId, int propType) +{ + if (!object || propId == -1) + return Value::nullValue(); + + ExecutionEngine *v4 = QV8Engine::getV4(v8); + + QmlListWrapper *r = new (v4->memoryManager) QmlListWrapper(v8); + r->object = object; + r->propertyType = propType; + void *args[] = { &r->property, 0 }; + QMetaObject::metacall(object, QMetaObject::ReadProperty, propId, args); + return Value::fromObject(r); +} + +Value QmlListWrapper::create(QV8Engine *v8, const QQmlListProperty<QObject> &prop, int propType) +{ + ExecutionEngine *v4 = QV8Engine::getV4(v8); + + QmlListWrapper *r = new (v4->memoryManager) QmlListWrapper(v8); + r->object = prop.object; + r->property = prop; + r->propertyType = propType; + return Value::fromObject(r); +} + +QVariant QmlListWrapper::toVariant() const +{ + if (!object) + return QVariant(); + + return QVariant::fromValue(QQmlListReferencePrivate::init(property, propertyType, v8->engine())); +} + + +Value QmlListWrapper::get(Managed *m, ExecutionContext *ctx, String *name, bool *hasProperty) +{ + QmlListWrapper *w = m->asQmlListWrapper(); + if (!w) + ctx->throwTypeError(); + + if (name == ctx->engine->id_length && !w->object.isNull()) { + quint32 count = w->property.count ? w->property.count(&w->property) : 0; + return Value::fromUInt32(count); + } + + return Value::undefinedValue(); +} + +Value QmlListWrapper::getIndexed(Managed *m, ExecutionContext *ctx, uint index, bool *hasProperty) +{ + QmlListWrapper *w = m->asQmlListWrapper(); + if (!w) + ctx->throwTypeError(); + + quint32 count = w->property.count ? w->property.count(&w->property) : 0; + if (index < count && w->property.at) + return w->v8->newQObject(w->property.at(&w->property, index)); + + return Value::undefinedValue(); +} + +void QmlListWrapper::put(Managed *m, ExecutionContext *ctx, String *name, const Value &value) +{ + // doesn't do anything. Should we throw? + Q_UNUSED(m); + Q_UNUSED(ctx); + Q_UNUSED(name); + Q_UNUSED(value); +} + +void QmlListWrapper::destroy(Managed *that) +{ + QmlListWrapper *w = that->asQmlListWrapper(); + w->~QmlListWrapper(); +} + +#if 0 +// ### does this need porting? +v8::Handle<v8::Array> QV8ListWrapper::Enumerator(const v8::AccessorInfo &info) +{ + QV8ListResource *resource = v8_resource_cast<QV8ListResource>(info.This()); + + if (!resource || resource->object.isNull()) return v8::Array::New(); + + quint32 count = resource->property.count?resource->property.count(&resource->property):0; + + v8::Handle<v8::Array> rv = v8::Array::New(count); + + for (uint ii = 0; ii < count; ++ii) + rv->Set(ii, Value::fromDouble(ii)); + + return rv; +} +#endif + +QT_END_NAMESPACE diff --git a/src/qml/qml/v8/qv8listwrapper_p.h b/src/qml/qml/qqmllistwrapper_p.h index 8031a3beaf..6cbcef1093 100644 --- a/src/qml/qml/v8/qv8listwrapper_p.h +++ b/src/qml/qml/qqmllistwrapper_p.h @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#ifndef QV8LISTWRAPPER_P_H -#define QV8LISTWRAPPER_P_H +#ifndef QQMLLISTWRAPPER_P_H +#define QQMLLISTWRAPPER_P_H // // W A R N I N G @@ -55,45 +55,47 @@ #include <QtCore/qglobal.h> #include <QtQml/qqmllist.h> -#include <private/qv8_p.h> +#include <private/qqmlguard_p.h> #include <private/qv4value_p.h> +#include <private/qv4object_p.h> QT_BEGIN_NAMESPACE class QV8Engine; -class QV8ObjectResource; -class QV8ListWrapper + +namespace QV4 { + +struct Q_QML_EXPORT QmlListWrapper : Object { +protected: + QmlListWrapper(QV8Engine *engine); + ~QmlListWrapper(); + public: - QV8ListWrapper(); - ~QV8ListWrapper(); - void init(QV8Engine *); - void destroy(); + static Value create(QV8Engine *v8, QObject *object, int propId, int propType); + static Value create(QV8Engine *v8, const QQmlListProperty<QObject> &prop, int propType); - v8::Handle<v8::Value> newList(QObject *, int, int); - v8::Handle<v8::Value> newList(const QQmlListProperty<QObject> &, int); - QVariant toVariant(v8::Handle<v8::Object>); - QVariant toVariant(QV8ObjectResource *); + QVariant toVariant() const; + + static Value get(Managed *m, ExecutionContext *ctx, String *name, bool *hasProperty); + static Value getIndexed(Managed *m, ExecutionContext *ctx, uint index, bool *hasProperty); + static void put(Managed *m, ExecutionContext *ctx, String *name, const Value &value); + static void destroy(Managed *that); private: - static v8::Handle<v8::Value> Getter(v8::Handle<v8::String> property, - const v8::AccessorInfo &info); - static v8::Handle<v8::Value> Setter(v8::Handle<v8::String> property, - v8::Handle<v8::Value> value, - const v8::AccessorInfo &info); - static v8::Handle<v8::Value> IndexedGetter(uint32_t index, - const v8::AccessorInfo &info); - static v8::Handle<v8::Value> LengthGetter(v8::Handle<v8::String> property, - const v8::AccessorInfo &info); - static v8::Handle<v8::Array> Enumerator(const v8::AccessorInfo &info); - - QV8Engine *m_engine; - QV4::PersistentValue m_constructor; + QV8Engine *v8; + QQmlGuard<QObject> object; + QQmlListProperty<QObject> property; + int propertyType; + + static const ManagedVTable static_vtbl; }; +} + QT_END_NAMESPACE -#endif // QV8LISTWRAPPER_P_H +#endif diff --git a/src/qml/qml/qqmltypewrapper.cpp b/src/qml/qml/qqmltypewrapper.cpp index 6d464405f5..cdc9265004 100644 --- a/src/qml/qml/qqmltypewrapper.cpp +++ b/src/qml/qml/qqmltypewrapper.cpp @@ -118,7 +118,7 @@ Value QmlTypeWrapper::create(QV8Engine *v8, QObject *o, QQmlTypeNameCache *t, co Value QmlTypeWrapper::get(Managed *m, ExecutionContext *ctx, String *name, bool *hasProperty) { QmlTypeWrapper *w = m->asQmlTypeWrapper(); - if (!m) + if (!w) ctx->throwTypeError(); if (hasProperty) @@ -230,7 +230,6 @@ Value QmlTypeWrapper::get(Managed *m, ExecutionContext *ctx, String *name, bool void QmlTypeWrapper::put(Managed *m, ExecutionContext *ctx, String *name, const Value &value) { QmlTypeWrapper *w = m->asQmlTypeWrapper(); - if (!w) ctx->throwTypeError(); diff --git a/src/qml/qml/qqmlvaluetypewrapper.cpp b/src/qml/qml/qqmlvaluetypewrapper.cpp index b6535ae61b..2db3a2f865 100644 --- a/src/qml/qml/qqmlvaluetypewrapper.cpp +++ b/src/qml/qml/qqmlvaluetypewrapper.cpp @@ -236,7 +236,6 @@ Value QmlValueTypeWrapper::method_toString(SimpleCallContext *ctx) Value QmlValueTypeWrapper::get(Managed *m, ExecutionContext *ctx, String *name, bool *hasProperty) { QmlValueTypeWrapper *r = m->asQmlValueTypeWrapper(); - if (!r) ctx->throwTypeError(); diff --git a/src/qml/qml/v4/qv4managed_p.h b/src/qml/qml/v4/qv4managed_p.h index d4239ee915..ea2f4e16f9 100644 --- a/src/qml/qml/v4/qv4managed_p.h +++ b/src/qml/qml/v4/qv4managed_p.h @@ -84,6 +84,7 @@ struct QtObject; struct QmlContextWrapper; struct QmlTypeWrapper; struct QmlValueTypeWrapper; +struct QmlListWrapper; struct ManagedVTable { @@ -190,7 +191,8 @@ public: Type_QtObject, Type_QmlContext, Type_QmlTypeWrapper, - Type_QmlValueTypeWrapper + Type_QmlValueTypeWrapper, + Type_QmlListWrapper }; ExecutionEngine *engine() const; @@ -227,6 +229,7 @@ public: QmlContextWrapper *asQmlContext() { return type == Type_QmlContext ? reinterpret_cast<QmlContextWrapper *>(this) : 0; } QmlTypeWrapper *asQmlTypeWrapper() { return type == Type_QmlTypeWrapper ? reinterpret_cast<QmlTypeWrapper *>(this) : 0; } QmlValueTypeWrapper *asQmlValueTypeWrapper() { return type == Type_QmlValueTypeWrapper ? reinterpret_cast<QmlValueTypeWrapper *>(this) : 0; } + QmlListWrapper *asQmlListWrapper() { return type == Type_QmlListWrapper ? reinterpret_cast<QmlListWrapper *>(this) : 0; } bool isListType() const { return type >= Type_QmlIntList && type <= Type_QmlUrlList; } diff --git a/src/qml/qml/v8/qv8engine.cpp b/src/qml/qml/v8/qv8engine.cpp index b665863a9f..4165ab6d59 100644 --- a/src/qml/qml/v8/qv8engine.cpp +++ b/src/qml/qml/v8/qv8engine.cpp @@ -56,6 +56,7 @@ #include <private/qqmltypewrapper_p.h> #include <private/qqmlcontextwrapper_p.h> #include <private/qqmlvaluetypewrapper_p.h> +#include <private/qqmllistwrapper_p.h> #include "qv4domerrors_p.h" #include "qv4sqlerrors_p.h" @@ -136,7 +137,6 @@ QV8Engine::QV8Engine(QJSEngine* qq) m_bindingFlagKey = QV4::Value::fromString(m_v4Engine->current, QStringLiteral("qml::binding")); m_qobjectWrapper.init(this); - m_listWrapper.init(this); m_jsonWrapper.init(m_v4Engine); } @@ -153,7 +153,6 @@ QV8Engine::~QV8Engine() m_listModelData = 0; m_jsonWrapper.destroy(); - m_listWrapper.destroy(); m_qobjectWrapper.destroy(); v8::Isolate::SetEngine(0); @@ -193,8 +192,6 @@ QVariant QV8Engine::toVariant(const QV4::Value &value, int typeHint) case QV8ObjectResource::ParticleDataType: case QV8ObjectResource::ChangeSetArrayType: return QVariant(); - case QV8ObjectResource::ListType: - return m_listWrapper.toVariant(r); } } else if (typeHint == QMetaType::QJsonObject && !value.asArrayObject() && !value.asFunctionObject()) { @@ -207,6 +204,8 @@ QVariant QV8Engine::toVariant(const QV4::Value &value, int typeHint) return w->toVariant(); } else if (QV4::QmlValueTypeWrapper *v = object->asQmlValueTypeWrapper()) { return v->toVariant(); + } else if (QV4::QmlListWrapper *l = object->asQmlListWrapper()) { + return l->toVariant(); } else if (object->isListType()) return QV4::SequencePrototype::toVariant(object); } @@ -351,7 +350,7 @@ QV4::Value QV8Engine::fromVariant(const QVariant &variant) typedef QQmlListReferencePrivate QDLRP; QDLRP *p = QDLRP::get((QQmlListReference*)ptr); if (p->object) { - return m_listWrapper.newList(p->property, p->propertyType)->v4Value(); + return QV4::QmlListWrapper::create(this, p->property, p->propertyType); } else { return QV4::Value::nullValue(); } diff --git a/src/qml/qml/v8/qv8engine_p.h b/src/qml/qml/v8/qv8engine_p.h index 3b3ed9472e..f53b9219d3 100644 --- a/src/qml/qml/v8/qv8engine_p.h +++ b/src/qml/qml/v8/qv8engine_p.h @@ -72,7 +72,6 @@ #include "qv8objectresource_p.h" #include "qv8qobjectwrapper_p.h" -#include "qv8listwrapper_p.h" #include <private/qv4sequenceobject_p.h> #include "qv4jsonwrapper_p.h" #include <private/qv4value_p.h> @@ -272,7 +271,6 @@ public: QV4::Value global(); QV8QObjectWrapper *qobjectWrapper() { return &m_qobjectWrapper; } - QV8ListWrapper *listWrapper() { return &m_listWrapper; } void *xmlHttpRequestData() { return m_xmlHttpRequestData; } @@ -388,7 +386,6 @@ protected: QV4::PersistentValue m_bindingFlagKey; QV8QObjectWrapper m_qobjectWrapper; - QV8ListWrapper m_listWrapper; QV4JsonWrapper m_jsonWrapper; QV4::PersistentValue m_freezeObject; diff --git a/src/qml/qml/v8/qv8listwrapper.cpp b/src/qml/qml/v8/qv8listwrapper.cpp deleted file mode 100644 index 8e90bceba1..0000000000 --- a/src/qml/qml/v8/qv8listwrapper.cpp +++ /dev/null @@ -1,195 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtQml module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qv8listwrapper_p.h" -#include "qv8engine_p.h" -#include <private/qqmllist_p.h> - -#include <private/qv4functionobject_p.h> - -QT_BEGIN_NAMESPACE - -class QV8ListResource : public QV8ObjectResource -{ - V8_RESOURCE_TYPE(ListType); -public: - QV8ListResource(QV8Engine *engine) : QV8ObjectResource(engine) {} - - QQmlGuard<QObject> object; - QQmlListProperty<QObject> property; - int propertyType; -}; - -QV8ListWrapper::QV8ListWrapper() -: m_engine(0) -{ -} - -QV8ListWrapper::~QV8ListWrapper() -{ -} - -void QV8ListWrapper::init(QV8Engine *engine) -{ - m_engine = engine; - v8::Handle<v8::FunctionTemplate> ft = v8::FunctionTemplate::New(); - ft->InstanceTemplate()->SetFallbackPropertyHandler(Getter, Setter, 0, 0, Enumerator); - ft->InstanceTemplate()->SetIndexedPropertyHandler(IndexedGetter); - ft->InstanceTemplate()->SetAccessor(v8::String::New("length"), LengthGetter, 0, - v8::Handle<v8::Value>(), v8::DEFAULT, - v8::PropertyAttribute(v8::ReadOnly | v8::DontDelete | v8::DontEnum)); - ft->InstanceTemplate()->SetHasExternalResource(true); - m_constructor = ft->GetFunction()->v4Value(); -} - -void QV8ListWrapper::destroy() -{ -} - -v8::Handle<v8::Value> QV8ListWrapper::newList(QObject *object, int propId, int propType) -{ - if (!object || propId == -1) - return QV4::Value::nullValue(); - - // XXX NewInstance() should be optimized - v8::Handle<v8::Object> rv = m_constructor.value().asFunctionObject()->newInstance(); - QV8ListResource *r = new QV8ListResource(m_engine); - r->object = object; - r->propertyType = propType; - void *args[] = { &r->property, 0 }; - QMetaObject::metacall(object, QMetaObject::ReadProperty, propId, args); - rv->SetExternalResource(r); - return rv; -} - -v8::Handle<v8::Value> QV8ListWrapper::newList(const QQmlListProperty<QObject> &prop, int propType) -{ - // XXX NewInstance() should be optimized - v8::Handle<v8::Object> rv = m_constructor.value().asFunctionObject()->newInstance(); - QV8ListResource *r = new QV8ListResource(m_engine); - r->object = prop.object; - r->property = prop; - r->propertyType = propType; - rv->SetExternalResource(r); - return rv; -} - -QVariant QV8ListWrapper::toVariant(v8::Handle<v8::Object> obj) -{ - QV8ListResource *resource = v8_resource_cast<QV8ListResource>(obj); - if (resource) return toVariant(resource); - else return QVariant(); -} - -QVariant QV8ListWrapper::toVariant(QV8ObjectResource *r) -{ - Q_ASSERT(r->resourceType() == QV8ObjectResource::ListType); - QV8ListResource *resource = static_cast<QV8ListResource *>(r); - - if (!resource->object) - return QVariant(); - - return QVariant::fromValue(QQmlListReferencePrivate::init(resource->property, resource->propertyType, - m_engine->engine())); -} - -v8::Handle<v8::Value> QV8ListWrapper::Getter(v8::Handle<v8::String> property, - const v8::AccessorInfo &info) -{ - Q_UNUSED(property); - Q_UNUSED(info); - return v8::Handle<v8::Value>(); -} - -v8::Handle<v8::Value> QV8ListWrapper::Setter(v8::Handle<v8::String> property, - v8::Handle<v8::Value> value, - const v8::AccessorInfo &info) -{ - Q_UNUSED(property); - Q_UNUSED(info); - return value; -} - -v8::Handle<v8::Value> QV8ListWrapper::IndexedGetter(uint32_t index, const v8::AccessorInfo &info) -{ - QV8ListResource *resource = v8_resource_cast<QV8ListResource>(info.This()); - - if (!resource || resource->object.isNull()) return QV4::Value::undefinedValue(); - - quint32 count = resource->property.count?resource->property.count(&resource->property):0; - if (index < count && resource->property.at) { - return resource->engine->newQObject(resource->property.at(&resource->property, index)); - } else { - return QV4::Value::undefinedValue(); - } -} - -v8::Handle<v8::Value> QV8ListWrapper::LengthGetter(v8::Handle<v8::String> property, - const v8::AccessorInfo &info) -{ - Q_UNUSED(property); - - QV8ListResource *resource = v8_resource_cast<QV8ListResource>(info.This()); - - if (!resource || resource->object.isNull()) return QV4::Value::undefinedValue(); - - quint32 count = resource->property.count?resource->property.count(&resource->property):0; - - return QV4::Value::fromUInt32(count); -} - -v8::Handle<v8::Array> QV8ListWrapper::Enumerator(const v8::AccessorInfo &info) -{ - QV8ListResource *resource = v8_resource_cast<QV8ListResource>(info.This()); - - if (!resource || resource->object.isNull()) return v8::Array::New(); - - quint32 count = resource->property.count?resource->property.count(&resource->property):0; - - v8::Handle<v8::Array> rv = v8::Array::New(count); - - for (uint ii = 0; ii < count; ++ii) - rv->Set(ii, QV4::Value::fromDouble(ii)); - - return rv; -} - -QT_END_NAMESPACE diff --git a/src/qml/qml/v8/qv8objectresource_p.h b/src/qml/qml/v8/qv8objectresource_p.h index 019178b0df..e477bba2d4 100644 --- a/src/qml/qml/v8/qv8objectresource_p.h +++ b/src/qml/qml/v8/qv8objectresource_p.h @@ -69,8 +69,7 @@ class QV8ObjectResource : public v8::Object::ExternalResource { public: QV8ObjectResource(QV8Engine *engine) : engine(engine) { Q_ASSERT(engine); } - enum ResourceType { ListType, - XMLHttpRequestType, DOMNodeType, SQLDatabaseType, + enum ResourceType { XMLHttpRequestType, DOMNodeType, SQLDatabaseType, ListModelType, Context2DStyleType, Context2DPixelArrayType, ParticleDataType, SignalHandlerType, IncubatorType, VisualDataItemType, ChangeSetArrayType }; diff --git a/src/qml/qml/v8/qv8qobjectwrapper.cpp b/src/qml/qml/v8/qv8qobjectwrapper.cpp index 79f221e8bc..578eaea567 100644 --- a/src/qml/qml/v8/qv8qobjectwrapper.cpp +++ b/src/qml/qml/v8/qv8qobjectwrapper.cpp @@ -53,6 +53,7 @@ #include <private/qqmlglobal_p.h> #include <private/qqmltypewrapper_p.h> #include <private/qqmlcontextwrapper_p.h> +#include <private/qqmllistwrapper_p.h> #include <private/qv4functionobject_p.h> #include <private/qv4runtime_p.h> @@ -463,7 +464,7 @@ static v8::Handle<v8::Value> LoadProperty(QV8Engine *engine, QObject *object, ReadFunction(object, property, &rv, notifier); return engine->newQObject(rv); } else if (property.isQList()) { - return engine->listWrapper()->newList(object, property.coreIndex, property.propType); + return QmlListWrapper::create(engine, object, property.coreIndex, property.propType); } else if (property.propType == QMetaType::QReal) { qreal v = 0; ReadFunction(object, property, &v, notifier); diff --git a/src/qml/qml/v8/v8.pri b/src/qml/qml/v8/v8.pri index 6748753bb1..01ecd2e925 100644 --- a/src/qml/qml/v8/v8.pri +++ b/src/qml/qml/v8/v8.pri @@ -6,7 +6,6 @@ HEADERS += \ $$PWD/qv8profiler_p.h \ $$PWD/qv8engine_p.h \ $$PWD/qv8qobjectwrapper_p.h \ - $$PWD/qv8listwrapper_p.h \ $$PWD/qv4jsonwrapper_p.h \ $$PWD/qv4domerrors_p.h \ $$PWD/qv4sqlerrors_p.h \ @@ -16,7 +15,6 @@ HEADERS += \ SOURCES += \ $$PWD/qv8engine.cpp \ $$PWD/qv8qobjectwrapper.cpp \ - $$PWD/qv8listwrapper.cpp \ $$PWD/qv4jsonwrapper.cpp \ $$PWD/qv4domerrors.cpp \ $$PWD/qv4sqlerrors.cpp \ |