int propertyIdx = 0;
for (const QmlIR::Property *p = obj->firstProperty(); p; p = p->next, ++propertyIdx) {
- if (p->type == QV4::CompiledData::Property::Alias ||
- p->type == QV4::CompiledData::Property::Var)
+ if (p->type == QV4::CompiledData::Property::Alias)
continue;
int propertyType = 0;
int vmePropertyType = 0;
quint32 propertyFlags = 0;
- if (p->type < builtinTypeCount) {
+ if (p->type == QV4::CompiledData::Property::Var) {
+ propertyType = QMetaType::QVariant;
+ vmePropertyType = QQmlVMEMetaData::VarPropertyType;
+ propertyFlags = QQmlPropertyData::IsVarProperty;
+ } else if (p->type < builtinTypeCount) {
propertyType = builtinTypes[p->type].metaType;
vmePropertyType = propertyType;
vmd->propertyCount++;
}
- // Now do var properties
- propertyIdx = 0;
- for (const QmlIR::Property *p = obj->firstProperty(); p; p = p->next, ++propertyIdx) {
-
- if (p->type != QV4::CompiledData::Property::Var)
- continue;
-
- quint32 propertyFlags = QQmlPropertyData::IsVarProperty;
- if (!(p->flags & QV4::CompiledData::Property::IsReadOnly))
- propertyFlags |= QQmlPropertyData::IsWritable;
-
- VMD *vmd = (QQmlVMEMetaData *)dynamicData.data();
- (vmd->propertyData() + vmd->propertyCount)->propertyType = QMetaType::QVariant;
- vmd->propertyCount++;
- ((QQmlVMEMetaData *)dynamicData.data())->varPropertyCount++;
-
- QString propertyName = stringAt(p->nameIndex);
- if (propertyIdx == obj->indexOfDefaultProperty) cache->_defaultPropertyName = propertyName;
- cache->appendProperty(propertyName, propertyFlags, effectivePropertyIndex++,
- QMetaType::QVariant, effectiveSignalIndex);
-
- effectiveSignalIndex++;
- }
-
// Alias property count. Actual data is setup in buildDynamicMetaAliases
((QQmlVMEMetaData *)dynamicData.data())->aliasCount = aliasCount;
const QQmlVMEMetaData *meta, QV4::ExecutionContext *qmlBindingContext, QQmlCompiledData *compiledData)
: object(obj),
ctxt(QQmlData::get(obj, true)->outerContext), cache(cache), metaData(meta),
- hasAssignedMetaObjectData(false), aliasEndpoints(0), firstVarPropertyIndex(-1),
+ hasAssignedMetaObjectData(false), aliasEndpoints(0),
propertiesInitialized(false), interceptors(0), v8methods(0)
{
QObjectPrivate *op = QObjectPrivate::get(obj);
bool needsJSWrapper = (metaData->propertyCount > 0);
// ### Optimize
- for (int ii = 0; ii < metaData->propertyCount - metaData->varPropertyCount; ++ii) {
+ for (int ii = 0; ii < metaData->propertyCount; ++ii) {
int t = (metaData->propertyData() + ii)->propertyType;
if (t == list_type) {
listProperties.append(List(methodOffset() + ii, this));
}
}
- firstVarPropertyIndex = metaData->propertyCount - metaData->varPropertyCount;
-
if (needsJSWrapper)
ensureQObjectWrapper();
QV4::Scope scope(properties.engine());
QV4::ScopedValue sv(scope, *(md->data() + id));
- if (!sv->isInt32()) {
- writeProperty(id, int(0));
+ if (!sv->isInt32())
return 0;
- }
return sv->integerValue();
}
QV4::Scope scope(properties.engine());
QV4::ScopedValue sv(scope, *(md->data() + id));
- if (!sv->isBoolean()) {
- writeProperty(id, false);
+ if (!sv->isBoolean())
return false;
- }
return sv->booleanValue();
}
QV4::Scope scope(properties.engine());
QV4::ScopedValue sv(scope, *(md->data() + id));
- if (!sv->isDouble()) {
- writeProperty(id, 0.0);
+ if (!sv->isDouble())
return 0.0;
- }
return sv->doubleValue();
}
QV4::Scope scope(properties.engine());
QV4::ScopedValue sv(scope, *(md->data() + id));
- if (!sv->isString()) {
- writeProperty(id, QString());
+ if (!sv->isString())
return QString();
- }
return sv->stringValue()->toQString();
}
QV4::Scope scope(properties.engine());
QV4::ScopedValue sv(scope, *(md->data() + id));
const QV4::VariantObject *v = sv->as<QV4::VariantObject>();
- if (!v || v->d()->data.type() != QVariant::Url) {
- writeProperty(id, QUrl());
+ if (!v || v->d()->data.type() != QVariant::Url)
return QUrl();
- }
return v->d()->data.value<QUrl>();
}
QV4::Scope scope(properties.engine());
QV4::ScopedValue sv(scope, *(md->data() + id));
const QV4::VariantObject *v = sv->as<QV4::VariantObject>();
- if (!v || v->d()->data.type() != QVariant::Date) {
- writeProperty(id, QDate());
+ if (!v || v->d()->data.type() != QVariant::Date)
return QDate();
- }
return v->d()->data.value<QDate>();
}
QV4::Scope scope(properties.engine());
QV4::ScopedValue sv(scope, *(md->data() + id));
const QV4::VariantObject *v = sv->as<QV4::VariantObject>();
- if (!v || v->d()->data.type() != QVariant::DateTime) {
- writeProperty(id, QDateTime());
+ if (!v || v->d()->data.type() != QVariant::DateTime)
return QDateTime();
- }
return v->d()->data.value<QDateTime>();
}
QV4::Scope scope(properties.engine());
QV4::ScopedValue sv(scope, *(md->data() + id));
const QV4::VariantObject *v = sv->as<QV4::VariantObject>();
- if (!v || v->d()->data.type() != QVariant::SizeF) {
- writeProperty(id, QSizeF());
+ if (!v || v->d()->data.type() != QVariant::SizeF)
return QSizeF();
- }
return v->d()->data.value<QSizeF>();
}
QV4::Scope scope(properties.engine());
QV4::ScopedValue sv(scope, *(md->data() + id));
const QV4::VariantObject *v = sv->as<QV4::VariantObject>();
- if (!v || v->d()->data.type() != QVariant::PointF) {
- writeProperty(id, QPointF());
+ if (!v || v->d()->data.type() != QVariant::PointF)
return QPointF();
- }
return v->d()->data.value<QPointF>();
}
QV4::Scope scope(properties.engine());
QV4::ScopedValue sv(scope, *(md->data() + id));
const QV4::QObjectWrapper *wrapper = sv->as<QV4::QObjectWrapper>();
- if (!wrapper) {
- writeProperty(id, static_cast<QObject*>(Q_NULLPTR));
+ if (!wrapper)
return 0;
- }
return wrapper->object();
}
QV4::Scope scope(properties.engine());
QV4::ScopedValue sv(scope, *(md->data() + id));
const QV4::VariantObject *v = sv->as<QV4::VariantObject>();
- if (!v || v->d()->data.type() != QVariant::RectF) {
- writeProperty(id, QRectF());
+ if (!v || v->d()->data.type() != QVariant::RectF)
return QRectF();
- }
return v->d()->data.value<QRectF>();
}
int t = (metaData->propertyData() + id)->propertyType;
bool needActivate = false;
- if (id >= firstVarPropertyIndex) {
- Q_ASSERT(t == QMetaType::QVariant);
+ if (t == QQmlVMEMetaData::VarPropertyType) {
// the context can be null if accessing var properties from cpp after re-parenting an item.
QQmlEnginePrivate *ep = (ctxt == 0 || ctxt->engine == 0) ? 0 : QQmlEnginePrivate::get(ctxt->engine);
QV8Engine *v8e = (ep == 0) ? 0 : ep->v8engine();
QV4::ReturnedValue QQmlVMEMetaObject::readVarProperty(int id)
{
- Q_ASSERT(id >= firstVarPropertyIndex);
+ Q_ASSERT((metaData->propertyData() + id)->propertyType == QQmlVMEMetaData::VarPropertyType);
QV4::MemberData *md = propertiesAsMemberData();
if (md)
QVariant QQmlVMEMetaObject::readPropertyAsVariant(int id)
{
- if (id >= firstVarPropertyIndex) {
- QV4::MemberData *md = propertiesAsMemberData();
- if (md)
- return properties.engine()->toVariant(*(md->data() + id), -1);
- } else {
- QV4::MemberData *md = propertiesAsMemberData();
- if (md) {
- const QV4::QObjectWrapper *wrapper = (md->data() + id)->as<QV4::QObjectWrapper>();
- if (wrapper)
- return QVariant::fromValue(wrapper->object());
- const QV4::VariantObject *v = (md->data() + id)->as<QV4::VariantObject>();
- if (!v) {
- writeProperty(id, QVariant());
- return QVariant();
- }
+ QV4::MemberData *md = propertiesAsMemberData();
+ if (md) {
+ const QV4::QObjectWrapper *wrapper = (md->data() + id)->as<QV4::QObjectWrapper>();
+ if (wrapper)
+ return QVariant::fromValue(wrapper->object());
+ const QV4::VariantObject *v = (md->data() + id)->as<QV4::VariantObject>();
+ if (v)
return v->d()->data;
- }
+ return properties.engine()->toVariant(*(md->data() + id), -1);
}
return QVariant();
}
void QQmlVMEMetaObject::writeVarProperty(int id, const QV4::Value &value)
{
- Q_ASSERT(id >= firstVarPropertyIndex);
+ Q_ASSERT((metaData->propertyData() + id)->propertyType == QQmlVMEMetaData::VarPropertyType);
+
QV4::MemberData *md = propertiesAsMemberData();
if (!md)
return;
void QQmlVMEMetaObject::writeProperty(int id, const QVariant &value)
{
- if (id >= firstVarPropertyIndex) {
+ if ((metaData->propertyData() + id)->propertyType == QQmlVMEMetaData::VarPropertyType) {
QV4::MemberData *md = propertiesAsMemberData();
if (!md)
return;