diff --git a/src/qml/jsapi/qjsmanagedvalue.cpp b/src/qml/jsapi/qjsmanagedvalue.cpp index 8b2f367304..8d00ecb2f9 100644 --- a/src/qml/jsapi/qjsmanagedvalue.cpp +++ b/src/qml/jsapi/qjsmanagedvalue.cpp @@ -631,8 +631,8 @@ QVariant QJSManagedValue::toVariant() const return QVariant(d->doubleValue()); if (d->isString()) return QVariant(d->toQString()); - if (QV4::Managed *m = d->as()) - return m->engine()->toVariant(*d, QMetaType{}, true); + if (d->as()) + return QV4::ExecutionEngine::toVariant(*d, QMetaType{}, true); Q_UNREACHABLE(); return QVariant(); diff --git a/src/qml/jsapi/qjsvalue.cpp b/src/qml/jsapi/qjsvalue.cpp index 34fe760732..18ad1ebdfd 100644 --- a/src/qml/jsapi/qjsvalue.cpp +++ b/src/qml/jsapi/qjsvalue.cpp @@ -598,8 +598,10 @@ QVariant QJSValue::toVariant(QJSValue::ObjectConversionBehavior behavior) const if (val.isString()) return QVariant(val.toQString()); - if (QV4::Managed *m = val.as()) - return m->engine()->toVariant(val, /*typeHint*/ QMetaType{}, behavior == RetainJSObjects); + if (val.as()) { + return QV4::ExecutionEngine::toVariant( + val, /*typeHint*/ QMetaType{}, behavior == RetainJSObjects); + } Q_ASSERT(false); return QVariant(); diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index a66478d61e..43b3c6fa29 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -1493,9 +1493,9 @@ QQmlError ExecutionEngine::catchExceptionAsQmlError() // Variant conversion code typedef QSet V4ObjectSet; -static QVariant toVariant(QV4::ExecutionEngine *e, const QV4::Value &value, QMetaType typeHint, bool createJSValueForObjects, V4ObjectSet *visitedObjects); +static QVariant toVariant(const QV4::Value &value, QMetaType typeHint, bool createJSValueForObjects, V4ObjectSet *visitedObjects); static QObject *qtObjectFromJS(const QV4::Value &value); -static QVariant objectToVariant(QV4::ExecutionEngine *e, const QV4::Object *o, V4ObjectSet *visitedObjects = nullptr); +static QVariant objectToVariant(const QV4::Object *o, V4ObjectSet *visitedObjects = nullptr); static bool convertToNativeQObject(const QV4::Value &value, QMetaType targetType, void **result); static QV4::ReturnedValue variantListToJS(QV4::ExecutionEngine *v4, const QVariantList &lst); static QV4::ReturnedValue sequentialIterableToJS(QV4::ExecutionEngine *v4, const QSequentialIterable &lst); @@ -1505,10 +1505,11 @@ static QV4::ReturnedValue variantToJS(QV4::ExecutionEngine *v4, const QVariant & return v4->metaTypeToJS(value.metaType(), value.constData()); } -static QVariant toVariant(QV4::ExecutionEngine *e, const QV4::Value &value, QMetaType metaType, bool createJSValueForObjects, V4ObjectSet *visitedObjects) +static QVariant toVariant( + const QV4::Value &value, QMetaType metaType, bool createJSValueForObjects, + V4ObjectSet *visitedObjects) { Q_ASSERT (!value.isEmpty()); - QV4::Scope scope(e); if (const QV4::VariantObject *v = value.as()) return v->d()->data(); @@ -1522,8 +1523,9 @@ static QVariant toVariant(QV4::ExecutionEngine *e, const QV4::Value &value, QMet if (metaType == QMetaType::fromType()) return QVariant::fromValue(QJSValuePrivate::fromReturnedValue(value.asReturnedValue())); - if (value.as()) { - QV4::ScopedObject object(scope, value); + if (const QV4::Object *o = value.as()) { + QV4::Scope scope(o->engine()); + QV4::ScopedObject object(scope, o); if (metaType == QMetaType::fromType() && !value.as() && !value.as()) { return QVariant::fromValue(QV4::JsonObject::toJsonObject(object)); @@ -1542,8 +1544,9 @@ static QVariant toVariant(QV4::ExecutionEngine *e, const QV4::Value &value, QMet } } - if (value.as()) { - QV4::ScopedArrayObject a(scope, value); + if (const QV4::ArrayObject *o = value.as()) { + QV4::Scope scope(o->engine()); + QV4::ScopedArrayObject a(scope, o); if (metaType == QMetaType::fromType>()) { QList list; uint length = a->getLength(); @@ -1590,7 +1593,7 @@ static QVariant toVariant(QV4::ExecutionEngine *e, const QV4::Value &value, QMet } } - asVariant = toVariant(e, arrayValue, valueMetaType, false, visitedObjects); + asVariant = toVariant(arrayValue, valueMetaType, false, visitedObjects); if (valueMetaType == QMetaType::fromType()) { retnAsIterable.metaContainer().addValue(retn.data(), &asVariant); } else { @@ -1649,8 +1652,10 @@ static QVariant toVariant(QV4::ExecutionEngine *e, const QV4::Value &value, QMet return d->asByteArray(); // NOTE: since we convert QTime to JS Date, round trip will change the variant type (to QDateTime)! - QV4::ScopedObject o(scope, value); - Q_ASSERT(o); + const QV4::Object *object = value.as(); + Q_ASSERT(object); + QV4::Scope scope(object->engine()); + QV4::ScopedObject o(scope, object); #if QT_CONFIG(regularexpression) if (QV4::RegExpObject *re = o->as()) @@ -1660,16 +1665,16 @@ static QVariant toVariant(QV4::ExecutionEngine *e, const QV4::Value &value, QMet if (createJSValueForObjects) return QVariant::fromValue(QJSValuePrivate::fromReturnedValue(o->asReturnedValue())); - return objectToVariant(e, o, visitedObjects); + return objectToVariant(o, visitedObjects); } QVariant ExecutionEngine::toVariant(const Value &value, QMetaType typeHint, bool createJSValueForObjects) { - return ::toVariant(this, value, typeHint, createJSValueForObjects, nullptr); + return ::toVariant(value, typeHint, createJSValueForObjects, nullptr); } -static QVariant objectToVariant(QV4::ExecutionEngine *e, const QV4::Object *o, V4ObjectSet *visitedObjects) +static QVariant objectToVariant(const QV4::Object *o, V4ObjectSet *visitedObjects) { Q_ASSERT(o); @@ -1689,7 +1694,7 @@ static QVariant objectToVariant(QV4::ExecutionEngine *e, const QV4::Object *o, V QVariant result; if (o->as()) { - QV4::Scope scope(e); + QV4::Scope scope(o->engine()); QV4::ScopedArrayObject a(scope, o->asReturnedValue()); QV4::ScopedValue v(scope); QVariantList list; @@ -1697,7 +1702,7 @@ static QVariant objectToVariant(QV4::ExecutionEngine *e, const QV4::Object *o, V int length = a->getLength(); for (int ii = 0; ii < length; ++ii) { v = a->get(ii); - list << ::toVariant(e, v, QMetaType {}, /*createJSValueForObjects*/false, visitedObjects); + list << ::toVariant(v, QMetaType {}, /*createJSValueForObjects*/false, visitedObjects); } result = list; @@ -1706,7 +1711,7 @@ static QVariant objectToVariant(QV4::ExecutionEngine *e, const QV4::Object *o, V result = QVariant::fromValue(QJSValuePrivate::fromReturnedValue(f->asReturnedValue())); } else { QVariantMap map; - QV4::Scope scope(e); + QV4::Scope scope(o->engine()); QV4::ObjectIterator it(scope, o, QV4::ObjectIterator::EnumerableOnly); QV4::ScopedValue name(scope); QV4::ScopedValue val(scope); @@ -1716,7 +1721,9 @@ static QVariant objectToVariant(QV4::ExecutionEngine *e, const QV4::Object *o, V break; QString key = name->toQStringNoThrow(); - map.insert(key, ::toVariant(e, val, /*type hint*/ QMetaType {}, /*createJSValueForObjects*/false, visitedObjects)); + map.insert(key, ::toVariant( + val, /*type hint*/ QMetaType {}, + /*createJSValueForObjects*/false, visitedObjects)); } result = map; @@ -1893,7 +1900,7 @@ QV4::ReturnedValue QV4::ExecutionEngine::fromVariant(const QVariant &variant) QVariantMap ExecutionEngine::variantMapFromJS(const Object *o) { - return objectToVariant(this, o).toMap(); + return objectToVariant(o).toMap(); } @@ -2452,7 +2459,7 @@ bool ExecutionEngine::metaTypeFromJS(const Value &value, QMetaType metaType, voi case QMetaType::QVariantList: { const QV4::ArrayObject *a = value.as(); if (a) { - *reinterpret_cast(data) = a->engine()->toVariant( + *reinterpret_cast(data) = ExecutionEngine::toVariant( *a, /*typeHint*/QMetaType{}, /*createJSValueForObjects*/false).toList(); return true; } @@ -2467,18 +2474,20 @@ bool ExecutionEngine::metaTypeFromJS(const Value &value, QMetaType metaType, voi break; } case QMetaType::QVariant: - if (const QV4::Managed *m = value.as()) - *reinterpret_cast(data) = m->engine()->toVariant(value, /*typeHint*/QMetaType{}, /*createJSValueForObjects*/false); - else if (value.isNull()) + if (value.as()) { + *reinterpret_cast(data) = ExecutionEngine::toVariant( + value, /*typeHint*/QMetaType{}, /*createJSValueForObjects*/false); + } else if (value.isNull()) { *reinterpret_cast(data) = QVariant::fromValue(nullptr); - else if (value.isUndefined()) + } else if (value.isUndefined()) { *reinterpret_cast(data) = QVariant(); - else if (value.isBoolean()) + } else if (value.isBoolean()) { *reinterpret_cast(data) = QVariant(value.booleanValue()); - else if (value.isInteger()) + } else if (value.isInteger()) { *reinterpret_cast(data) = QVariant(value.integerValue()); - else if (value.isDouble()) + } else if (value.isDouble()) { *reinterpret_cast(data) = QVariant(value.doubleValue()); + } return true; case QMetaType::QJsonValue: *reinterpret_cast(data) = QV4::JsonObject::toJsonValue(value); diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h index aa79f89231..1bca525584 100644 --- a/src/qml/jsruntime/qv4engine_p.h +++ b/src/qml/jsruntime/qv4engine_p.h @@ -637,10 +637,11 @@ public: QQmlError catchExceptionAsQmlError(); // variant conversions - QVariant toVariant(const QV4::Value &value, QMetaType typeHint, bool createJSValueForObjects = true); + static QVariant toVariant( + const QV4::Value &value, QMetaType typeHint, bool createJSValueForObjects = true); QV4::ReturnedValue fromVariant(const QVariant &); - QVariantMap variantMapFromJS(const QV4::Object *o); + static QVariantMap variantMapFromJS(const QV4::Object *o); static bool metaTypeFromJS(const Value &value, QMetaType type, void *data); QV4::ReturnedValue metaTypeToJS(QMetaType type, const void *data); diff --git a/src/qml/jsruntime/qv4jscall_p.h b/src/qml/jsruntime/qv4jscall_p.h index 327b5bb510..cf62f2549e 100644 --- a/src/qml/jsruntime/qv4jscall_p.h +++ b/src/qml/jsruntime/qv4jscall_p.h @@ -207,7 +207,7 @@ bool convertAndCall(ExecutionEngine *engine, QObject *thisObject, // When the return type is QVariant, JS objects are to be returned as // QJSValue wrapped in QVariant. metaTypeFromJS unwraps them, unfortunately. if (resultType == QMetaType::fromType()) { - new (result) QVariant(scope.engine->toVariant(jsResult, QMetaType {})); + new (result) QVariant(ExecutionEngine::toVariant(jsResult, QMetaType {})); } else { resultType.construct(result); ExecutionEngine::metaTypeFromJS(jsResult, resultType, result); diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp index b744e45f26..54ef2c75b7 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper.cpp +++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp @@ -593,9 +593,9 @@ void QObjectWrapper::setProperty( } else { QVariant v; if (property->isQList() && propType.flags().testFlag(QMetaType::IsQmlList)) - v = scope.engine->toVariant(value, QMetaType::fromType >()); + v = ExecutionEngine::toVariant(value, QMetaType::fromType >()); else - v = scope.engine->toVariant(value, propType); + v = ExecutionEngine::toVariant(value, propType); QQmlRefPointer callingQmlContext = scope.engine->callingQmlContext(); if (!QQmlPropertyPrivate::write(object, *property, v, callingQmlContext)) { @@ -1514,7 +1514,7 @@ static int MatchScore(const Value &actual, QMetaType conversionMetaType) if (obj->as()) { if (conversionType == qMetaTypeId()) return 0; - if (obj->engine()->toVariant(actual, QMetaType {}).metaType() == conversionMetaType) + if (ExecutionEngine::toVariant(actual, QMetaType {}).metaType() == conversionMetaType) return 0; else return 10; @@ -1537,7 +1537,7 @@ static int MatchScore(const Value &actual, QMetaType conversionMetaType) } if (obj->as()) { - const QVariant v = obj->engine()->toVariant(actual, QMetaType {}); + const QVariant v = ExecutionEngine::toVariant(actual, QMetaType {}); if (v.userType() == conversionType) return 0; else if (v.canConvert(conversionMetaType)) @@ -1969,7 +1969,7 @@ bool CallArgument::fromValue(QMetaType metaType, ExecutionEngine *engine, const qobjectPtr = nullptr; return value.isNullOrUndefined(); // null and undefined are nullptr case QMetaType::QVariant: - qvariantPtr = new (&allocData) QVariant(engine->toVariant(value, QMetaType {})); + qvariantPtr = new (&allocData) QVariant(ExecutionEngine::toVariant(value, QMetaType {})); return true; case QMetaType::QJsonArray: { Scope scope(engine); @@ -2064,7 +2064,7 @@ bool CallArgument::fromValue(QMetaType metaType, ExecutionEngine *engine, const qvariantPtr = new (&allocData) QVariant(); type = QVariantWrappedType; - QVariant v = engine->toVariant(value, metaType); + QVariant v = ExecutionEngine::toVariant(value, metaType); if (v.metaType() == metaType) { *qvariantPtr = std::move(v); diff --git a/src/qml/jsruntime/qv4sequenceobject.cpp b/src/qml/jsruntime/qv4sequenceobject.cpp index 6ed27d9d02..cb36ece6a4 100644 --- a/src/qml/jsruntime/qv4sequenceobject.cpp +++ b/src/qml/jsruntime/qv4sequenceobject.cpp @@ -306,7 +306,7 @@ bool Sequence::containerPutIndexed(qsizetype index, const Value &value) const qsizetype count = size(); const QMetaType valueType = valueMetaType(d()); - const QVariant element = engine()->toVariant(value, valueType, false); + const QVariant element = ExecutionEngine::toVariant(value, valueType, false); if (index < 0) return false; @@ -643,7 +643,7 @@ QVariant SequencePrototype::toVariant(const QV4::Value &array, QMetaType typeHin QV4::ScopedValue v(scope); for (quint32 i = 0; i < quint32(length); ++i) { const QMetaType valueMetaType = priv->typeId; - QVariant variant = scope.engine->toVariant(a->get(i), valueMetaType, false); + QVariant variant = ExecutionEngine::toVariant(a->get(i), valueMetaType, false); if (valueMetaType == QMetaType::fromType()) { meta->addValueAtEnd(result.data(), &variant); } else { diff --git a/src/qml/qml/qqmlbinding.cpp b/src/qml/qml/qqmlbinding.cpp index d009381394..9020a544ac 100644 --- a/src/qml/qml/qqmlbinding.cpp +++ b/src/qml/qml/qqmlbinding.cpp @@ -466,9 +466,6 @@ Q_NEVER_INLINE bool QQmlBinding::slowWrite(const QQmlPropertyData &core, const QV4::Value &result, bool isUndefined, QQmlPropertyData::WriteFlags flags) { - QQmlEngine *qmlEngine = engine(); - QV4::ExecutionEngine *v4engine = qmlEngine->handle(); - const QMetaType metaType = valueTypeData.isValid() ? valueTypeData.propType() : core.propType(); const int type = metaType.id(); @@ -480,19 +477,19 @@ Q_NEVER_INLINE bool QQmlBinding::slowWrite(const QQmlPropertyData &core, if (isUndefined) { } else if (core.isQList()) { if (core.propType().flags() & QMetaType::IsQmlList) - value = v4engine->toVariant(result, QMetaType::fromType >()); + value = QV4::ExecutionEngine::toVariant(result, QMetaType::fromType>()); else - value = v4engine->toVariant(result, core.propType()); + value = QV4::ExecutionEngine::toVariant(result, core.propType()); } else if (result.isNull() && core.isQObject()) { value = QVariant::fromValue((QObject *)nullptr); } else if (core.propType() == QMetaType::fromType>()) { const QVariant resultVariant - = v4engine->toVariant(result, QMetaType::fromType>()); + = QV4::ExecutionEngine::toVariant(result, QMetaType::fromType>()); value = QVariant::fromValue(QQmlPropertyPrivate::resolveUrlsOnAssignment() ? QQmlPropertyPrivate::urlSequence(resultVariant, context()) : QQmlPropertyPrivate::urlSequence(resultVariant)); } else if (!isVarProperty && metaType != QMetaType::fromType()) { - value = v4engine->toVariant(result, metaType); + value = QV4::ExecutionEngine::toVariant(result, metaType); } if (hasError()) { @@ -595,7 +592,7 @@ QVariant QQmlBinding::evaluate() ep->dereferenceScarceResources(); - return scope.engine->toVariant(result, QMetaType::fromType >()); + return QV4::ExecutionEngine::toVariant(result, QMetaType::fromType >()); } void QQmlBinding::expressionChanged() diff --git a/src/qml/qml/qqmlexpression.cpp b/src/qml/qml/qqmlexpression.cpp index ecece668d3..7e4483a604 100644 --- a/src/qml/qml/qqmlexpression.cpp +++ b/src/qml/qml/qqmlexpression.cpp @@ -243,7 +243,7 @@ QVariant QQmlExpressionPrivate::value(bool *isUndefined) QV4::Scope scope(engine->handle()); QV4::ScopedValue result(scope, v4value(isUndefined)); if (!hasError()) - rv = scope.engine->toVariant(result, QMetaType {}); + rv = QV4::ExecutionEngine::toVariant(result, QMetaType {}); } ep->dereferenceScarceResources(); // "release" scarce resources if top-level expression evaluation is complete. diff --git a/src/qml/qml/qqmlpropertybinding_p.h b/src/qml/qml/qqmlpropertybinding_p.h index 9973fe42d7..50688fa245 100644 --- a/src/qml/qml/qqmlpropertybinding_p.h +++ b/src/qml/qml/qqmlpropertybinding_p.h @@ -398,7 +398,7 @@ bool QQmlPropertyBinding::evaluate(QMetaType metaType, void *dataPtr) break; } - QVariant resultVariant(scope.engine->toVariant(result, metaType)); + QVariant resultVariant(QV4::ExecutionEngine::toVariant(result, metaType)); resultVariant.convert(metaType); const bool hasChanged = !metaType.equals(resultVariant.constData(), dataPtr); metaType.destruct(dataPtr); diff --git a/src/qml/qml/qqmlvaluetypewrapper.cpp b/src/qml/qml/qqmlvaluetypewrapper.cpp index 1ded94983e..9e08882b59 100644 --- a/src/qml/qml/qqmlvaluetypewrapper.cpp +++ b/src/qml/qml/qqmlvaluetypewrapper.cpp @@ -662,7 +662,7 @@ bool QQmlValueTypeWrapper::virtualPut(Managed *m, PropertyKey id, const Value &v QMetaProperty property = metaObject->property(pd.coreIndex()); Q_ASSERT(property.isValid()); - QVariant v = v4->toVariant(value, property.metaType()); + QVariant v = QV4::ExecutionEngine::toVariant(value, property.metaType()); if (property.isEnumType() && (QMetaType::Type)v.userType() == QMetaType::Double) v = v.toInt(); diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index 59dbfdf5f1..46e5ad96da 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -1110,7 +1110,7 @@ QVariant QQmlVMEMetaObject::readPropertyAsVariant(int id) const const QV4::VariantObject *v = (md->data() + id)->as(); if (v) return v->d()->data(); - return engine->toVariant(*(md->data() + id), QMetaType {}); + return QV4::ExecutionEngine::toVariant(*(md->data() + id), QMetaType {}); } return QVariant(); } diff --git a/src/qmllocalstorage/qqmllocalstorage.cpp b/src/qmllocalstorage/qqmllocalstorage.cpp index 073b3c790f..e3b0159c09 100644 --- a/src/qmllocalstorage/qqmllocalstorage.cpp +++ b/src/qmllocalstorage/qqmllocalstorage.cpp @@ -223,13 +223,13 @@ static ReturnedValue qmlsqldatabase_rows_item(const FunctionObject *b, const Val RETURN_RESULT(qmlsqldatabase_rows_index(r, scope.engine, argc ? argv[0].toUInt32() : 0)); } -static QVariant toSqlVariant(QV4::ExecutionEngine *engine, const QV4::ScopedValue &value) +static QVariant toSqlVariant(const QV4::ScopedValue &value) { // toVariant() maps a null JS value to QVariant(VoidStar), but the SQL module // expects a null variant. (this is because of QTBUG-40880) if (value->isNull()) return QVariant(); - return engine->toVariant(value, /*typehint*/ QMetaType {}); + return QV4::ExecutionEngine::toVariant(value, /*typehint*/ QMetaType {}); } static ReturnedValue qmlsqldatabase_executeSql(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) @@ -263,7 +263,7 @@ static ReturnedValue qmlsqldatabase_executeSql(const FunctionObject *b, const Va quint32 size = array->getLength(); QV4::ScopedValue v(scope); for (quint32 ii = 0; ii < size; ++ii) { - query.bindValue(ii, toSqlVariant(scope.engine, (v = array->get(ii)))); + query.bindValue(ii, toSqlVariant((v = array->get(ii)))); } } else if (values->as()) { ScopedObject object(scope, values); @@ -274,7 +274,7 @@ static ReturnedValue qmlsqldatabase_executeSql(const FunctionObject *b, const Va key = it.nextPropertyName(val); if (key->isNull()) break; - QVariant v = toSqlVariant(scope.engine, val); + QVariant v = toSqlVariant(val); if (key->isString()) { query.bindValue(key->stringValue()->toQString(), v); } else { @@ -283,7 +283,7 @@ static ReturnedValue qmlsqldatabase_executeSql(const FunctionObject *b, const Va } } } else { - query.bindValue(0, toSqlVariant(scope.engine, values)); + query.bindValue(0, toSqlVariant(values)); } } if (query.exec()) { diff --git a/src/qmlmodels/qqmladaptormodel.cpp b/src/qmlmodels/qqmladaptormodel.cpp index 080cd90aa6..e046509151 100644 --- a/src/qmlmodels/qqmladaptormodel.cpp +++ b/src/qmlmodels/qqmladaptormodel.cpp @@ -333,10 +333,11 @@ QV4::ReturnedValue QQmlDMCachedModelData::set_property(const QV4::FunctionObject QQmlDMCachedModelData *modelData = static_cast(o->d()->item); if (!modelData->cachedData.isEmpty()) { if (modelData->cachedData.count() > 1) { - modelData->cachedData[propertyId] = scope.engine->toVariant(argv[0], QMetaType {}); + modelData->cachedData[propertyId] + = QV4::ExecutionEngine::toVariant(argv[0], QMetaType {}); QMetaObject::activate(o->d()->item, o->d()->item->metaObject(), propertyId, nullptr); } else if (modelData->cachedData.count() == 1) { - modelData->cachedData[0] = scope.engine->toVariant(argv[0], QMetaType {}); + modelData->cachedData[0] = QV4::ExecutionEngine::toVariant(argv[0], QMetaType {}); QMetaObject::activate(o->d()->item, o->d()->item->metaObject(), 0, nullptr); QMetaObject::activate(o->d()->item, o->d()->item->metaObject(), 1, nullptr); } @@ -568,7 +569,8 @@ public: if (!argc) return v4->throwTypeError(); - static_cast(o->d()->item)->setModelData(v4->toVariant(argv[0], QMetaType {})); + static_cast(o->d()->item)->setModelData( + QV4::ExecutionEngine::toVariant(argv[0], QMetaType {})); return QV4::Encode::undefined(); } diff --git a/src/qmlmodels/qqmldelegatemodel.cpp b/src/qmlmodels/qqmldelegatemodel.cpp index 7222b6cb93..9ec34704a2 100644 --- a/src/qmlmodels/qqmldelegatemodel.cpp +++ b/src/qmlmodels/qqmldelegatemodel.cpp @@ -2039,7 +2039,9 @@ bool QQmlDelegateModelPrivate::insert(Compositor::insert_iterator &before, const propertyName = it.nextPropertyNameAsString(v); if (propertyName->isNull()) break; - cacheItem->setValue(propertyName->toQStringNoThrow(), scope.engine->toVariant(v, QMetaType {})); + cacheItem->setValue( + propertyName->toQStringNoThrow(), + QV4::ExecutionEngine::toVariant(v, QMetaType {})); } cacheItem->groups = groups | Compositor::UnresolvedFlag | Compositor::CacheFlag; diff --git a/src/qmlmodels/qqmllistmodel.cpp b/src/qmlmodels/qqmllistmodel.cpp index 4a3d582cb1..457c9b9e67 100644 --- a/src/qmlmodels/qqmllistmodel.cpp +++ b/src/qmlmodels/qqmllistmodel.cpp @@ -622,7 +622,8 @@ void ListModel::set(int elementIndex, QV4::Object *object, QVector *roles) const ListLayout::Role &role = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::QObject); if (role.type == ListLayout::Role::QObject) roleIndex = e->setQObjectProperty(role, o); - } else if (QVariant maybeUrl = o->engine()->toVariant(o->asReturnedValue(), QMetaType::fromType(), true); + } else if (QVariant maybeUrl = QV4::ExecutionEngine::toVariant( + o->asReturnedValue(), QMetaType::fromType(), true); maybeUrl.metaType() == QMetaType::fromType()) { const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::Url); QUrl qurl = maybeUrl.toUrl(); @@ -714,7 +715,8 @@ void ListModel::set(int elementIndex, QV4::Object *object, ListModel::SetElement if (r.type == ListLayout::Role::QObject) e->setQObjectPropertyFast(r, o); } else { - QVariant maybeUrl = o->engine()->toVariant(o->asReturnedValue(), QMetaType::fromType(), true); + QVariant maybeUrl = QV4::ExecutionEngine::toVariant( + o->asReturnedValue(), QMetaType::fromType(), true); if (maybeUrl.metaType() == QMetaType::fromType()) { const QUrl qurl = maybeUrl.toUrl(); const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::Url); @@ -1598,7 +1600,8 @@ int ListElement::setJsProperty(const ListLayout::Role &role, const QV4::Value &d } else if (role.type == ListLayout::Role::VariantMap) { roleIndex = setVariantMapProperty(role, o); } else if (role.type == ListLayout::Role::Url) { - QVariant maybeUrl = o->engine()->toVariant(o.asReturnedValue(), QMetaType::fromType(), true); + QVariant maybeUrl = QV4::ExecutionEngine::toVariant( + o.asReturnedValue(), QMetaType::fromType(), true); if (maybeUrl.metaType() == QMetaType::fromType()) { roleIndex = setUrlProperty(role, maybeUrl.toUrl()); } diff --git a/src/qmltest/quicktestresult.cpp b/src/qmltest/quicktestresult.cpp index 7b1a379214..9c8cc533aa 100644 --- a/src/qmltest/quicktestresult.cpp +++ b/src/qmltest/quicktestresult.cpp @@ -520,7 +520,7 @@ void QuickTestResult::stringify(QQmlV4Function *args) if (value->isObject() && !value->as() && !value->as()) { - QVariant v = scope.engine->toVariant(value, QMetaType {}); + QVariant v = QV4::ExecutionEngine::toVariant(value, QMetaType {}); if (v.isValid()) { switch (v.userType()) { case QMetaType::QVector3D: diff --git a/src/qmlworkerscript/qv4serialize.cpp b/src/qmlworkerscript/qv4serialize.cpp index 1906d164f6..fda96cf763 100644 --- a/src/qmlworkerscript/qv4serialize.cpp +++ b/src/qmlworkerscript/qv4serialize.cpp @@ -225,7 +225,8 @@ void Serialize::serialize(QByteArray &data, const QV4::Value &v, ExecutionEngine return; } else if (const Object *o = v.as()) { - const QVariant variant = engine->toVariant(v, QMetaType::fromType(), false); + const QVariant variant = QV4::ExecutionEngine::toVariant( + v, QMetaType::fromType(), false); if (variant.userType() == QMetaType::QUrl) { serializeString(data, variant.value().toString(), WorkerUrl); return; diff --git a/src/quick/items/context2d/qquickcontext2d.cpp b/src/quick/items/context2d/qquickcontext2d.cpp index d2e24a8b30..491cf1108c 100644 --- a/src/quick/items/context2d/qquickcontext2d.cpp +++ b/src/quick/items/context2d/qquickcontext2d.cpp @@ -1397,7 +1397,7 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_fillStyle(const QV4::FunctionOb QV4::ScopedValue value(scope, argc ? argv[0] : QV4::Value::undefinedValue()); if (value->as()) { - QColor color = scope.engine->toVariant(value, QMetaType::fromType()).value(); + QColor color = QV4::ExecutionEngine::toVariant(value, QMetaType::fromType()).value(); if (color.isValid()) { r->d()->context()->state.fillStyle = color; r->d()->context()->buffer()->setFillStyle(color); @@ -1506,7 +1506,7 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_strokeStyle(const QV4::Function QV4::ScopedValue value(scope, argc ? argv[0] : QV4::Value::undefinedValue()); if (value->as()) { - QColor color = scope.engine->toVariant(value, QMetaType::fromType()).value(); + QColor color = QV4::ExecutionEngine::toVariant(value, QMetaType::fromType()).value(); if (color.isValid()) { r->d()->context()->state.strokeStyle = color; r->d()->context()->buffer()->setStrokeStyle(color); @@ -1738,7 +1738,8 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_createPattern(const QV4::F if (argc >= 2) { QV4::Scoped pattern(scope, scope.engine->memoryManager->allocate()); - QColor color = scope.engine->toVariant(argv[0], QMetaType::fromType()).value(); + QColor color = QV4::ExecutionEngine::toVariant( + argv[0], QMetaType::fromType()).value(); if (color.isValid()) { int patternMode = argv[1].toInt32(); Qt::BrushStyle style = Qt::SolidPattern; @@ -3552,7 +3553,8 @@ QV4::ReturnedValue QQuickContext2DStyle::gradient_proto_addColorStop(const QV4:: QColor color; if (argv[1].as()) { - color = scope.engine->toVariant(argv[1], QMetaType::fromType()).value(); + color = QV4::ExecutionEngine::toVariant( + argv[1], QMetaType::fromType()).value(); } else { color = qt_color_from_string(argv[1]); } diff --git a/src/quicktemplates2/qquickmenu.cpp b/src/quicktemplates2/qquickmenu.cpp index a61ca0bd00..d71054e972 100644 --- a/src/quicktemplates2/qquickmenu.cpp +++ b/src/quicktemplates2/qquickmenu.cpp @@ -1368,7 +1368,7 @@ void QQuickMenu::popup(QQmlV4Function *args) if (pos.isNull && (len >= 2 || (!parentItem && len >= 1))) { // point pos QV4::ScopedValue posArg(scope, (*args)[parentItem ? 1 : 0]); - const QVariant var = v4->toVariant(posArg, QMetaType {}); + const QVariant var = QV4::ExecutionEngine::toVariant(posArg, QMetaType {}); if (var.userType() == QMetaType::QPointF) pos = var.toPointF(); } diff --git a/src/quicktemplates2/qquickstackview_p.cpp b/src/quicktemplates2/qquickstackview_p.cpp index 23cdf0c41e..817ae092ae 100644 --- a/src/quicktemplates2/qquickstackview_p.cpp +++ b/src/quicktemplates2/qquickstackview_p.cpp @@ -149,8 +149,8 @@ QQuickStackElement *QQuickStackViewPrivate::createElement(const QV4::Value &valu if (const QV4::UrlObject *u = value.as()) return QQuickStackElement::fromString(resolvedUrl(u->href(), context), q, error); - if (const QV4::Object *v = value.as()) { - const QVariant data = v->engine()->toVariant(value, QMetaType::fromType()); + if (value.as()) { + const QVariant data = QV4::ExecutionEngine::toVariant(value, QMetaType::fromType()); if (data.typeId() == QMetaType::QUrl) { return QQuickStackElement::fromString(resolvedUrl(data.toUrl(), context).toString(), q, error); diff --git a/tests/auto/qml/qqmlecmascript/testtypes.h b/tests/auto/qml/qqmlecmascript/testtypes.h index de8871129d..da882d7840 100644 --- a/tests/auto/qml/qqmlecmascript/testtypes.h +++ b/tests/auto/qml/qqmlecmascript/testtypes.h @@ -924,7 +924,7 @@ public: QV4::Scope scope(v->v4engine()); for (int i = 0, end = v->length(); i != end; ++i) { QV4::ScopedValue v4Value(scope, (*v)[i]); - m_actuals.append(v->v4engine()->toVariant(v4Value, QMetaType())); + m_actuals.append(QV4::ExecutionEngine::toVariant(v4Value, QMetaType())); } } Q_INVOKABLE void method_overload2(const QVariantList &list) diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 10dd2ec823..340b1a148d 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -2918,7 +2918,7 @@ void tst_qqmlecmascript::callQtInvokables() { QV4::ScopedValue ret(scope, EVALUATE("object.method_NoArgs_QPointF()")); QVERIFY(!ret->isUndefined()); - QCOMPARE(scope.engine->toVariant(ret, QMetaType {}), QVariant(QPointF(123, 4.5))); + QCOMPARE(QV4::ExecutionEngine::toVariant(ret, QMetaType {}), QVariant(QPointF(123, 4.5))); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 3); QCOMPARE(o->actuals().count(), 0);