[ES6] Allow trailing comma in ArrayBindingPattern and ObjectBindingPattern
https://bugs.webkit.org/show_bug.cgi?id=146192
Reviewed by Darin Adler.
Source/JavaScriptCore:
According to the ES6 spec, trailing comma in ArrayBindingPattern and ObjectBindingPattern is allowed.
And empty ArrayBindingPattern and ObjectBindingPattern is also allowed.
This patch allows trailing comma and empty binding patterns.
* bytecompiler/NodesCodegen.cpp:
(JSC::ArrayPatternNode::bindValue):
* parser/Parser.cpp:
(JSC::Parser<LexerType>::parseDeconstructionPattern):
* tests/stress/trailing-comma-in-patterns.js: Added.
(shouldBe):
(iterator):
LayoutTests:
* js/object-literal-syntax-expected.txt:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@185853 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp b/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
index 7643e0b..81a5819 100644
--- a/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
+++ b/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
@@ -3139,8 +3139,12 @@
generator.emitCall(iterator.get(), iterator.get(), NoExpectedFunction, args, divot(), divotStart(), divotEnd());
}
+ if (m_targetPatterns.isEmpty()) {
+ generator.emitIteratorClose(iterator.get(), this);
+ return;
+ }
+
RefPtr<RegisterID> done;
- ASSERT(!m_targetPatterns.isEmpty());
for (auto& target : m_targetPatterns) {
RefPtr<RegisterID> value = generator.newTemporary();