Skip to content

Commit

Permalink
Ensure || expressions in v4 will always exit.
Browse files Browse the repository at this point in the history
Change-Id: I7188e38403fec96f83f3bdfc68b763a9aec9346a
Task-number: QTBUG-24038
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
  • Loading branch information
Michael Brasser authored and Qt by Nokia committed Feb 2, 2012
1 parent 3499561 commit 348b513
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/declarative/qml/v4/qv4irbuilder.cpp
Expand Up @@ -892,6 +892,7 @@ bool QV4IRBuilder::visit(AST::BinaryExpression *ast)
_block = iftrue;
ExprResult right = expression(ast->right);
_block->MOVE(r, right);
_block->JUMP(endif);

if (left.type() != right.type())
discard();
Expand Down
14 changes: 14 additions & 0 deletions tests/auto/declarative/v4/data/nestedLogicalOr.qml
@@ -0,0 +1,14 @@
import Qt.v4 1.0

Result {
property bool val1: false
property bool val2: true
property bool val3: false

property bool b1: (false || false || true)
property bool b2: (false || (false || true))
property bool b3: ((false || false) || true)
property bool b4: (val1 || (val2 || val3)) ? true : false

result: b1 && b2 && b3 && b4
}
16 changes: 16 additions & 0 deletions tests/auto/declarative/v4/tst_v4.cpp
Expand Up @@ -62,6 +62,7 @@ private slots:

void unnecessaryReeval();
void logicalOr();
void nestedLogicalOr();
void conditionalExpr();
void qtscript();
void qtscript_data();
Expand Down Expand Up @@ -183,6 +184,21 @@ void tst_v4::logicalOr()
}
}

void tst_v4::nestedLogicalOr()
{
//we are primarily testing that v4 does not get caught in a loop (QTBUG-24038)
QDeclarativeComponent component(&engine, testFileUrl("nestedLogicalOr.qml"));

QObject *o = component.create();
QVERIFY(o != 0);

ResultObject *ro = qobject_cast<ResultObject *>(o);
QVERIFY(ro != 0);

QCOMPARE(ro->result(), 1);
delete o;
}

void tst_v4::conditionalExpr()
{
{
Expand Down

0 comments on commit 348b513

Please sign in to comment.