[ES6] Destructuring assignment need to accept iterables
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 20 Jun 2015 11:04:27 +0000 (11:04 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 20 Jun 2015 11:04:27 +0000 (11:04 +0000)
commit97bd1c1ea7ec795b3d313fe6271854cfabb26fd2
tree3845c64efdcafb12617ff22b7cc6c7afa092f06f
parentdbb951fe00d20500ddc65953cc06dc6a84a82251
[ES6] Destructuring assignment need to accept iterables
https://bugs.webkit.org/show_bug.cgi?id=144111

Reviewed by Darin Adler.

Source/JavaScriptCore:

This patch makes that destructuring assignments to array binding patterns accept iterables.
Previously, it just access the indexed properties.
After this patch, it iterates the given value by using ES6 iterator protocol.

The iteration becomes different from the for-of case.
1. Since there's no break/continue case, finally scope is not necessary.
2. When the error is raised, the close status of the iterator becomes true. So IteratorClose is not called for that.
3. Since the array binding patterns requires a limited count of iterations (if there is no rest(...rest) case), IteratorClose is called when the iteration does not consume the all values of the iterator.
4. Since the array binding patterns requires a specified count of iterations, iterator's next call is skipped when iterator becomes closed.

* bytecompiler/BytecodeGenerator.cpp:
(JSC::BytecodeGenerator::emitIteratorClose):
* bytecompiler/BytecodeGenerator.h:
* bytecompiler/NodesCodegen.cpp:
(JSC::ArrayPatternNode::bindValue):
* parser/ASTBuilder.h:
(JSC::ASTBuilder::finishArrayPattern):
* parser/Nodes.h:
* parser/Parser.cpp:
(JSC::Parser<LexerType>::parseDeconstructionPattern):
* parser/SyntaxChecker.h:
(JSC::SyntaxChecker::operatorStackPop):
* tests/stress/destructuring-assignment-accepts-iterables.js: Added.
(shouldBe):
(shouldThrow):
(.set shouldThrow):

LayoutTests:

From this patch, we use iterators for destructuring assignments to array binding patterns.
So test results become different.

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

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@185791 268f45cc-cd09-0410-ab3c-d52691b4dbfc
13 files changed:
LayoutTests/ChangeLog
LayoutTests/js/destructuring-assignment-expected.txt
LayoutTests/js/parser-syntax-check-expected.txt
LayoutTests/js/script-tests/destructuring-assignment.js
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp
Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h
Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
Source/JavaScriptCore/parser/ASTBuilder.h
Source/JavaScriptCore/parser/Nodes.h
Source/JavaScriptCore/parser/Parser.cpp
Source/JavaScriptCore/parser/SyntaxChecker.h
Source/JavaScriptCore/tests/stress/destructuring-assignment-accepts-iterables.js [new file with mode: 0644]