Move data of more Qml related objects into Heap namespace.

Change-Id: Ifb3a7093351474d6feb2f64498b531c36fdf669b
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
This commit is contained in:
Lars Knoll 2014-11-07 02:06:42 +01:00 committed by Simon Hausmann
parent 4838cc89f0
commit fcf0203aaf
11 changed files with 167 additions and 106 deletions

View File

@ -58,9 +58,6 @@ class Profiler;
namespace CompiledData { namespace CompiledData {
struct CompilationUnit; struct CompilationUnit;
} }
}
namespace QV4 {
struct Function; struct Function;
struct Object; struct Object;

View File

@ -297,9 +297,11 @@ ReturnedValue QObjectWrapper::getQmlProperty(ExecutionContext *ctx, QQmlContextD
if (r.scriptIndex != -1) { if (r.scriptIndex != -1) {
return QV4::Encode::undefined(); return QV4::Encode::undefined();
} else if (r.type) { } else if (r.type) {
return QmlTypeWrapper::create(ctx->d()->engine->v8Engine, d()->object, r.type, QmlTypeWrapper::ExcludeEnums); return QmlTypeWrapper::create(ctx->d()->engine->v8Engine, d()->object,
r.type, Heap::QmlTypeWrapper::ExcludeEnums);
} else if (r.importNamespace) { } else if (r.importNamespace) {
return QmlTypeWrapper::create(ctx->d()->engine->v8Engine, d()->object, qmlContext->imports, r.importNamespace, QmlTypeWrapper::ExcludeEnums); return QmlTypeWrapper::create(ctx->d()->engine->v8Engine, d()->object,
qmlContext->imports, r.importNamespace, Heap::QmlTypeWrapper::ExcludeEnums);
} }
Q_ASSERT(!"Unreachable"); Q_ASSERT(!"Unreachable");
} }

View File

@ -51,8 +51,47 @@
#include <QtCore/QDebug> #include <QtCore/QDebug>
#include <QtCore/QString> #include <QtCore/QString>
QT_BEGIN_NAMESPACE
namespace QV4 {
namespace Heap {
struct CompilationUnitHolder : Object {
inline CompilationUnitHolder(ExecutionEngine *engine, CompiledData::CompilationUnit *unit);
QQmlRefPointer<CompiledData::CompilationUnit> unit;
};
}
struct CompilationUnitHolder : public Object
{
V4_OBJECT2(CompilationUnitHolder, Object)
static void destroy(Managed *that)
{
static_cast<CompilationUnitHolder*>(that)->d()->~Data();
}
};
inline
Heap::CompilationUnitHolder::CompilationUnitHolder(ExecutionEngine *engine, CompiledData::CompilationUnit *unit)
: Heap::Object(engine)
, unit(unit)
{
setVTable(QV4::CompilationUnitHolder::staticVTable());
}
}
QT_END_NAMESPACE
using namespace QV4; using namespace QV4;
DEFINE_OBJECT_VTABLE(QmlBindingWrapper);
DEFINE_OBJECT_VTABLE(CompilationUnitHolder);
Heap::QmlBindingWrapper::QmlBindingWrapper(QV4::ExecutionContext *scope, Function *f, QV4::Object *qml) Heap::QmlBindingWrapper::QmlBindingWrapper(QV4::ExecutionContext *scope, Function *f, QV4::Object *qml)
: Heap::FunctionObject(scope, scope->d()->engine->id_eval, /*createProto = */ false) : Heap::FunctionObject(scope, scope->d()->engine->id_eval, /*createProto = */ false)
, qml(qml) , qml(qml)
@ -154,31 +193,6 @@ Returned<FunctionObject> *QmlBindingWrapper::createQmlCallableForFunction(QQmlCo
return function->asReturned<FunctionObject>(); return function->asReturned<FunctionObject>();
} }
DEFINE_OBJECT_VTABLE(QmlBindingWrapper);
struct CompilationUnitHolder : public Object
{
struct Data : Heap::Object {
Data(ExecutionEngine *engine, CompiledData::CompilationUnit *unit)
: Heap::Object(engine)
, unit(unit)
{
setVTable(staticVTable());
}
QQmlRefPointer<QV4::CompiledData::CompilationUnit> unit;
};
V4_OBJECT(Object)
static void destroy(Managed *that)
{
static_cast<CompilationUnitHolder*>(that)->d()->~Data();
}
};
DEFINE_OBJECT_VTABLE(CompilationUnitHolder);
Script::Script(ExecutionEngine *v4, Object *qml, CompiledData::CompilationUnit *compilationUnit) Script::Script(ExecutionEngine *v4, Object *qml, CompiledData::CompilationUnit *compilationUnit)
: line(0), column(0), scope(v4->rootContext), strictMode(false), inheritContext(true), parsed(false) : line(0), column(0), scope(v4->rootContext), strictMode(false), inheritContext(true), parsed(false)
, qml(qml->asReturnedValue()), vmFunction(0), parseAsBinding(true) , qml(qml->asReturnedValue()), vmFunction(0), parseAsBinding(true)

