aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-10-19 15:22:25 +0200
committerUlf Hermann <ulf.hermann@qt.io>2021-10-20 15:51:23 +0200
commitbf115a446c1a633a11577306eff8a78028a7f5b5 (patch)
tree8a2cd7650fe9d5ace7bdfdaa31669fccd8f1021a /src/qml/jsruntime
parent974e2c668ae6e942f9e5d3eda8d77b1893af371f (diff)
Improve type conversions from/to QJSValue
We can convert everything into a QJSValue if we have an engine and we can save a binding function in a QVariant by wrapping it into QJSValue. Change-Id: I48e7c13f3f744f1c50bf673b427fe9331250f313 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r--src/qml/jsruntime/qv4engine.cpp5
-rw-r--r--src/qml/jsruntime/qv4qobjectwrapper.cpp4
-rw-r--r--src/qml/jsruntime/qv4qobjectwrapper_p.h5
3 files changed, 10 insertions, 4 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp
index 93a15669ee..a5f3336584 100644
--- a/src/qml/jsruntime/qv4engine.cpp
+++ b/src/qml/jsruntime/qv4engine.cpp
@@ -1708,7 +1708,10 @@ static QVariant objectToVariant(QV4::ExecutionEngine *e, const QV4::Object *o, V
}
result = list;
- } else if (!o->as<FunctionObject>()) {
+ } else if (const FunctionObject *f = o->as<FunctionObject>()) {
+ // If it's a FunctionObject, we can only save it as QJSValue.
+ result = QVariant::fromValue(QJSValuePrivate::fromReturnedValue(f->asReturnedValue()));
+ } else {
QVariantMap map;
QV4::Scope scope(e);
QV4::ObjectIterator it(scope, o, QV4::ObjectIterator::EnumerableOnly);
diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp
index 6657f3d6fc..517fbab6f1 100644
--- a/src/qml/jsruntime/qv4qobjectwrapper.cpp
+++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp
@@ -475,7 +475,9 @@ bool QObjectWrapper::setQmlProperty(
return true;
}
-void QObjectWrapper::setProperty(ExecutionEngine *engine, QObject *object, QQmlPropertyData *property, const Value &value)
+void QObjectWrapper::setProperty(
+ ExecutionEngine *engine, QObject *object,
+ const QQmlPropertyData *property, const Value &value)
{
if (!property->isWritable() && !property->isQList()) {
QString error = QLatin1String("Cannot assign to read-only property \"") +
diff --git a/src/qml/jsruntime/qv4qobjectwrapper_p.h b/src/qml/jsruntime/qv4qobjectwrapper_p.h
index 37cb4d3cac..f90ce06d58 100644
--- a/src/qml/jsruntime/qv4qobjectwrapper_p.h
+++ b/src/qml/jsruntime/qv4qobjectwrapper_p.h
@@ -183,6 +183,9 @@ struct Q_QML_EXPORT QObjectWrapper : public Object
static void setProperty(ExecutionEngine *engine, QObject *object, int propertyIndex, const Value &value);
void setProperty(ExecutionEngine *engine, int propertyIndex, const Value &value);
+ static void setProperty(
+ ExecutionEngine *engine, QObject *object,
+ const QQmlPropertyData *property, const Value &value);
void destroyObject(bool lastCall);
@@ -198,8 +201,6 @@ struct Q_QML_EXPORT QObjectWrapper : public Object
static bool virtualResolveLookupSetter(Object *object, ExecutionEngine *engine, Lookup *lookup, const Value &value);
protected:
- static void setProperty(ExecutionEngine *engine, QObject *object, QQmlPropertyData *property, const Value &value);
-
static bool virtualIsEqualTo(Managed *that, Managed *o);
static ReturnedValue create(ExecutionEngine *engine, QObject *object);