aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsapi
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2023-03-07 12:41:58 +0100
committerUlf Hermann <ulf.hermann@qt.io>2023-03-07 13:43:58 +0100
commit1fc13ba08af467e54670ab7b5d2ae9484b91c4a9 (patch)
tree5e504336a3c46000b0ae0875e6eee9879081d2d7 /src/qml/jsapi
parentac0a6ff966acfaf00ee0903581e30e5b1ac01aeb (diff)
QJSEngine: scope the results of fromData() and fromVariant()
Otherwise the gc might collect them while we're still operating on them. Pick-to: 6.2 6.5 Change-Id: I4644ff7b4b1221f3e58832a245d71215e77bd891 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/jsapi')
-rw-r--r--src/qml/jsapi/qjsengine.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/qml/jsapi/qjsengine.cpp b/src/qml/jsapi/qjsengine.cpp
index c581a469fb..eda1c4c931 100644
--- a/src/qml/jsapi/qjsengine.cpp
+++ b/src/qml/jsapi/qjsengine.cpp
@@ -922,6 +922,7 @@ bool QJSEngine::convertV2(const QJSValue &value, QMetaType metaType, void *ptr)
if (const QString *string = QJSValuePrivate::asQString(&value))
return convertString(*string, metaType, ptr);
+ // Does not need scoping since QJSValue still holds on to the value.
return QV4::ExecutionEngine::metaTypeFromJS(QJSValuePrivate::asReturnedValue(&value), metaType, ptr);
}
@@ -929,14 +930,18 @@ bool QJSEngine::convertVariant(const QVariant &value, QMetaType metaType, void *
{
// TODO: We could probably avoid creating a QV4::Value in many cases, but we'd have to
// duplicate much of metaTypeFromJS and some methods of QV4::Value itself here.
- return QV4::ExecutionEngine::metaTypeFromJS(handle()->fromVariant(value), metaType, ptr);
+ QV4::Scope scope(handle());
+ QV4::ScopedValue scoped(scope, scope.engine->fromVariant(value));
+ return QV4::ExecutionEngine::metaTypeFromJS(scoped, metaType, ptr);
}
bool QJSEngine::convertMetaType(QMetaType fromType, const void *from, QMetaType toType, void *to)
{
// TODO: We could probably avoid creating a QV4::Value in many cases, but we'd have to
// duplicate much of metaTypeFromJS and some methods of QV4::Value itself here.
- return QV4::ExecutionEngine::metaTypeFromJS(handle()->fromData(fromType, from), toType, to);
+ QV4::Scope scope(handle());
+ QV4::ScopedValue scoped(scope, scope.engine->fromData(fromType, from));
+ return QV4::ExecutionEngine::metaTypeFromJS(scoped, toType, to);
}
QString QJSEngine::convertQObjectToString(QObject *object)