diff options
Diffstat (limited to 'src/qml/compiler/qv4codegen.cpp')
-rw-r--r-- | src/qml/compiler/qv4codegen.cpp | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index cbe935c5cd..274917dd0a 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -1134,7 +1134,14 @@ bool Codegen::visit(ArrayPattern *ast) BytecodeGenerator::Label done = bytecodeGenerator->newLabel(); { - ControlFlowLoop flow(this, &end, &in, /*requiresUnwind*/ true); + auto unwind = [this, iterator]() { + Reference iteratorDone = Reference::fromConst(this, Encode(false)).storeOnStack(); + iterator.loadInAccumulator(); + Instruction::IteratorClose close; + close.done = iteratorDone.stackSlot(); + bytecodeGenerator->addInstruction(close); + }; + ControlFlowLoop flow(this, &end, &in, unwind); bytecodeGenerator->jump().link(in); BytecodeGenerator::Label body = bytecodeGenerator->label(); @@ -1149,15 +1156,9 @@ bool Codegen::visit(ArrayPattern *ast) bytecodeGenerator->addInstruction(next); bytecodeGenerator->addJumpInstruction(Instruction::JumpFalse()).link(body); bytecodeGenerator->jump().link(done); - } - - end.link(); - Reference iteratorDone = Reference::fromConst(this, Encode(false)).storeOnStack(); - iterator.loadInAccumulator(); - Instruction::IteratorClose close; - close.done = iteratorDone.stackSlot(); - bytecodeGenerator->addInstruction(close); + end.link(); + } done.link(); } else { @@ -3177,7 +3178,16 @@ bool Codegen::visit(ForEachStatement *ast) BytecodeGenerator::Label done = bytecodeGenerator->newLabel(); { - ControlFlowLoop flow(this, &end, &in, /*requiresUnwind*/ true); + auto unwind = [ast, this, iterator]() { + 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); + } + }; + ControlFlowLoop flow(this, &end, &in, unwind); bytecodeGenerator->jump().link(in); BytecodeGenerator::Label body = bytecodeGenerator->label(); @@ -3220,16 +3230,8 @@ bool Codegen::visit(ForEachStatement *ast) bytecodeGenerator->addInstruction(next); bytecodeGenerator->addJumpInstruction(Instruction::JumpFalse()).link(body); bytecodeGenerator->jump().link(done); - } - - 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); + end.link(); } done.link(); |