diff options
author | Andrei Golubev <andrei.golubev@qt.io> | 2021-05-03 11:04:39 +0200 |
---|---|---|
committer | Andrei Golubev <andrei.golubev@qt.io> | 2021-05-11 08:48:11 +0200 |
commit | 2f9b62ea5961550e8d65897932a792da8b232a9c (patch) | |
tree | 0fb4642f532e99423953deaed65d9cd3d337116f /tests/auto/qml/qqmlengine | |
parent | 0d5c2768808a5c0b77df9e0e4763cf7348b47b5f (diff) |
QQmlEngine::executeRuntimeFunction: pass return value as input argument
Use the newer version of QV4::Function::call() that does not require
manual JSCallData setup and is more optimal for AOT function calls
Change-Id: I5a5e2d0477c0603b05b7213f1b2adcc34d156bf5
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlengine')
-rw-r--r-- | tests/auto/qml/qqmlengine/tst_qqmlengine.cpp | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp index c02728e2a9..e1dff63e03 100644 --- a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp +++ b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp @@ -1250,27 +1250,31 @@ void tst_qqmlengine::executeRuntimeFunction() QScopedPointer<QObject> dummy(component.create()); // getConstantValue(): - const int constant = qjsvalue_cast<int>(priv->executeRuntimeFunction(url, 0, dummy.get())); + int constant = 0; + void *a0[] = { const_cast<void *>(reinterpret_cast<const void *>(std::addressof(constant))) }; + QMetaType t0[] = { QMetaType::fromType<int>() }; + priv->executeRuntimeFunction(url, /* index = */ 0, dummy.get(), /* argc = */ 0, a0, t0); QCOMPARE(constant, 42); // squareValue(): + int squared = 0; int x = 5; - void *a0[] = { nullptr, const_cast<void *>(reinterpret_cast<const void *>(std::addressof(x))) }; - QMetaType t0[] = { QMetaType::fromType<int>() }; - const int squared = - qjsvalue_cast<int>(priv->executeRuntimeFunction(url, 1, dummy.get(), 1, a0, t0)); + void *a1[] = { const_cast<void *>(reinterpret_cast<const void *>(std::addressof(squared))), + const_cast<void *>(reinterpret_cast<const void *>(std::addressof(x))) }; + QMetaType t1[] = { QMetaType::fromType<int>(), QMetaType::fromType<int>() }; + priv->executeRuntimeFunction(url, /* index = */ 1, dummy.get(), /* argc = */ 1, a1, t1); QCOMPARE(squared, x * x); // concatenate(): + QString concatenated; QString str1 = QStringLiteral("Hello"); // uses "raw data" storage QString str2 = QLatin1String(", Qml"); // uses own QString storage - void *a1[] = { nullptr, + void *a2[] = { const_cast<void *>(reinterpret_cast<const void *>(std::addressof(concatenated))), const_cast<void *>(reinterpret_cast<const void *>(std::addressof(str1))), const_cast<void *>(reinterpret_cast<const void *>(std::addressof(str2))) }; - QMetaType t1[] = { QMetaType::fromType<QString>(), - QMetaType::fromType<QString>() }; - QString concatenated = - qjsvalue_cast<QString>(priv->executeRuntimeFunction(url, 2, dummy.get(), 2, a1, t1)); + QMetaType t2[] = { QMetaType::fromType<QString>(), QMetaType::fromType<QString>(), + QMetaType::fromType<QString>() }; + priv->executeRuntimeFunction(url, /* index = */ 2, dummy.get(), /* argc = */ 2, a2, t2); QCOMPARE(concatenated, str1 + str2); } |