aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@theqtcompany.com>2015-04-30 13:20:43 +0200
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-04-30 15:57:19 +0000
commit2fdb6eba0a58b629db32f9eefec2f26df08d3d2e (patch)
tree5b953451a0202ceadcaf1a154ea43ee3b1c2c33d
parent0d31aa1617c96ed3e3624d77332ea6f13aba1492 (diff)
Fix passing of locals as function arguments with side-effects
Commit 75c22465cf8fe262edfe6178bb9ca19661fb710e regressed in allowing locals and arguments to be passed directly as further arguments to function calls, but that's incorrect when considering var i = 2; testFunction(i, i += 2) where it is instrumental to place the first argument into a temp (making a copy) instead of passing it directly. Change-Id: Iffcf6c6eda92a8fb665982cda1db0b96359cd092 Task-number: QTBUG-45879 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
-rw-r--r--src/qml/compiler/qv4codegen.cpp2
-rw-r--r--tests/auto/qml/qjsengine/tst_qjsengine.cpp21
2 files changed, 22 insertions, 1 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp
index a7b5326861..260db0f0dd 100644
--- a/src/qml/compiler/qv4codegen.cpp
+++ b/src/qml/compiler/qv4codegen.cpp
@@ -538,7 +538,7 @@ IR::Expr *Codegen::subscript(IR::Expr *base, IR::Expr *index)
IR::Expr *Codegen::argument(IR::Expr *expr)
{
- if (expr && !expr->asTemp() && !expr->asArgLocal()) {
+ if (expr && !expr->asTemp()) {
const unsigned t = _block->newTemp();
move(_block->TEMP(t), expr);
expr = _block->TEMP(t);
diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
index 2b7b1fc524..2690b857fa 100644
--- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp
+++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
@@ -176,6 +176,8 @@ private slots:
void intConversion_QTBUG43309();
void toFixed();
+ void argumentEvaluationOrder();
+
signals:
void testSignal();
};
@@ -3628,6 +3630,25 @@ void tst_QJSEngine::toFixed()
QCOMPARE(result.toString(), QStringLiteral("12.1"));
}
+void tst_QJSEngine::argumentEvaluationOrder()
+{
+ QJSEngine engine;
+ QJSValue ok = engine.evaluate(
+ "function record(arg1, arg2) {\n"
+ " parameters = [arg1, arg2]\n"
+ "}\n"
+ "function test() {\n"
+ " var i = 2;\n"
+ " record(i, i += 2);\n"
+ "}\n"
+ "test()\n"
+ "parameters[0] == 2 && parameters[1] == 4");
+ qDebug() << ok.toString();
+ QVERIFY(ok.isBool());
+ QVERIFY(ok.toBool());
+
+}
+
QTEST_MAIN(tst_QJSEngine)
#include "tst_qjsengine.moc"