aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@qt.io>2018-07-06 14:36:11 +0200
committerErik Verbruggen <erik.verbruggen@qt.io>2018-07-13 10:20:07 +0000
commit8fdfd9ff5ded388a3d29c917aebb795485abfbfd (patch)
treee9b614f90adbd7943a4c6190e8e1ba39cec37d40 /tests
parenteab3371b91a2a752a123c4995d977a36ff952168 (diff)
JS: Encode result of Math.min and Math.max as int when possible
So now Math.max(array1.length, array2.length) won't return a double anymore. This improves the score in the crypto benchmark by ~10% Change-Id: I8453a671d28d7f2a39ba74b18b3155f031d9b12f Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qjsengine/tst_qjsengine.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
index c20937f9a1..935fd53a42 100644
--- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp
+++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
@@ -39,6 +39,7 @@
#include <qqmlcomponent.h>
#include <stdlib.h>
#include <private/qv4alloca_p.h>
+#include <private/qjsvalue_p.h>
#ifdef Q_CC_MSVC
#define NO_INLINE __declspec(noinline)
@@ -220,6 +221,7 @@ private slots:
void multilineStrings();
void throwError();
+ void mathMinMax();
public:
Q_INVOKABLE QJSValue throwingCppMethod();
@@ -4326,6 +4328,21 @@ QJSValue tst_QJSEngine::throwingCppMethod()
return QJSValue(47);
}
+void tst_QJSEngine::mathMinMax()
+{
+ QJSEngine engine;
+
+ QJSValue result = engine.evaluate("var a = .5; Math.min(1, 2, 3.5 + a, '5')");
+ QCOMPARE(result.toNumber(), 1.0);
+ QVERIFY(QJSValuePrivate::getValue(&result) != nullptr);
+ QVERIFY(QJSValuePrivate::getValue(&result)->isInteger());
+
+ result = engine.evaluate("var a = .5; Math.max('0', 1, 2, 3.5 + a)");
+ QCOMPARE(result.toNumber(), 4.0);
+ QVERIFY(QJSValuePrivate::getValue(&result) != nullptr);
+ QVERIFY(QJSValuePrivate::getValue(&result)->isInteger());
+}
+
QTEST_MAIN(tst_QJSEngine)
#include "tst_qjsengine.moc"