View File

@ -155,40 +155,29 @@ template <> bool convertValueToElement(const ValueRef value)
return value->toBoolean(); return value->toBoolean();
} }
template <typename Container> namespace QV4 {
struct QQmlSequence : public QV4::Object
{ template <typename Container> struct QQmlSequence;
struct Data : Heap::Object {
Data(QV4::ExecutionEngine *engine, const Container &container) namespace Heap {
: Heap::Object(InternalClass::create(engine, staticVTable(), engine->sequencePrototype.asObject()))
, container(container) template <typename Container>
, propertyIndex(-1) struct QQmlSequence : Object {
, isReference(false) QQmlSequence(QV4::ExecutionEngine *engine, const Container &container);
{ QQmlSequence(QV4::ExecutionEngine *engine, QObject *object, int propertyIndex);
QV4::Scope scope(engine);
QV4::Scoped<QQmlSequence<Container> > o(scope, this);
o->setArrayType(Heap::ArrayData::Custom);
o->init();
}
Data(QV4::ExecutionEngine *engine, QObject *object, int propertyIndex)
: Heap::Object(InternalClass::create(engine, staticVTable(), engine->sequencePrototype.asObject()))
, object(object)
, propertyIndex(propertyIndex)
, isReference(true)
{
QV4::Scope scope(engine);
QV4::Scoped<QQmlSequence<Container> > o(scope, this);
o->setArrayType(Heap::ArrayData::Custom);
o->loadReference();
o->init();
}
mutable Container container; mutable Container container;
QPointer<QObject> object; QPointer<QObject> object;
int propertyIndex; int propertyIndex;
bool isReference; bool isReference;
}; };
V4_OBJECT(QV4::Object)
}
template <typename Container>
struct QQmlSequence : public QV4::Object
{
V4_OBJECT2(QQmlSequence<Container>, QV4::Object)
Q_MANAGED_TYPE(QmlSequence) Q_MANAGED_TYPE(QmlSequence)
public: public:
@ -474,7 +463,6 @@ public:
return QVariant::fromValue(result); return QVariant::fromValue(result);
} }
private:
void loadReference() const void loadReference() const
{ {
Q_ASSERT(d()->object); Q_ASSERT(d()->object);
@ -512,6 +500,36 @@ private:
} }
}; };
template <typename Container>
Heap::QQmlSequence<Container>::QQmlSequence(QV4::ExecutionEngine *engine, const Container &container)
: Heap::Object(InternalClass::create(engine, QV4::QQmlSequence<Container>::staticVTable(), engine->sequencePrototype.asObject()))
, container(container)
, propertyIndex(-1)
, isReference(false)
{
QV4::Scope scope(engine);
QV4::Scoped<QV4::QQmlSequence<Container> > o(scope, this);
o->setArrayType(Heap::ArrayData::Custom);
o->init();
}
template <typename Container>
Heap::QQmlSequence<Container>::QQmlSequence(QV4::ExecutionEngine *engine, QObject *object, int propertyIndex)
: Heap::Object(InternalClass::create(engine, QV4::QQmlSequence<Container>::staticVTable(), engine->sequencePrototype.asObject()))
, object(object)
, propertyIndex(propertyIndex)
, isReference(true)
{
QV4::Scope scope(engine);
QV4::Scoped<QV4::QQmlSequence<Container> > o(scope, this);
o->setArrayType(Heap::ArrayData::Custom);
o->loadReference();
o->init();
}
}
typedef QQmlSequence<QStringList> QQmlQStringList; typedef QQmlSequence<QStringList> QQmlQStringList;
template<> template<>
DEFINE_OBJECT_VTABLE(QQmlQStringList); DEFINE_OBJECT_VTABLE(QQmlQStringList);

View File

@ -45,18 +45,18 @@ using namespace QV4;
DEFINE_OBJECT_VTABLE(QmlListWrapper); DEFINE_OBJECT_VTABLE(QmlListWrapper);
QmlListWrapper::Data::Data(QV8Engine *engine) Heap::QmlListWrapper::QmlListWrapper(QV8Engine *engine)
: Heap::Object(QV8Engine::getV4(engine)) : Heap::Object(QV8Engine::getV4(engine))
, v8(engine) , v8(engine)
{ {
setVTable(staticVTable()); setVTable(QV4::QmlListWrapper::staticVTable());
QV4::Scope scope(QV8Engine::getV4(engine)); QV4::Scope scope(QV8Engine::getV4(engine));
QV4::ScopedObject o(scope, this); QV4::ScopedObject o(scope, this);
o->setArrayType(Heap::ArrayData::Custom); o->setArrayType(Heap::ArrayData::Custom);
} }
QmlListWrapper::Data::~Data() Heap::QmlListWrapper::~QmlListWrapper()
{ {
} }

