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 {
struct CompilationUnit;
}
}
namespace QV4 {
struct Function;
struct Object;

View File

@ -297,9 +297,11 @@ ReturnedValue QObjectWrapper::getQmlProperty(ExecutionContext *ctx, QQmlContextD
if (r.scriptIndex != -1) {
return QV4::Encode::undefined();
} 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) {
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");
}

View File

@ -51,8 +51,47 @@
#include <QtCore/QDebug>
#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;
DEFINE_OBJECT_VTABLE(QmlBindingWrapper);
DEFINE_OBJECT_VTABLE(CompilationUnitHolder);
Heap::QmlBindingWrapper::QmlBindingWrapper(QV4::ExecutionContext *scope, Function *f, QV4::Object *qml)
: Heap::FunctionObject(scope, scope->d()->engine->id_eval, /*createProto = */ false)
, qml(qml)
@ -154,31 +193,6 @@ Returned<FunctionObject> *QmlBindingWrapper::createQmlCallableForFunction(QQmlCo
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)
: line(0), column(0), scope(v4->rootContext), strictMode(false), inheritContext(true), parsed(false)
, qml(qml->asReturnedValue()), vmFunction(0), parseAsBinding(true)

View File

@ -155,40 +155,29 @@ template <> bool convertValueToElement(const ValueRef value)
return value->toBoolean();
}
namespace QV4 {
template <typename Container> struct QQmlSequence;
namespace Heap {
template <typename Container>
struct QQmlSequence : Object {
QQmlSequence(QV4::ExecutionEngine *engine, const Container &container);
QQmlSequence(QV4::ExecutionEngine *engine, QObject *object, int propertyIndex);
mutable Container container;
QPointer<QObject> object;
int propertyIndex;
bool isReference;
};
}
template <typename Container>
struct QQmlSequence : public QV4::Object
{
struct Data : Heap::Object {
Data(QV4::ExecutionEngine *engine, const Container &container)
: Heap::Object(InternalClass::create(engine, staticVTable(), engine->sequencePrototype.asObject()))
, container(container)
, propertyIndex(-1)
, isReference(false)
{
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;
QPointer<QObject> object;
int propertyIndex;
bool isReference;
};
V4_OBJECT(QV4::Object)
V4_OBJECT2(QQmlSequence<Container>, QV4::Object)
Q_MANAGED_TYPE(QmlSequence)
public:
@ -474,7 +463,6 @@ public:
return QVariant::fromValue(result);
}
private:
void loadReference() const
{
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;
template<>
DEFINE_OBJECT_VTABLE(QQmlQStringList);

View File

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

View File

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

View File

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

View File

@ -121,17 +121,20 @@ private:
static QV4::ReturnedValue method_localeCompare(QV4::CallContext *ctx);
};
namespace QV4 {
namespace Heap {
struct QQmlLocaleData : Object {
inline QQmlLocaleData(ExecutionEngine *engine);
QLocale locale;
};
}
struct QQmlLocaleData : public QV4::Object
{
struct Data : QV4::Heap::Object {
Data(QV4::ExecutionEngine *engine)
: QV4::Heap::Object(engine)
{
setVTable(staticVTable());
}
QLocale locale;
};
V4_OBJECT(Object)
V4_OBJECT2(QQmlLocaleData, Object)
static QLocale *getThisLocale(QV4::CallContext *ctx) {
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
#endif

View File

@ -48,15 +48,15 @@ using namespace QV4;
DEFINE_OBJECT_VTABLE(QmlTypeWrapper);
QmlTypeWrapper::Data::Data(QV8Engine *engine)
Heap::QmlTypeWrapper::QmlTypeWrapper(QV8Engine *engine)
: Heap::Object(QV8Engine::getV4(engine))
, v8(engine)
, mode(IncludeEnums)
{
setVTable(staticVTable());
setVTable(QV4::QmlTypeWrapper::staticVTable());
}
QmlTypeWrapper::Data::~Data()
Heap::QmlTypeWrapper::~QmlTypeWrapper()
{
if (typeNamespace)
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.
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);
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
// 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(importNamespace);
@ -153,7 +155,7 @@ ReturnedValue QmlTypeWrapper::get(Managed *m, String *name, bool *hasProperty)
if (qobjectSingleton) {
// check for enum value
if (name->startsWithUpper()) {
if (w->d()->mode == IncludeEnums) {
if (w->d()->mode == Heap::QmlTypeWrapper::IncludeEnums) {
// ### Optimize
QByteArray enumName = name->toQString().toUtf8();
const QMetaObject *metaObject = qobjectSingleton->metaObject();

View File

@ -58,22 +58,30 @@ class QQmlTypeNameCache;
namespace QV4 {
namespace Heap {
struct QmlTypeWrapper : Object {
enum TypeNameMode {
IncludeEnums,
ExcludeEnums
};
QmlTypeWrapper(QV8Engine *engine);
~QmlTypeWrapper();
QV8Engine *v8;
TypeNameMode mode;
QPointer<QObject> object;
QQmlType *type;
QQmlTypeNameCache *typeNamespace;
const void *importNamespace;
};
}
struct Q_QML_EXPORT QmlTypeWrapper : Object
{
enum TypeNameMode { IncludeEnums, ExcludeEnums };
struct Data : Heap::Object {
Data(QV8Engine *engine);
~Data();
QV8Engine *v8;
TypeNameMode mode;
QPointer<QObject> object;
QQmlType *type;
QQmlTypeNameCache *typeNamespace;
const void *importNamespace;
};
V4_OBJECT(Object)
V4_OBJECT2(QmlTypeWrapper, Object)
private:
public:
@ -83,8 +91,10 @@ public:
QVariant toVariant() const;
static ReturnedValue create(QV8Engine *, QObject *, QQmlType *, TypeNameMode = IncludeEnums);
static ReturnedValue create(QV8Engine *, QObject *, QQmlTypeNameCache *, const void *, TypeNameMode = IncludeEnums);
static ReturnedValue create(QV8Engine *, QObject *, QQmlType *,
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);

View File

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