summaryrefslogtreecommitdiff
path: root/src/qml/compiler/qv4codegen.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-05-14 14:26:48 +0200
committerLars Knoll <lars.knoll@qt.io>2018-05-14 19:32:46 +0000
commitd57a7c775f685e7e46b5d76e1f715dd59fc39e3b (patch)
tree44a96d36937981a7a6083a645addc53d03fe3589 /src/qml/compiler/qv4codegen.cpp
parentc4ef0d6e4b5bb7de7b0ab08928d693988a60b25d (diff)
downloadqtdeclarative-d57a7c775f685e7e46b5d76e1f715dd59fc39e3b.tar.gz
Partial support for calling iterator.return when break a for-of loop
This will only work for non labelled break statements that don't break an outer loop as well. It also still doesn't work when an exception is thrown within the loop. Change-Id: Ie7cee7094ce2c51cdaa52270bbb16bc83b1e208f Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4codegen.cpp')
-rw-r--r--src/qml/compiler/qv4codegen.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp
index 897f104093..b46891572e 100644
--- a/src/qml/compiler/qv4codegen.cpp
+++ b/src/qml/compiler/qv4codegen.cpp
@@ -2715,11 +2715,21 @@ bool Codegen::visit(ForEachStatement *ast)
Instruction::IteratorNext next;
next.value = lhsValue.stackSlot();
bytecodeGenerator->addInstruction(next);
- BytecodeGenerator::Jump done = bytecodeGenerator->addJumpInstruction(Instruction::JumpTrue());
- bytecodeGenerator->jump().link(body);
+ bytecodeGenerator->addJumpInstruction(Instruction::JumpFalse()).link(body);
+ BytecodeGenerator::Jump done = bytecodeGenerator->jump();
- done.link();
end.link();
+
+ if (ast->type == ForEachType::Of) {
+ Reference iteratorDone = Reference::fromConst(this, Encode(false)).storeOnStack();
+ iterator.loadInAccumulator();
+ Instruction::IteratorClose close;
+ close.done = iteratorDone.stackSlot();
+ bytecodeGenerator->addInstruction(close);
+ }
+
+ done.link();
+
return false;
}