View File

@ -59,17 +59,22 @@ class QV8Engine;
namespace QV4 { namespace QV4 {
struct Q_QML_EXPORT QmlListWrapper : Object namespace Heap {
{
struct Data : Heap::Object { struct QmlListWrapper : Object {
Data(QV8Engine *engine); QmlListWrapper(QV8Engine *engine);
~Data(); ~QmlListWrapper();
QV8Engine *v8; QV8Engine *v8;
QPointer<QObject> object; QPointer<QObject> object;
QQmlListProperty<QObject> property; QQmlListProperty<QObject> property;
int propertyType; int propertyType;
}; };
V4_OBJECT(Object)
}
struct Q_QML_EXPORT QmlListWrapper : Object
{
V4_OBJECT2(QmlListWrapper, Object)
static ReturnedValue create(QV8Engine *v8, QObject *object, int propId, int propType); static ReturnedValue create(QV8Engine *v8, QObject *object, int propId, int propType);
static ReturnedValue create(QV8Engine *v8, const QQmlListProperty<QObject> &prop, int propType); static ReturnedValue create(QV8Engine *v8, const QQmlListProperty<QObject> &prop, int propType);

View File

@ -46,6 +46,8 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
using namespace QV4;
DEFINE_OBJECT_VTABLE(QQmlLocaleData); DEFINE_OBJECT_VTABLE(QQmlLocaleData);
#define GET_LOCALE_DATA_RESOURCE(OBJECT) \ #define GET_LOCALE_DATA_RESOURCE(OBJECT) \

View File

@ -121,17 +121,20 @@ private:
static QV4::ReturnedValue method_localeCompare(QV4::CallContext *ctx); static QV4::ReturnedValue method_localeCompare(QV4::CallContext *ctx);
}; };
struct QQmlLocaleData : public QV4::Object namespace QV4 {
{
struct Data : QV4::Heap::Object { namespace Heap {
Data(QV4::ExecutionEngine *engine)
: QV4::Heap::Object(engine) struct QQmlLocaleData : Object {
{ inline QQmlLocaleData(ExecutionEngine *engine);
setVTable(staticVTable());
}
QLocale locale; QLocale locale;
}; };
V4_OBJECT(Object)
}
struct QQmlLocaleData : public QV4::Object
{
V4_OBJECT2(QQmlLocaleData, Object)
static QLocale *getThisLocale(QV4::CallContext *ctx) { static QLocale *getThisLocale(QV4::CallContext *ctx) {
QV4::Object *o = ctx->d()->callData->thisObject.asObject(); QV4::Object *o = ctx->d()->callData->thisObject.asObject();
@ -178,6 +181,14 @@ private:
} }
}; };
Heap::QQmlLocaleData::QQmlLocaleData(ExecutionEngine *engine)
: Heap::Object(engine)
{
setVTable(QV4::QQmlLocaleData::staticVTable());
}
}
QT_END_NAMESPACE QT_END_NAMESPACE
#endif #endif

View File

@ -48,15 +48,15 @@ using namespace QV4;
DEFINE_OBJECT_VTABLE(QmlTypeWrapper); DEFINE_OBJECT_VTABLE(QmlTypeWrapper);
QmlTypeWrapper::Data::Data(QV8Engine *engine) Heap::QmlTypeWrapper::QmlTypeWrapper(QV8Engine *engine)
: Heap::Object(QV8Engine::getV4(engine)) : Heap::Object(QV8Engine::getV4(engine))
, v8(engine) , v8(engine)
, mode(IncludeEnums) , mode(IncludeEnums)
{ {
setVTable(staticVTable()); setVTable(QV4::QmlTypeWrapper::staticVTable());
} }
QmlTypeWrapper::Data::~Data() Heap::QmlTypeWrapper::~QmlTypeWrapper()
{ {
if (typeNamespace) if (typeNamespace)
typeNamespace->release(); typeNamespace->release();
@ -96,7 +96,8 @@ QVariant QmlTypeWrapper::toVariant() const
// Returns a type wrapper for type t on o. This allows access of enums, and attached properties. // Returns a type wrapper for type t on o. This allows access of enums, and attached properties.
ReturnedValue QmlTypeWrapper::create(QV8Engine *v8, QObject *o, QQmlType *t, TypeNameMode mode) ReturnedValue QmlTypeWrapper::create(QV8Engine *v8, QObject *o, QQmlType *t,
Heap::QmlTypeWrapper::TypeNameMode mode)
{ {
Q_ASSERT(t); Q_ASSERT(t);
ExecutionEngine *v4 = QV8Engine::getV4(v8); ExecutionEngine *v4 = QV8Engine::getV4(v8);
@ -109,7 +110,8 @@ ReturnedValue QmlTypeWrapper::create(QV8Engine *v8, QObject *o, QQmlType *t, Typ
// Returns a type wrapper for importNamespace (of t) on o. This allows nested resolution of a type in a // Returns a type wrapper for importNamespace (of t) on o. This allows nested resolution of a type in a
// namespace. // namespace.
ReturnedValue QmlTypeWrapper::create(QV8Engine *v8, QObject *o, QQmlTypeNameCache *t, const void *importNamespace, TypeNameMode mode) ReturnedValue QmlTypeWrapper::create(QV8Engine *v8, QObject *o, QQmlTypeNameCache *t, const void *importNamespace,
Heap::QmlTypeWrapper::TypeNameMode mode)
{ {
Q_ASSERT(t); Q_ASSERT(t);
Q_ASSERT(importNamespace); Q_ASSERT(importNamespace);
@ -153,7 +155,7 @@ ReturnedValue QmlTypeWrapper::get(Managed *m, String *name, bool *hasProperty)
if (qobjectSingleton) { if (qobjectSingleton) {
// check for enum value // check for enum value
if (name->startsWithUpper()) { if (name->startsWithUpper()) {
if (w->d()->mode == IncludeEnums) { if (w->d()->mode == Heap::QmlTypeWrapper::IncludeEnums) {
// ### Optimize // ### Optimize
QByteArray enumName = name->toQString().toUtf8(); QByteArray enumName = name->toQString().toUtf8();
const QMetaObject *metaObject = qobjectSingleton->metaObject(); const QMetaObject *metaObject = qobjectSingleton->metaObject();

View File

@ -58,13 +58,16 @@ class QQmlTypeNameCache;
namespace QV4 { namespace QV4 {
struct Q_QML_EXPORT QmlTypeWrapper : Object namespace Heap {
{
enum TypeNameMode { IncludeEnums, ExcludeEnums };
struct Data : Heap::Object { struct QmlTypeWrapper : Object {
Data(QV8Engine *engine); enum TypeNameMode {
~Data(); IncludeEnums,
ExcludeEnums
};
QmlTypeWrapper(QV8Engine *engine);
~QmlTypeWrapper();
QV8Engine *v8; QV8Engine *v8;
TypeNameMode mode; TypeNameMode mode;
QPointer<QObject> object; QPointer<QObject> object;
@ -73,7 +76,12 @@ struct Q_QML_EXPORT QmlTypeWrapper : Object
QQmlTypeNameCache *typeNamespace; QQmlTypeNameCache *typeNamespace;
const void *importNamespace; const void *importNamespace;
}; };
V4_OBJECT(Object)
}
struct Q_QML_EXPORT QmlTypeWrapper : Object
{
V4_OBJECT2(QmlTypeWrapper, Object)
private: private:
public: public:
@ -83,8 +91,10 @@ public:
QVariant toVariant() const; QVariant toVariant() const;
static ReturnedValue create(QV8Engine *, QObject *, QQmlType *, TypeNameMode = IncludeEnums); static ReturnedValue create(QV8Engine *, QObject *, QQmlType *,
static ReturnedValue create(QV8Engine *, QObject *, QQmlTypeNameCache *, const void *, TypeNameMode = IncludeEnums); Heap::QmlTypeWrapper::TypeNameMode = Heap::QmlTypeWrapper::IncludeEnums);
static ReturnedValue create(QV8Engine *, QObject *, QQmlTypeNameCache *, const void *,
Heap::QmlTypeWrapper::TypeNameMode = Heap::QmlTypeWrapper::IncludeEnums);
static ReturnedValue get(Managed *m, String *name, bool *hasProperty); static ReturnedValue get(Managed *m, String *name, bool *hasProperty);

View File

@ -233,7 +233,7 @@ QVariant QV8Engine::toVariant(const QV4::ValueRef value, int typeHint, bool crea
return value->asDouble(); return value->asDouble();
if (value->isString()) if (value->isString())
return value->stringValue()->toQString(); return value->stringValue()->toQString();
if (QQmlLocaleData *ld = value->as<QQmlLocaleData>()) if (QV4::QQmlLocaleData *ld = value->as<QV4::QQmlLocaleData>())
return ld->d()->locale; return ld->d()->locale;
if (QV4::DateObject *d = value->asDateObject()) if (QV4::DateObject *d = value->asDateObject())
return d->toQDateTime(); return d->toQDateTime();