Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (192767 => 192768)
--- trunk/Source/_javascript_Core/ChangeLog 2015-11-25 00:20:42 UTC (rev 192767)
+++ trunk/Source/_javascript_Core/ChangeLog 2015-11-25 01:43:14 UTC (rev 192768)
@@ -1,3 +1,44 @@
+2015-11-24 Caitlin Potter <[email protected]>
+
+ [JSC] support Computed Property Names in destructuring Patterns
+ https://bugs.webkit.org/show_bug.cgi?id=151494
+
+ 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):
+
2015-11-24 Commit Queue <[email protected]>
Unreviewed, rolling out r192536, r192722, and r192743.
Modified: trunk/Source/_javascript_Core/bytecompiler/NodesCodegen.cpp (192767 => 192768)
--- trunk/Source/_javascript_Core/bytecompiler/NodesCodegen.cpp 2015-11-25 00:20:42 UTC (rev 192767)
+++ trunk/Source/_javascript_Core/bytecompiler/NodesCodegen.cpp 2015-11-25 01:43:14 UTC (rev 192768)
@@ -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());
Modified: trunk/Source/_javascript_Core/parser/ASTBuilder.h (192767 => 192768)
--- trunk/Source/_javascript_Core/parser/ASTBuilder.h 2015-11-25 00:20:42 UTC (rev 192767)
+++ trunk/Source/_javascript_Core/parser/ASTBuilder.h 2015-11-25 01:43:14 UTC (rev 192768)
@@ -851,7 +851,12 @@
{
node->appendEntry(location, identifier, wasString, pattern, defaultValue);
}
-
+
+ void appendObjectPatternEntry(ObjectPattern node, const JSTokenLocation& location, ExpressionNode* propertyExpression, DestructuringPattern pattern, ExpressionNode* defaultValue)
+ {
+ node->appendEntry(location, propertyExpression, pattern, defaultValue);
+ }
+
BindingPattern createBindingLocation(const JSTokenLocation&, const Identifier& boundProperty, const JSTextPosition& start, const JSTextPosition& end, AssignmentContext context)
{
return new (m_parserArena) BindingNode(boundProperty, start, end, context);
Modified: trunk/Source/_javascript_Core/parser/Nodes.h (192767 => 192768)
--- trunk/Source/_javascript_Core/parser/Nodes.h 2015-11-25 00:20:42 UTC (rev 192767)
+++ trunk/Source/_javascript_Core/parser/Nodes.h 2015-11-25 01:43:14 UTC (rev 192768)
@@ -2017,15 +2017,21 @@
ObjectPatternNode();
void appendEntry(const JSTokenLocation&, const Identifier& identifier, bool wasString, DestructuringPatternNode* pattern, ExpressionNode* defaultValue)
{
- m_targetPatterns.append(Entry{ identifier, wasString, pattern, defaultValue });
+ m_targetPatterns.append(Entry{ identifier, nullptr, wasString, pattern, defaultValue });
}
+ void appendEntry(const JSTokenLocation&, ExpressionNode* propertyExpression, DestructuringPatternNode* pattern, ExpressionNode* defaultValue)
+ {
+ m_targetPatterns.append(Entry{ Identifier(), propertyExpression, false, pattern, defaultValue });
+ }
+
private:
virtual void collectBoundIdentifiers(Vector<Identifier>&) const override;
virtual void bindValue(BytecodeGenerator&, RegisterID*) const override;
virtual void toString(StringBuilder&) const override;
struct Entry {
const Identifier& propertyName;
+ ExpressionNode* propertyExpression;
bool wasString;
DestructuringPatternNode* pattern;
ExpressionNode* defaultValue;
Modified: trunk/Source/_javascript_Core/parser/Parser.cpp (192767 => 192768)
--- trunk/Source/_javascript_Core/parser/Parser.cpp 2015-11-25 00:20:42 UTC (rev 192767)
+++ trunk/Source/_javascript_Core/parser/Parser.cpp 2015-11-25 01:43:14 UTC (rev 192768)
@@ -861,6 +861,7 @@
break;
const Identifier* propertyName = nullptr;
+ TreeExpression propertyExpression = 0;
TreeDestructuringPattern innerPattern = 0;
JSTokenLocation location = m_token.m_location;
if (matchSpecIdentifier()) {
@@ -883,6 +884,12 @@
propertyName = m_token.m_data.ident;
wasString = true;
break;
+ case OPENBRACKET:
+ next();
+ propertyExpression = parseAssignmentExpression(context);
+ failIfFalse(propertyExpression, "Cannot parse computed property name");
+ matchOrFail(CLOSEBRACKET, "Expected ']' to end end a computed property name");
+ break;
default:
if (m_token.m_type != RESERVED && m_token.m_type != RESERVED_IF_STRICT && !(m_token.m_type & KeywordTokenFlag)) {
if (kind == DestructureToExpressions)
@@ -908,8 +915,12 @@
return 0;
failIfFalse(innerPattern, "Cannot parse this destructuring pattern");
TreeExpression defaultValue = parseDefaultValueForDestructuringPattern(context);
- ASSERT(propertyName);
- context.appendObjectPatternEntry(objectPattern, location, wasString, *propertyName, innerPattern, defaultValue);
+ if (propertyExpression)
+ context.appendObjectPatternEntry(objectPattern, location, propertyExpression, innerPattern, defaultValue);
+ else {
+ ASSERT(propertyName);
+ context.appendObjectPatternEntry(objectPattern, location, wasString, *propertyName, innerPattern, defaultValue);
+ }
} while (consume(COMMA));
if (kind == DestructureToExpressions && !match(CLOSEBRACE))
Modified: trunk/Source/_javascript_Core/parser/SyntaxChecker.h (192767 => 192768)
--- trunk/Source/_javascript_Core/parser/SyntaxChecker.h 2015-11-25 00:20:42 UTC (rev 192767)
+++ trunk/Source/_javascript_Core/parser/SyntaxChecker.h 2015-11-25 01:43:14 UTC (rev 192768)
@@ -343,6 +343,10 @@
void appendObjectPatternEntry(ArrayPattern, const JSTokenLocation&, bool, const Identifier&, DestructuringPattern, int)
{
}
+ void appendObjectPatternEntry(ArrayPattern, const JSTokenLocation&, _expression_, DestructuringPattern, _expression_)
+ {
+ }
+
DestructuringPattern createBindingLocation(const JSTokenLocation&, const Identifier&, const JSTextPosition&, const JSTextPosition&, AssignmentContext)
{
return BindingDestructuring;
Added: trunk/Source/_javascript_Core/tests/es6/destructuring_assignment_computed_properties.js (0 => 192768)
--- trunk/Source/_javascript_Core/tests/es6/destructuring_assignment_computed_properties.js (rev 0)
+++ trunk/Source/_javascript_Core/tests/es6/destructuring_assignment_computed_properties.js 2015-11-25 01:43:14 UTC (rev 192768)
@@ -0,0 +1,72 @@
+function test() {
+ var steps = [];
+ var backingStore = {};
+
+ function storeProperty(name, value) {
+ steps.push(`store: ${name} = ${value}`);
+ backingStore[name] = value;
+ }
+
+ function computeName(name) {
+ steps.push(`compute: ${name}`);
+ return name;
+ }
+
+ function loadValue(name, value) {
+ steps.push(`load: ${name} > ${value}`);
+ return value;
+ }
+
+ var out = {
+ get a() { return backingStore.a; },
+ set a(v) { storeProperty("a", v); },
+ get b() { return backingStore.b; },
+ set b(v) { storeProperty("b", v); },
+ get c() { return backingStore.c; },
+ set c(v) { storeProperty("c", v); },
+ get d() { return backingStore.d; },
+ set d(v) { storeProperty("d", v); }
+ };
+ ({
+ [computeName("propA")]: out.a,
+ [computeName("propB")]: out.b,
+ [computeName("propC")]: [...out["c"]],
+ [computeName("propD")]: out.d = "default"
+ } = {
+ get propA() { return loadValue("propA", "hello"); },
+ get propB() { return loadValue("propB", "world"); },
+ get propC() { return loadValue("propC", [1, 2, 3]); },
+ get propD() { return loadValue("propD"); }
+ });
+
+ var expectedSteps = [
+ "compute: propA",
+ "load: propA > hello",
+ "store: a = hello",
+
+ "compute: propB",
+ "load: propB > world",
+ "store: b = world",
+
+ "compute: propC",
+ "load: propC > 1,2,3",
+ "store: c = 1,2,3",
+
+ "compute: propD",
+ "load: propD > undefined",
+ "store: d = default"
+ ];
+
+ if (expectedSteps.length !== steps.length)
+ return false;
+ for (var i = 0; i < expectedSteps.length; ++i)
+ if (expectedSteps[i] !== steps[i])
+ return false;
+ if (`${backingStore.a} ${backingStore.b} ${backingStore.c.join(":")}` !== "hello world 1:2:3")
+ return false;
+
+ return true;
+}
+
+if (!test())
+ throw new Error("Test failed");
Added: trunk/Source/_javascript_Core/tests/es6/destructuring_assignment_computed_property_default.js (0 => 192768)
--- trunk/Source/_javascript_Core/tests/es6/destructuring_assignment_computed_property_default.js (rev 0)
+++ trunk/Source/_javascript_Core/tests/es6/destructuring_assignment_computed_property_default.js 2015-11-25 01:43:14 UTC (rev 192768)
@@ -0,0 +1,8 @@
+function test() {
+ var result0, result1, i = 0;
+ ({ [i++]: result0 = "hungryByDefault", [i++]: result1 = "hippoByDefault"} = []);
+ return result0 === "hungryByDefault" && result1 === "hippoByDefault" && i === 2;
+}
+
+if (!test())
+ throw new Error("Test failed");
Added: trunk/Source/_javascript_Core/tests/es6/destructuring_assignment_computed_property_simple.js (0 => 192768)
--- trunk/Source/_javascript_Core/tests/es6/destructuring_assignment_computed_property_simple.js (rev 0)
+++ trunk/Source/_javascript_Core/tests/es6/destructuring_assignment_computed_property_simple.js 2015-11-25 01:43:14 UTC (rev 192768)
@@ -0,0 +1,8 @@
+function test() {
+ var result0, result1, i = 0;
+ ({ [i++]: result0, [i++]: result1 } = ["hungryhungry", "hippos"]);
+ return result0 === "hungryhungry" && result1 === "hippos" && i === 2;
+}
+
+if (!test())
+ throw new Error("Test failed");
Modified: trunk/Source/_javascript_Core/tests/es6.yaml (192767 => 192768)
--- trunk/Source/_javascript_Core/tests/es6.yaml 2015-11-25 00:20:42 UTC (rev 192767)
+++ trunk/Source/_javascript_Core/tests/es6.yaml 2015-11-25 01:43:14 UTC (rev 192768)
@@ -216,6 +216,12 @@
cmd: runES6 :normal
- path: es6/destructuring_assignment_non_simple_target.js
cmd: runES6 :normal
+- path: es6/destructuring_assignment_computed_properties.js
+ cmd: runES6 :normal
+- path: es6/destructuring_assignment_computed_property_simple.js
+ cmd: runES6 :normal
+- path: es6/destructuring_assignment_computed_property_default.js
+ cmd: runES6 :normal
- path: es6/destructuring_initializer_scoping.js
cmd: runES6 :normal
- path: es6/for..of_loops_with_arrays.js
@@ -745,7 +751,7 @@
- path: es6/block-level_function_declaration.js
cmd: runES6 :fail
- path: es6/destructuring_computed_properties.js
- cmd: runES6 :fail
+ cmd: runES6 :normal
- path: es6/destructuring_defaults_in_parameters_separate_scope.js
cmd: runES6 :fail
- path: es6/destructuring_iterator_closing.js