Implement nested rest destructuring w.r.t the ES7 spec
authorsbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Aug 2016 07:50:40 +0000 (07:50 +0000)
committersbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Aug 2016 07:50:40 +0000 (07:50 +0000)
commitbb709ced2254d351a2978fa1e54607b5e1448ad1
tree579e9b885eb2fc39c9943f08692ef9667302a142
parent346138d6bf13f01e4c8c62eef58fb7e208d28960
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):
* stress/rest-elements.js:
(testSyntaxError.String.raw):
* stress/rest-parameter-is-destructuring.js: Added.
(assert):
(test):
(foo):
(bar):
* test262.yaml:

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):
* parser/ASTBuilder.h:
(JSC::ASTBuilder::createBindingLocation):
(JSC::ASTBuilder::createRestParameter):
(JSC::ASTBuilder::createAssignmentElement):
* parser/NodeConstructors.h:
(JSC::AssignmentElementNode::AssignmentElementNode):
(JSC::RestParameterNode::RestParameterNode):
(JSC::DestructuringAssignmentNode::DestructuringAssignmentNode):
* parser/Nodes.h:
(JSC::RestParameterNode::name): Deleted.
* parser/Parser.cpp:
(JSC::Parser<LexerType>::parseDestructuringPattern):
(JSC::Parser<LexerType>::parseFormalParameters):
* parser/SyntaxChecker.h:
(JSC::SyntaxChecker::operatorStackPop):

LayoutTests:

* js/parser-syntax-check-expected.txt:
* js/script-tests/parser-syntax-check.js:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@204078 268f45cc-cd09-0410-ab3c-d52691b4dbfc
15 files changed:
JSTests/ChangeLog
JSTests/stress/destructuring-rest-element.js [new file with mode: 0644]
JSTests/stress/rest-elements.js
JSTests/stress/rest-parameter-is-destructuring.js [new file with mode: 0644]
JSTests/test262.yaml
LayoutTests/ChangeLog
LayoutTests/js/parser-syntax-check-expected.txt
LayoutTests/js/script-tests/parser-syntax-check.js
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
Source/JavaScriptCore/parser/ASTBuilder.h
Source/JavaScriptCore/parser/NodeConstructors.h
Source/JavaScriptCore/parser/Nodes.h
Source/JavaScriptCore/parser/Parser.cpp
Source/JavaScriptCore/parser/SyntaxChecker.h