diff options
author | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2015-01-13 16:59:22 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2015-01-15 11:29:37 +0100 |
commit | 0bba8d7411d0b1f1b547f9ac960e7d84769c7154 (patch) | |
tree | 550683a5957e492ed2a19def03d02656be223ddc | |
parent | 88e87647c3b7d651dba2c8e61f945d47ecdd02c4 (diff) |
Fix failing assertion in debug builds for JS that calls constants
For
true()
we generate IR that looks like this:
temp = true
result = call temp()
and therefore the move at isel time has IR::Call as source and a temp
as base for the call. However constant propagation in the optimizer transforms
this to
result = call true()
and that's a case we didn't handle in the IR visitor. Since we have
Runtime::callValue we can however handle this case as well and the run-time
will consequently produce the expected run-time error.
Change-Id: Ia94a8116388e66f9f339913307f68e33a5c18a19
Task-number: QTBUG-43819
Reviewed-by: Robin Burchell <robin.burchell@viroteck.net>
Reviewed-by: Jan Kundrát <jkt@kde.org>
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
-rw-r--r-- | src/qml/compiler/qv4isel_p.cpp | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4runtime.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qml/qjsengine/tst_qjsengine.cpp | 2 |
3 files changed, 4 insertions, 2 deletions
diff --git a/src/qml/compiler/qv4isel_p.cpp b/src/qml/compiler/qv4isel_p.cpp index e419084238..4bb866616d 100644 --- a/src/qml/compiler/qv4isel_p.cpp +++ b/src/qml/compiler/qv4isel_p.cpp @@ -182,7 +182,7 @@ void IRDecoder::visitMove(IR::Move *s) } else if (Subscript *ss = c->base->asSubscript()) { callSubscript(ss->base, ss->index, c->args, s->target); return; - } else if (c->base->asTemp() || c->base->asArgLocal()) { + } else if (c->base->asTemp() || c->base->asArgLocal() || c->base->asConst()) { callValue(c->base, c->args, s->target); return; } diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp index f72f25bd58..b019d4db14 100644 --- a/src/qml/jsruntime/qv4runtime.cpp +++ b/src/qml/jsruntime/qv4runtime.cpp @@ -961,7 +961,7 @@ ReturnedValue Runtime::callElement(ExecutionContext *context, const ValueRef ind ReturnedValue Runtime::callValue(ExecutionContext *context, const ValueRef func, CallData *callData) { if (!func->isObject()) - return context->throwTypeError(); + return context->throwTypeError(QStringLiteral("%1 is not a function").arg(func->toQStringNoThrow())); return func->objectValue()->call(callData); } diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp index d24a1a4f20..158ee1589a 100644 --- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp +++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp @@ -3140,6 +3140,8 @@ void tst_QJSEngine::callConstants() " var one; one();\n" " var two = null; two();\n" "}\n"); + QJSValue exceptionResult = engine.evaluate("true()"); + QCOMPARE(exceptionResult.toString(), QString("TypeError: true is not a function")); } void tst_QJSEngine::installTranslatorFunctions() |