831int QQmlVMEMetaObject::metaCall(QObject *o, QMetaObject::Call c,
int _id,
void **a)
833 Q_ASSERT(o == object.data());
838 if (intercept(c, _id, a))
841 if (c == QMetaObject::ReadProperty || c == QMetaObject::WriteProperty || c == QMetaObject::ResetProperty || c == QMetaObject::BindableProperty) {
842 if (id >= propOffset()) {
845 const QQmlPropertyData *propertyData = cache->property(_id);
846 if (!propertyData->isAlias()) {
849 QQmlEnginePrivate *ep = (m_ctxt.isNull() || m_ctxt->engine() ==
nullptr)
851 : QQmlEnginePrivate::get(m_ctxt->engine());
853 if (c == QMetaObject::ReadProperty) {
854 if (propertyData->isQList()) {
856 const QQmlPropertyData *propertyData = cache->property(_id);
857 const QMetaType propType = propertyData->propType();
859 if (propType.flags().testFlag(QMetaType::IsQmlList)) {
860 if (!getListProperty(
861 id,
static_cast<QQmlListProperty<QObject> *>(a[0]))) {
864 }
else if (QV4::MemberData *md = propertyAndMethodStorageAsMemberData()) {
866 QV4::Scope scope(m_engine);
867 QV4::Scoped<QV4::Sequence> sequence(scope, *(md->data() + id));
868 switch (QV4::SequencePrototype::getRawContainer(
869 sequence, a[0], propType)) {
870 case QV4::SequencePrototype::Copied:
871 case QV4::SequencePrototype::WasEqual:
873 case QV4::SequencePrototype::TypeMismatch:
876 propType.destruct(a[0]);
877 propType.construct(a[0]);
881 qmlWarning(object.data()) <<
"Cannot find member data";
884 const QV4::CompiledData::CommonType t
885 = QQmlPropertyCacheCreatorBase::propertyTypeForMetaType(
886 propertyData->propType());
888 case QV4::CompiledData::CommonType::Void:
890 case QV4::CompiledData::CommonType::Int:
891 *
reinterpret_cast<
int *>(a[0]) = readPropertyAsInt(id);
893 case QV4::CompiledData::CommonType::Bool:
894 *
reinterpret_cast<
bool *>(a[0]) = readPropertyAsBool(id);
896 case QV4::CompiledData::CommonType::Real:
897 *
reinterpret_cast<
double *>(a[0]) = readPropertyAsDouble(id);
899 case QV4::CompiledData::CommonType::String:
900 *
reinterpret_cast<QString *>(a[0]) = readPropertyAsString(id);
902 case QV4::CompiledData::CommonType::Url:
903 *
reinterpret_cast<QUrl *>(a[0]) = readPropertyAsUrl(id);
905 case QV4::CompiledData::CommonType::Date:
906 *
reinterpret_cast<QDate *>(a[0]) = readPropertyAsDate(id);
908 case QV4::CompiledData::CommonType::DateTime:
909 *
reinterpret_cast<QDateTime *>(a[0]) = readPropertyAsDateTime(id);
911 case QV4::CompiledData::CommonType::RegExp:
912#if QT_CONFIG(regularexpression)
913 *
reinterpret_cast<QRegularExpression *>(a[0])
914 = readPropertyAsRegularExpression(id);
917 case QV4::CompiledData::CommonType::Rect:
918 *
reinterpret_cast<QRectF *>(a[0]) = readPropertyAsRectF(id);
920 case QV4::CompiledData::CommonType::Size:
921 *
reinterpret_cast<QSizeF *>(a[0]) = readPropertyAsSizeF(id);
923 case QV4::CompiledData::CommonType::Point:
924 *
reinterpret_cast<QPointF *>(a[0]) = readPropertyAsPointF(id);
926 case QV4::CompiledData::CommonType::Time:
927 *
reinterpret_cast<QTime *>(a[0]) = readPropertyAsTime(id);
929 case QV4::CompiledData::CommonType::Var:
931 *
reinterpret_cast<QVariant *>(a[0]) = readPropertyAsVariant(id);
935 *
reinterpret_cast<QVariant *>(a[0]) = QVariant();
938 case QV4::CompiledData::CommonType::Invalid:
939 if (QV4::MemberData *md = propertyAndMethodStorageAsMemberData()) {
940 QV4::Scope scope(m_engine);
941 QV4::ScopedValue sv(scope, *(md->data() + id));
944 const QQmlPropertyData *propertyData = cache->property(_id);
946 if (propertyData->isQObject()) {
947 if (
const auto *wrap = sv->as<QV4::QObjectWrapper>())
948 *
reinterpret_cast<QObject **>(a[0]) = wrap->object();
950 *
reinterpret_cast<QObject **>(a[0]) =
nullptr;
952 const QMetaType propType = propertyData->propType();
953 const void *data =
nullptr;
954 if (
const auto *v = sv->as<QV4::VariantObject>()) {
955 const QVariant &variant = v->d()->data();
956 if (variant.metaType() == propType)
957 data = variant.constData();
959 propType.destruct(a[0]);
960 propType.construct(a[0], data);
963 qmlWarning(object.data()) <<
"Cannot find member data";
967 }
else if (c == QMetaObject::WriteProperty) {
968 bool needActivate =
false;
970 if (propertyData->isQList()) {
971 const QMetaType propType = propertyData->propType();
973 if (propType.flags().testFlag(QMetaType::IsQmlList)) {
975 QQmlListProperty<QObject> listProp;
976 if (!getListProperty(id, &listProp))
979 QQmlListProperty<QObject> *input
980 =
static_cast<QQmlListProperty<QObject> *>(a[0]);
984 if (listProp.count(&listProp) != input->count(input)) {
987 for (qsizetype i = 0, end = input->count(input); i < end; ++i) {
988 if (listProp.at(&listProp, i) == input->at(input, i))
999 QQmlVMEMetaObject::list_clear_nosignal(&listProp);
1000 for (qsizetype i = 0, end = input->count(input); i < end; ++i) {
1001 QQmlVMEMetaObject::list_append_nosignal(
1002 &listProp, input->at(input, i));
1005 }
else if (QV4::MemberData *md = propertyAndMethodStorageAsMemberData()) {
1007 QV4::Scope scope(m_engine);
1008 QV4::Scoped<QV4::Sequence> sequence(scope, *(md->data() + id));
1009 switch (QV4::SequencePrototype::setRawContainer(
1010 sequence, a[0], propType)) {
1011 case QV4::SequencePrototype::Copied:
1012 needActivate =
true;
1014 case QV4::SequencePrototype::WasEqual:
1016 case QV4::SequencePrototype::TypeMismatch: {
1017 if (
const QQmlType type = QQmlMetaType::qmlListType(propType);
1018 type.isSequentialContainer()) {
1019 sequence = QV4::SequencePrototype::fromData(
1020 m_engine, propType, type.listMetaSequence(), a[0]);
1021 }
else if (QMetaSequence::Iterable iterable;
1024 QMetaType::fromType<QMetaSequence::Iterable>(),
1026 sequence = QV4::SequencePrototype::fromData(
1027 m_engine, propType, iterable.metaContainer(), a[0]);
1029 sequence = QV4::Encode::undefined();
1031 md->set(m_engine, id, sequence);
1032 if (sequence->isUndefined()) {
1033 qmlWarning(object.data())
1034 <<
"Could not create a QML sequence object for "
1037 needActivate =
true;
1042 qmlWarning(object.data()) <<
"Cannot find member data";
1045 const QV4::CompiledData::CommonType t
1046 = QQmlPropertyCacheCreatorBase::propertyTypeForMetaType(
1047 propertyData->propType());
1049 case QV4::CompiledData::CommonType::Void:
1051 case QV4::CompiledData::CommonType::Int:
1052 needActivate = *
reinterpret_cast<
int *>(a[0]) != readPropertyAsInt(id);
1053 writeProperty(id, *
reinterpret_cast<
int *>(a[0]));
1055 case QV4::CompiledData::CommonType::Bool:
1056 needActivate = *
reinterpret_cast<
bool *>(a[0]) != readPropertyAsBool(id);
1057 writeProperty(id, *
reinterpret_cast<
bool *>(a[0]));
1059 case QV4::CompiledData::CommonType::Real:
1060 needActivate = *
reinterpret_cast<
double *>(a[0]) != readPropertyAsDouble(id);
1061 writeProperty(id, *
reinterpret_cast<
double *>(a[0]));
1063 case QV4::CompiledData::CommonType::String:
1064 needActivate = *
reinterpret_cast<QString *>(a[0]) != readPropertyAsString(id);
1065 writeProperty(id, *
reinterpret_cast<QString *>(a[0]));
1067 case QV4::CompiledData::CommonType::Url:
1068 needActivate = *
reinterpret_cast<QUrl *>(a[0]) != readPropertyAsUrl(id);
1069 writeProperty(id, *
reinterpret_cast<QUrl *>(a[0]));
1071 case QV4::CompiledData::CommonType::Date:
1072 needActivate = *
reinterpret_cast<QDate *>(a[0]) != readPropertyAsDate(id);
1073 writeProperty(id, *
reinterpret_cast<QDate *>(a[0]));
1075 case QV4::CompiledData::CommonType::DateTime:
1076 needActivate = *
reinterpret_cast<QDateTime *>(a[0]) != readPropertyAsDateTime(id);
1077 writeProperty(id, *
reinterpret_cast<QDateTime *>(a[0]));
1079 case QV4::CompiledData::CommonType::RegExp:
1080#if QT_CONFIG(regularexpression)
1081 needActivate = *
reinterpret_cast<QRegularExpression *>(a[0])
1082 != readPropertyAsRegularExpression(id);
1083 writeProperty(id, *
reinterpret_cast<QRegularExpression *>(a[0]));
1086 case QV4::CompiledData::CommonType::Rect:
1087 needActivate = *
reinterpret_cast<QRectF *>(a[0]) != readPropertyAsRectF(id);
1088 writeProperty(id, *
reinterpret_cast<QRectF *>(a[0]));
1090 case QV4::CompiledData::CommonType::Size:
1091 needActivate = *
reinterpret_cast<QSizeF *>(a[0]) != readPropertyAsSizeF(id);
1092 writeProperty(id, *
reinterpret_cast<QSizeF *>(a[0]));
1094 case QV4::CompiledData::CommonType::Point:
1095 needActivate = *
reinterpret_cast<QPointF *>(a[0]) != readPropertyAsPointF(id);
1096 writeProperty(id, *
reinterpret_cast<QPointF *>(a[0]));
1098 case QV4::CompiledData::CommonType::Time:
1099 needActivate = *
reinterpret_cast<QTime *>(a[0]) != readPropertyAsTime(id);
1100 writeProperty(id, *
reinterpret_cast<QTime *>(a[0]));
1102 case QV4::CompiledData::CommonType::Var:
1104 writeKnownVarProperty(id, *
reinterpret_cast<QVariant *>(a[0]));
1106 case QV4::CompiledData::CommonType::Invalid:
1107 if (QV4::MemberData *md = propertyAndMethodStorageAsMemberData()) {
1108 QV4::Scope scope(m_engine);
1109 QV4::ScopedValue sv(scope, *(md->data() + id));
1112 const QQmlPropertyData *propertyData = cache->property(_id);
1114 if (propertyData->isQObject()) {
1115 QObject *arg = *
reinterpret_cast<QObject **>(a[0]);
1116 if (
const auto *wrap = sv->as<QV4::QObjectWrapper>())
1117 needActivate = wrap->object() != arg;
1118 else if (arg !=
nullptr || !sv->isNull())
1119 needActivate =
true;
1121 writeProperty(id, arg);
1123 const QMetaType propType = propertyData->propType();
1124 if (
const auto *v = sv->as<QV4::VariantObject>()) {
1125 QVariant &variant = v->d()->data();
1126 if (variant.metaType() != propType) {
1127 needActivate =
true;
1128 variant = QVariant(propType, a[0]);
1129 }
else if (!propType.equals(variant.constData(), a[0])) {
1130 needActivate =
true;
1131 propType.destruct(variant.data());
1132 propType.construct(variant.data(), a[0]);
1135 needActivate =
true;
1136 md->set(m_engine, id, m_engine->newVariantObject(
1141 qmlWarning(object.data()) <<
"Cannot find member data";
1147 activate(object.data(), id,
nullptr);
1155 if (id < aliasCount()) {
1156 const QV4::CompiledData::Object *compiledObject = findCompiledObject();
1157 if (!compiledObject)
1160 const QQmlPropertyData *aliasProperty = cache->property(aliasOffset() + id);
1161 if (c == QMetaObject::ReadProperty && aliasProperty && aliasProperty->isQObject())
1162 *
reinterpret_cast<
void **>(a[0]) =
nullptr;
1164 if (m_ctxt.isNull())
1167 QObject *target = m_ctxt->idValue(
1168 aliasProperty ? aliasProperty->aliasTargetObjectId() : -1);
1172 connectAlias(compiledObject, id);
1174 const int targetPropertyIndex = aliasProperty ? aliasProperty->aliasTarget() : -1;
1176 if (targetPropertyIndex == -1) {
1177 *
reinterpret_cast<QObject **>(a[0]) = target;
1181 QQmlData *targetDData = QQmlData::get(target,
false);
1185 QQmlPropertyIndex encodedIndex
1186 = QQmlPropertyIndex::fromEncoded(targetPropertyIndex);
1187 int coreIndex = encodedIndex.coreIndex();
1188 const int valueTypePropertyIndex = encodedIndex.valueTypeIndex();
1190 const auto removePendingBinding
1191 = [c, a](QObject *target,
int coreIndex, QQmlPropertyIndex encodedIndex) {
1193 if (c == QMetaObject::WriteProperty) {
1194 int flags = *
reinterpret_cast<
int*>(a[3]);
1195 if (flags & QQmlPropertyData::RemoveBindingOnAliasWrite) {
1196 QQmlData *targetData = QQmlData::get(target);
1197 if (targetData && targetData->hasBindingBit(coreIndex))
1198 QQmlPropertyPrivate::removeBinding(target, encodedIndex);
1203 if (valueTypePropertyIndex != -1) {
1204 if (!targetDData->propertyCache)
1206 const QQmlPropertyData *pd = targetDData->propertyCache->property(coreIndex);
1208 QQmlGadgetPtrWrapper *valueType = QQmlGadgetPtrWrapper::instance(
1209 m_ctxt->engine(), pd->propType());
1213 if (c == QMetaObject::BindableProperty)
1214 return QMetaObject::metacall(target, c, coreIndex, a);
1216 removePendingBinding(target, coreIndex, encodedIndex);
1217 valueType->read(target, coreIndex);
1218 int rv = QMetaObject::metacall(valueType, c, valueTypePropertyIndex, a);
1220 if (c == QMetaObject::WriteProperty)
1221 valueType->write(target, coreIndex, QQmlPropertyData::HasInternalIndex,
1222 valueTypePropertyIndex);
1227 void *argv[1] = { &target };
1228 QMetaObject::metacall(target, QMetaObject::ReadProperty, coreIndex, argv);
1229 removePendingBinding(
1230 target, valueTypePropertyIndex,
1231 QQmlPropertyIndex(valueTypePropertyIndex));
1232 return QMetaObject::metacall(target, c, valueTypePropertyIndex, a);
1236 removePendingBinding(target, coreIndex, encodedIndex);
1237 return QMetaObject::metacall(target, c, coreIndex, a);
1245 }
else if(c == QMetaObject::InvokeMetaMethod) {
1247 if (id >= signalOffset()) {
1249 id -= signalOffset();
1250 if (id < signalCount()) {
1251 activate(object.data(), id, a);
1255 id -= signalCount();
1256 if (id < methodCount()) {
1257 QQmlEngine *engine = m_ctxt->engine();
1261 QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine);
1262 QV4::ExecutionEngine *v4 = engine->handle();
1263 ep->referenceScarceResources();
1264 QV4::Scope scope(v4);
1267 QV4::Scoped<QV4::JavaScriptFunctionObject> function(scope, method(id));
1276 "Exception occurred during compilation of function: ")
1277 + QString::fromUtf8(metaObject->method(_id).methodSignature()));
1282 auto methodData = cache->method(_id);
1283 auto arguments = methodData->hasArguments() ? methodData->arguments() :
nullptr;
1285 if (arguments && arguments->names) {
1286 const quint32 parameterCount = arguments->names->size();
1287 Q_ASSERT(parameterCount == function->formalParameterCount());
1288 function->call(object.data(), a, arguments->types, parameterCount);
1290 Q_ASSERT(function->formalParameterCount() == 0);
1291 const QMetaType returnType = methodData->propType();
1292 function->call(object.data(), a, &returnType, 0);
1295 if (scope.hasException()) {
1296 QQmlError error = scope.engine->catchExceptionAsQmlError();
1297 if (error.isValid())
1301 ep->dereferenceScarceResources();
1309 return parent.asT1()->metaCall(object.data(), c, _id, a);
1311 return object->qt_metacall(c, _id, a);