V4: Make ExecutionEngine::toVariant() static
Wherever we need an engine in there, we also have a managed value to get it from. This relieves us from the requirement to drag an engine around wherever we want to call toVariant(). Change-Id: Ib95d02b5fbf5eaa494214e337c9b700e97e5e0df Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
parent
85ba26c644
commit
a2db40e6c0
|
@ -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<QV4::Managed>())
|
||||
return m->engine()->toVariant(*d, QMetaType{}, true);
|
||||
if (d->as<QV4::Managed>())
|
||||
return QV4::ExecutionEngine::toVariant(*d, QMetaType{}, true);
|
||||
|
||||
Q_UNREACHABLE();
|
||||
return QVariant();
|
||||
|
|
|
@ -598,8 +598,10 @@ QVariant QJSValue::toVariant(QJSValue::ObjectConversionBehavior behavior) const
|
|||
|
||||
if (val.isString())
|
||||
return QVariant(val.toQString());
|
||||
if (QV4::Managed *m = val.as<QV4::Managed>())
|
||||
return m->engine()->toVariant(val, /*typeHint*/ QMetaType{}, behavior == RetainJSObjects);
|
||||
if (val.as<QV4::Managed>()) {
|
||||
return QV4::ExecutionEngine::toVariant(
|
||||
val, /*typeHint*/ QMetaType{}, behavior == RetainJSObjects);
|
||||
}
|
||||
|
||||
Q_ASSERT(false);
|
||||
return QVariant();
|
||||
|
|
|
@ -1493,9 +1493,9 @@ QQmlError ExecutionEngine::catchExceptionAsQmlError()
|
|||
// Variant conversion code
|
||||
|
||||
typedef QSet<QV4::Heap::Object *> 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<QV4::VariantObject>())
|
||||
return v->d()->data();
|
||||
|
@ -1522,8 +1523,9 @@ static QVariant toVariant(QV4::ExecutionEngine *e, const QV4::Value &value, QMet
|
|||
if (metaType == QMetaType::fromType<QJSValue>())
|
||||
return QVariant::fromValue(QJSValuePrivate::fromReturnedValue(value.asReturnedValue()));
|
||||
|
||||
if (value.as<QV4::Object>()) {
|
||||
QV4::ScopedObject object(scope, value);
|
||||
if (const QV4::Object *o = value.as<QV4::Object>()) {
|
||||
QV4::Scope scope(o->engine());
|
||||
QV4::ScopedObject object(scope, o);
|
||||
if (metaType == QMetaType::fromType<QJsonObject>()
|
||||
&& !value.as<ArrayObject>() && !value.as<FunctionObject>()) {
|
||||
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<ArrayObject>()) {
|
||||
QV4::ScopedArrayObject a(scope, value);
|
||||
if (const QV4::ArrayObject *o = value.as<ArrayObject>()) {
|
||||
QV4::Scope scope(o->engine());
|
||||
QV4::ScopedArrayObject a(scope, o);
|
||||
if (metaType == QMetaType::fromType<QList<QObject *>>()) {
|
||||
QList<QObject *> 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<QVariant>()) {
|
||||
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<QV4::Object>();
|
||||
Q_ASSERT(object);
|
||||
QV4::Scope scope(object->engine());
|
||||
QV4::ScopedObject o(scope, object);
|
||||
|
||||
#if QT_CONFIG(regularexpression)
|
||||
if (QV4::RegExpObject *re = o->as<QV4::RegExpObject>())
|
||||
|
@ -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<ArrayObject>()) {
|
||||
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<QV4::ArrayObject>();
|
||||
if (a) {
|
||||
*reinterpret_cast<QVariantList *>(data) = a->engine()->toVariant(
|
||||
*reinterpret_cast<QVariantList *>(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<QV4::Managed>())
|
||||
*reinterpret_cast<QVariant*>(data) = m->engine()->toVariant(value, /*typeHint*/QMetaType{}, /*createJSValueForObjects*/false);
|
||||
else if (value.isNull())
|
||||
if (value.as<QV4::Managed>()) {
|
||||
*reinterpret_cast<QVariant*>(data) = ExecutionEngine::toVariant(
|
||||
value, /*typeHint*/QMetaType{}, /*createJSValueForObjects*/false);
|
||||
} else if (value.isNull()) {
|
||||
*reinterpret_cast<QVariant*>(data) = QVariant::fromValue(nullptr);
|
||||
else if (value.isUndefined())
|
||||
} else if (value.isUndefined()) {
|
||||
*reinterpret_cast<QVariant*>(data) = QVariant();
|
||||
else if (value.isBoolean())
|
||||
} else if (value.isBoolean()) {
|
||||
*reinterpret_cast<QVariant*>(data) = QVariant(value.booleanValue());
|
||||
else if (value.isInteger())
|
||||
} else if (value.isInteger()) {
|
||||
*reinterpret_cast<QVariant*>(data) = QVariant(value.integerValue());
|
||||
else if (value.isDouble())
|
||||
} else if (value.isDouble()) {
|
||||
*reinterpret_cast<QVariant*>(data) = QVariant(value.doubleValue());
|
||||
}
|
||||
return true;
|
||||
case QMetaType::QJsonValue:
|
||||
*reinterpret_cast<QJsonValue *>(data) = QV4::JsonObject::toJsonValue(value);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<QVariant>()) {
|
||||
new (result) QVariant(scope.engine->toVariant(jsResult, QMetaType {}));
|
||||
new (result) QVariant(ExecutionEngine::toVariant(jsResult, QMetaType {}));
|
||||
} else {
|
||||
resultType.construct(result);
|
||||
ExecutionEngine::metaTypeFromJS(jsResult, resultType, result);
|
||||
|
|
|
@ -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<QList<QObject *> >());
|
||||
v = ExecutionEngine::toVariant(value, QMetaType::fromType<QList<QObject *> >());
|
||||
else
|
||||
v = scope.engine->toVariant(value, propType);
|
||||
v = ExecutionEngine::toVariant(value, propType);
|
||||
|
||||
QQmlRefPointer<QQmlContextData> 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<VariantObject>()) {
|
||||
if (conversionType == qMetaTypeId<QVariant>())
|
||||
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<QQmlValueTypeWrapper>()) {
|
||||
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);
|
||||
|
|
|
@ -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<QVariant>()) {
|
||||
meta->addValueAtEnd(result.data(), &variant);
|
||||
} else {
|
||||
|
|
|
@ -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<QList<QObject *> >());
|
||||
value = QV4::ExecutionEngine::toVariant(result, QMetaType::fromType<QList<QObject*>>());
|
||||
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<QList<QUrl>>()) {
|
||||
const QVariant resultVariant
|
||||
= v4engine->toVariant(result, QMetaType::fromType<QList<QUrl>>());
|
||||
= QV4::ExecutionEngine::toVariant(result, QMetaType::fromType<QList<QUrl>>());
|
||||
value = QVariant::fromValue(QQmlPropertyPrivate::resolveUrlsOnAssignment()
|
||||
? QQmlPropertyPrivate::urlSequence(resultVariant, context())
|
||||
: QQmlPropertyPrivate::urlSequence(resultVariant));
|
||||
} else if (!isVarProperty && metaType != QMetaType::fromType<QJSValue>()) {
|
||||
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<QList<QObject*> >());
|
||||
return QV4::ExecutionEngine::toVariant(result, QMetaType::fromType<QList<QObject*> >());
|
||||
}
|
||||
|
||||
void QQmlBinding::expressionChanged()
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -1110,7 +1110,7 @@ QVariant QQmlVMEMetaObject::readPropertyAsVariant(int id) const
|
|||
const QV4::VariantObject *v = (md->data() + id)->as<QV4::VariantObject>();
|
||||
if (v)
|
||||
return v->d()->data();
|
||||
return engine->toVariant(*(md->data() + id), QMetaType {});
|
||||
return QV4::ExecutionEngine::toVariant(*(md->data() + id), QMetaType {});
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
|
|
@ -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<Object>()) {
|
||||
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()) {
|
||||
|
|
|
@ -333,10 +333,11 @@ QV4::ReturnedValue QQmlDMCachedModelData::set_property(const QV4::FunctionObject
|
|||
QQmlDMCachedModelData *modelData = static_cast<QQmlDMCachedModelData *>(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<QQmlDMListAccessorData *>(o->d()->item)->setModelData(v4->toVariant(argv[0], QMetaType {}));
|
||||
static_cast<QQmlDMListAccessorData *>(o->d()->item)->setModelData(
|
||||
QV4::ExecutionEngine::toVariant(argv[0], QMetaType {}));
|
||||
return QV4::Encode::undefined();
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -622,7 +622,8 @@ void ListModel::set(int elementIndex, QV4::Object *object, QVector<int> *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<QUrl>(), true);
|
||||
} else if (QVariant maybeUrl = QV4::ExecutionEngine::toVariant(
|
||||
o->asReturnedValue(), QMetaType::fromType<QUrl>(), true);
|
||||
maybeUrl.metaType() == QMetaType::fromType<QUrl>()) {
|
||||
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<QUrl>(), true);
|
||||
QVariant maybeUrl = QV4::ExecutionEngine::toVariant(
|
||||
o->asReturnedValue(), QMetaType::fromType<QUrl>(), true);
|
||||
if (maybeUrl.metaType() == QMetaType::fromType<QUrl>()) {
|
||||
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<QUrl>(), true);
|
||||
QVariant maybeUrl = QV4::ExecutionEngine::toVariant(
|
||||
o.asReturnedValue(), QMetaType::fromType<QUrl>(), true);
|
||||
if (maybeUrl.metaType() == QMetaType::fromType<QUrl>()) {
|
||||
roleIndex = setUrlProperty(role, maybeUrl.toUrl());
|
||||
}
|
||||
|
|
|
@ -520,7 +520,7 @@ void QuickTestResult::stringify(QQmlV4Function *args)
|
|||
if (value->isObject()
|
||||
&& !value->as<QV4::FunctionObject>()
|
||||
&& !value->as<QV4::ArrayObject>()) {
|
||||
QVariant v = scope.engine->toVariant(value, QMetaType {});
|
||||
QVariant v = QV4::ExecutionEngine::toVariant(value, QMetaType {});
|
||||
if (v.isValid()) {
|
||||
switch (v.userType()) {
|
||||
case QMetaType::QVector3D:
|
||||
|
|
|
@ -225,7 +225,8 @@ void Serialize::serialize(QByteArray &data, const QV4::Value &v, ExecutionEngine
|
|||
|
||||
return;
|
||||
} else if (const Object *o = v.as<Object>()) {
|
||||
const QVariant variant = engine->toVariant(v, QMetaType::fromType<QUrl>(), false);
|
||||
const QVariant variant = QV4::ExecutionEngine::toVariant(
|
||||
v, QMetaType::fromType<QUrl>(), false);
|
||||
if (variant.userType() == QMetaType::QUrl) {
|
||||
serializeString(data, variant.value<QUrl>().toString(), WorkerUrl);
|
||||
return;
|
||||
|
|
|
@ -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<Object>()) {
|
||||
QColor color = scope.engine->toVariant(value, QMetaType::fromType<QColor>()).value<QColor>();
|
||||
QColor color = QV4::ExecutionEngine::toVariant(value, QMetaType::fromType<QColor>()).value<QColor>();
|
||||
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<Object>()) {
|
||||
QColor color = scope.engine->toVariant(value, QMetaType::fromType<QColor>()).value<QColor>();
|
||||
QColor color = QV4::ExecutionEngine::toVariant(value, QMetaType::fromType<QColor>()).value<QColor>();
|
||||
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<QQuickContext2DStyle> pattern(scope, scope.engine->memoryManager->allocate<QQuickContext2DStyle>());
|
||||
|
||||
QColor color = scope.engine->toVariant(argv[0], QMetaType::fromType<QColor>()).value<QColor>();
|
||||
QColor color = QV4::ExecutionEngine::toVariant(
|
||||
argv[0], QMetaType::fromType<QColor>()).value<QColor>();
|
||||
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<Object>()) {
|
||||
color = scope.engine->toVariant(argv[1], QMetaType::fromType<QColor>()).value<QColor>();
|
||||
color = QV4::ExecutionEngine::toVariant(
|
||||
argv[1], QMetaType::fromType<QColor>()).value<QColor>();
|
||||
} else {
|
||||
color = qt_color_from_string(argv[1]);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -149,8 +149,8 @@ QQuickStackElement *QQuickStackViewPrivate::createElement(const QV4::Value &valu
|
|||
if (const QV4::UrlObject *u = value.as<QV4::UrlObject>())
|
||||
return QQuickStackElement::fromString(resolvedUrl(u->href(), context), q, error);
|
||||
|
||||
if (const QV4::Object *v = value.as<QV4::Object>()) {
|
||||
const QVariant data = v->engine()->toVariant(value, QMetaType::fromType<QUrl>());
|
||||
if (value.as<QV4::Object>()) {
|
||||
const QVariant data = QV4::ExecutionEngine::toVariant(value, QMetaType::fromType<QUrl>());
|
||||
if (data.typeId() == QMetaType::QUrl) {
|
||||
return QQuickStackElement::fromString(resolvedUrl(data.toUrl(), context).toString(), q,
|
||||
error);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue