diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-05-09 14:03:39 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-05-11 07:17:22 +0000 |
commit | e3b9726483cb7336aa54ae7d9455becbd148b2b6 (patch) | |
tree | ba056c898a9a694179104e1fd4f4f32d91a6dd86 /src/qml/compiler/qv4compilercontext.cpp | |
parent | 541b8220cffbbae4b798ae8282d04ca145caccd1 (diff) |
Improve for-in and for-of support
Create a Block scope per iteration as defined in the ES spec. So
closures created inside the loop will remember the iteration variable
at that loop iteration.
Add support for destructuring of the left hand side expression or
declaration.
Change-Id: Id06ef94e2a4b93646827da4f6ce922eb436e5a31
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4compilercontext.cpp')
-rw-r--r-- | src/qml/compiler/qv4compilercontext.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/qml/compiler/qv4compilercontext.cpp b/src/qml/compiler/qv4compilercontext.cpp index 07e19811a8..bfe0d4b131 100644 --- a/src/qml/compiler/qv4compilercontext.cpp +++ b/src/qml/compiler/qv4compilercontext.cpp @@ -167,6 +167,11 @@ int Context::emitBlockHeader(Codegen *codegen) setupFunctionIndices(bytecodeGenerator); int contextReg = -1; + if (requiresExecutionContext && blockIndex < 0) { + codegen->module()->blocks.append(this); + blockIndex = codegen->module()->blocks.count() - 1; + } + if (requiresExecutionContext && contextType == ContextType::Global) { Instruction::PushScriptContext scriptContext; scriptContext.index = blockIndex; @@ -268,9 +273,15 @@ QT_WARNING_POP void Context::setupFunctionIndices(Moth::BytecodeGenerator *bytecodeGenerator) { + if (registerOffset != -1) { + // already computed, check for consistency + Q_ASSERT(registerOffset == bytecodeGenerator->currentRegister()); + bytecodeGenerator->newRegisterArray(nRegisters); + return; + } Q_ASSERT(locals.size() == 0); Q_ASSERT(nRegisters == 0); - registerOffset = bytecodeGenerator->registerCount(); + registerOffset = bytecodeGenerator->currentRegister(); switch (contextType) { case ContextType::Block: @@ -304,7 +315,7 @@ void Context::setupFunctionIndices(Moth::BytecodeGenerator *bytecodeGenerator) } break; } - nRegisters = bytecodeGenerator->registerCount() - registerOffset; + nRegisters = bytecodeGenerator->currentRegister() - registerOffset; } QT_END_NAMESPACE |