aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qjsengine
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2018-03-21 11:43:47 +0100
committerLiang Qi <liang.qi@qt.io>2018-03-21 11:43:47 +0100
commit089e5f7822e6d64e8e5864806929d29fd735fb0d (patch)
treebb0c4f173067e8a498c70e218f0b8c0c82a5525f /tests/auto/qml/qjsengine
parentbc4455cda2ae395f2943cd9f18b6ae51a676399a (diff)
parent1a816cd8dcc3499351ce6dfb6ad3bdfb34c31ede (diff)
Merge remote-tracking branch 'origin/5.11' into dev
Conflicts: tests/auto/qml/qjsengine/tst_qjsengine.cpp Change-Id: I25e264df273c01832f64dbd31923d8529f1d1900
Diffstat (limited to 'tests/auto/qml/qjsengine')
-rw-r--r--tests/auto/qml/qjsengine/tst_qjsengine.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
index 9dc088486b..1eff5739b8 100644
--- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp
+++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
@@ -128,6 +128,7 @@ private slots:
void JSONparse();
void arraySort();
void lookupOnDisappearingProperty();
+ void arrayConcat();
void qRegExpInport_data();
void qRegExpInport();
@@ -202,6 +203,7 @@ private slots:
void malformedExpression();
void scriptScopes();
+ void perfMapFile();
void binaryNumbers();
void octalNumbers();
@@ -3011,6 +3013,19 @@ void tst_QJSEngine::lookupOnDisappearingProperty()
QVERIFY(func.call(QJSValueList()<< o).isUndefined());
}
+void tst_QJSEngine::arrayConcat()
+{
+ QJSEngine eng;
+ QJSValue v = eng.evaluate("var x = [1, 2, 3, 4, 5, 6];"
+ "var y = [];"
+ "for (var i = 0; i < 5; ++i)"
+ " x.shift();"
+ "for (var i = 10; i < 13; ++i)"
+ " x.push(i);"
+ "x.toString();");
+ QCOMPARE(v.toString(), QString::fromLatin1("6,10,11,12"));
+}
+
static QRegExp minimal(QRegExp r) { r.setMinimal(true); return r; }
void tst_QJSEngine::qRegExpInport_data()
@@ -4165,6 +4180,73 @@ void tst_QJSEngine::octalNumbers()
QVERIFY(result.isError());
}
+static const char *perfMapKey = "QV4_PROFILE_WRITE_PERF_MAP";
+static const char *jitCallKey = "QV4_JIT_CALL_THRESHOLD";
+
+struct EnvironmentModifier {
+ const bool hasPerfMap = false;
+ const bool hasJitCall = false;
+ const QByteArray perfMap;
+ const QByteArray jitCall;
+
+ EnvironmentModifier() :
+ hasPerfMap(qEnvironmentVariableIsSet(perfMapKey)),
+ hasJitCall(qEnvironmentVariableIsSet(jitCallKey)),
+ perfMap(qgetenv(perfMapKey)),
+ jitCall(qgetenv(jitCallKey))
+ {
+ qputenv(perfMapKey, "1");
+ qputenv(jitCallKey, "0");
+ }
+
+ ~EnvironmentModifier()
+ {
+ if (hasPerfMap)
+ qputenv(perfMapKey, perfMap);
+ else
+ qunsetenv(perfMapKey);
+
+ if (hasJitCall)
+ qputenv(jitCallKey, jitCall);
+ else
+ qunsetenv(jitCallKey);
+ }
+};
+
+void tst_QJSEngine::perfMapFile()
+{
+#if !defined(Q_OS_LINUX)
+ QSKIP("perf map files are only generated on linux");
+#else
+ EnvironmentModifier modifier;
+ Q_UNUSED(modifier);
+ QJSEngine engine;
+ QJSValue def = engine.evaluate("'use strict'; function foo() { return 42 }");
+ QVERIFY(!def.isError());
+ QJSValue use = engine.evaluate("'use strict'; foo()");
+ QVERIFY(use.isNumber());
+ QFile file(QString::fromLatin1("/tmp/perf-%1.map").arg(QCoreApplication::applicationPid()));
+ QVERIFY(file.exists());
+ QVERIFY(file.open(QIODevice::ReadOnly));
+ QList<QByteArray> functions;
+ while (!file.atEnd()) {
+ const QByteArray contents = file.readLine();
+ QVERIFY(contents.endsWith('\n'));
+ QList<QByteArray> fields = contents.split(' ');
+ QCOMPARE(fields.length(), 3);
+ bool ok = false;
+ const qulonglong address = fields[0].toULongLong(&ok, 16);
+ QVERIFY(ok);
+ QVERIFY(address > 0);
+ const ulong size = fields[1].toULong(&ok, 16);
+ QVERIFY(ok);
+ QVERIFY(size > 0);
+ functions.append(fields[2]);
+ }
+ QVERIFY(functions.contains("foo\n"));
+#endif
+}
+
QTEST_MAIN(tst_QJSEngine)
#include "tst_qjsengine.moc"