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: http://svn.webkit.org/repository/webkit/trunk@204078 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/parser/Nodes.h b/Source/JavaScriptCore/parser/Nodes.h
index 67af4fc..3a3868d 100644
--- a/Source/JavaScriptCore/parser/Nodes.h
+++ b/Source/JavaScriptCore/parser/Nodes.h
@@ -2128,23 +2128,19 @@
class RestParameterNode : public DestructuringPatternNode {
public:
- RestParameterNode(const Identifier& boundProperty, unsigned numParametersToSkip, const JSTextPosition& start, const JSTextPosition& end);
+ RestParameterNode(DestructuringPatternNode*, unsigned numParametersToSkip);
bool isRestParameter() const override { return true; }
void emit(BytecodeGenerator&);
- const Identifier& name() const { return m_name; }
-
private:
void collectBoundIdentifiers(Vector<Identifier>&) const override;
void bindValue(BytecodeGenerator&, RegisterID*) const override;
void toString(StringBuilder&) const override;
- const Identifier& m_name;
+ DestructuringPatternNode* m_pattern;
unsigned m_numParametersToSkip;
- JSTextPosition m_divotStart; // "f" in "...foo"
- JSTextPosition m_divotEnd;
};
class AssignmentElementNode : public DestructuringPatternNode {