Implement nested rest destructuring w.r.t the ES7 spec
https://bugs.webkit.org/show_bug.cgi?id=160423
Reviewed by Filip Pizlo.
JSTests:
- stress/destructuring-rest-element.js: Added.
(assert):
(test):
(arr):
(eq):
(gen):
(fakeGen.return.Symbol.iterator):
(fakeGen):
(testSyntaxError.String.raw):
- stress/rest-parameter-is-destructuring.js: Added.
(assert):
(test):
(foo):
(bar):
Source/JavaScriptCore:
The spec has updated the BindingRestElement grammar production to be:
BindingRestElement:
BindingIdentifier
BindingingPattern.
It used to only allow BindingIdentifier in the grammar production.
I've updated our engine to account for this. The semantics are exactly
what you'd expect. For example:
let [a, ...[b, ...c]] = expr();
means that we create an array for the first rest element ...[b, ...c]
and then perform the binding of [b, ...c]
to that array. And so on,
applied recursively through the pattern.
- bytecompiler/NodesCodegen.cpp:
(JSC::RestParameterNode::collectBoundIdentifiers):
(JSC::RestParameterNode::toString):
(JSC::RestParameterNode::bindValue):
(JSC::RestParameterNode::emit):
(JSC::ASTBuilder::createBindingLocation):
(JSC::ASTBuilder::createRestParameter):
(JSC::ASTBuilder::createAssignmentElement):
- parser/NodeConstructors.h:
(JSC::AssignmentElementNode::AssignmentElementNode):
(JSC::RestParameterNode::RestParameterNode):
(JSC::DestructuringAssignmentNode::DestructuringAssignmentNode):
(JSC::RestParameterNode::name): Deleted.
(JSC::Parser<LexerType>::parseDestructuringPattern):
(JSC::Parser<LexerType>::parseFormalParameters):
(JSC::SyntaxChecker::operatorStackPop):
LayoutTests:
- js/parser-syntax-check-expected.txt:
- js/script-tests/parser-syntax-check.js: