[JSC] support Computed Property Names in destructuring Patterns
https://bugs.webkit.org/show_bug.cgi?id=151494
Patch by Caitlin Potter <caitp@igalia.com> on 2015-11-24
Reviewed by Saam Barati.
Add support for computed property names in destructuring BindingPatterns
and AssignmentPatterns.
Productions BindingProperty(1) and AssignmentProperty(2) allow for any valid
PropertName(3), including ComputedPropertyName(4)
1: http://tc39.github.io/ecma262/#prod-BindingProperty
2: http://tc39.github.io/ecma262/#prod-AssignmentProperty
3: http://tc39.github.io/ecma262/#prod-PropertyName
4: http://tc39.github.io/ecma262/#prod-ComputedPropertyName
* bytecompiler/NodesCodegen.cpp:
(JSC::ObjectPatternNode::bindValue):
* parser/ASTBuilder.h:
(JSC::ASTBuilder::appendObjectPatternEntry):
* parser/Nodes.h:
(JSC::ObjectPatternNode::appendEntry):
* parser/Parser.cpp:
(JSC::Parser<LexerType>::parseDestructuringPattern):
* parser/SyntaxChecker.h:
(JSC::SyntaxChecker::operatorStackPop):
* tests/es6.yaml:
* tests/es6/destructuring_assignment_computed_properties.js: Added.
(test):
(test.computeName):
(test.loadValue):
(test.out.get a):
(test.out.set a):
(test.out.get b):
(test.out.set b):
(test.out.get c):
(test.out.set c):
(test.get var):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@192768 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp b/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
index 312a8c7..4a7e2e7 100644
--- a/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
+++ b/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
@@ -3340,7 +3340,13 @@
for (size_t i = 0; i < m_targetPatterns.size(); i++) {
auto& target = m_targetPatterns[i];
RefPtr<RegisterID> temp = generator.newTemporary();
- generator.emitGetById(temp.get(), rhs, target.propertyName);
+ if (!target.propertyExpression)
+ generator.emitGetById(temp.get(), rhs, target.propertyName);
+ else {
+ RefPtr<RegisterID> propertyName = generator.emitNode(target.propertyExpression);
+ generator.emitGetByVal(temp.get(), rhs, propertyName.get());
+ }
+
if (target.defaultValue)
assignDefaultValueIfUndefined(generator, temp.get(), target.defaultValue);
target.pattern->bindValue(generator, temp.get());