diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-05-14 10:22:09 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-05-14 19:32:29 +0000 |
commit | 16288498cf0e1eb389ac3acdce86eb74cc69e67a (patch) | |
tree | 32ffcf8899a40d8bf076b6ffb58823991dac1978 /src/qml/compiler/qv4codegen.cpp | |
parent | b9311cc01da09f7f736850f500113f3e576c21a9 (diff) | |
download | qtdeclarative-16288498cf0e1eb389ac3acdce86eb74cc69e67a.tar.gz |
Implement support for destructuring of rest elements
"var [x, ...y] = array" now works as intended.
Change-Id: I45238f27f468d0b0e14dc0e931c55c4f40043690
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4codegen.cpp')
-rw-r--r-- | src/qml/compiler/qv4codegen.cpp | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index ffb318168c..f00a0fafdc 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -495,22 +495,25 @@ void Codegen::destructureElementList(const Codegen::Reference &array, PatternEle } RegisterScope scope(this); - iterator.loadInAccumulator(); - Instruction::IteratorNext next; - next.returnUndefinedWhenDone = true; - bytecodeGenerator->addInstruction(next); + PatternElement *e = p->element; - if (!e) - continue; - if (e->type != PatternElement::RestElement) { + if (e && e->type == PatternElement::RestElement) { + bytecodeGenerator->addInstruction(Instruction::DestructureRestElement()); initializeAndDestructureBindingElement(e, Reference::fromAccumulator(this)); - if (hasError) { - end.link(); - return; - } } else { - throwSyntaxError(bindingList->firstSourceLocation(), QString::fromLatin1("Support for rest elements in binding arrays not implemented!")); + Instruction::IteratorNext next; + next.returnUndefinedWhenDone = true; + bytecodeGenerator->addInstruction(next); + if (!e) + continue; + if (e->type != PatternElement::RestElement) { + initializeAndDestructureBindingElement(e, Reference::fromAccumulator(this)); + if (hasError) { + end.link(); + return; + } + } } } end.link(); |