Chromium Code Reviews| Index: src/preparser.h | 
| diff --git a/src/preparser.h b/src/preparser.h | 
| index 828f284c1648717b073bf125a54cb64a65ab6293..800794bb3c62e3ebb4c1cf73bbc4f9ed111556b3 100644 | 
| --- a/src/preparser.h | 
| +++ b/src/preparser.h | 
| @@ -769,7 +769,8 @@ class PreParserFactory { | 
| return PreParserExpression::Default(); | 
| } | 
| PreParserExpression NewObjectLiteralProperty(PreParserExpression key, | 
| - PreParserExpression value) { | 
| + PreParserExpression value, | 
| + bool is_computed_name) { | 
| return PreParserExpression::Default(); | 
| } | 
| PreParserExpression NewObjectLiteral(PreParserExpressionList properties, | 
| @@ -1496,7 +1497,8 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral( | 
| // ObjectLiteral :: | 
| // '{' (( | 
| // ((IdentifierName | String | Number) ':' AssignmentExpression) | | 
| - // (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral) | 
| + // (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral)| | 
| + // ('[' AssignmentExpression ']' ':' AssignmentExpression) | 
| // ) ',')* '}' | 
| // (Except that trailing comma is not required and not allowed.) | 
| @@ -1505,6 +1507,7 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral( | 
| this->NewPropertyList(4, zone_); | 
| int number_of_boilerplate_properties = 0; | 
| bool has_function = false; | 
| + bool has_computed_names = false; | 
| ObjectLiteralChecker checker(this, strict_mode()); | 
| @@ -1513,7 +1516,8 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral( | 
| while (peek() != Token::RBRACE) { | 
| if (fni_ != NULL) fni_->Enter(); | 
| - typename Traits::Type::Literal key = this->EmptyLiteral(); | 
| + bool is_computed_name = false; | 
| + ExpressionT key = this->EmptyLiteral(); | 
| Token::Value next = peek(); | 
| int next_pos = peek_position(); | 
| @@ -1538,6 +1542,8 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral( | 
| next != i::Token::NUMBER && | 
| next != i::Token::STRING && | 
| !Token::IsKeyword(next)) { | 
| + // FIXME(wingo): Add support for computed property names here, as in | 
| + // get [AssignmentExpression]() { .. }. | 
| ReportUnexpectedToken(next); | 
| *ok = false; | 
| return this->EmptyLiteral(); | 
| @@ -1557,7 +1563,7 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral( | 
| // Specification only allows zero parameters for get and one for set. | 
| typename Traits::Type::ObjectLiteralProperty property = | 
| factory()->NewObjectLiteralProperty(is_getter, value, next_pos); | 
| - if (this->IsBoilerplateProperty(property)) { | 
| + if (!has_computed_names && this->IsBoilerplateProperty(property)) { | 
| number_of_boilerplate_properties++; | 
| } | 
| properties->Add(property, zone()); | 
| @@ -1595,6 +1601,16 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral( | 
| factory()); | 
| break; | 
| } | 
| + case Token::LBRACK: { | 
| + if (FLAG_harmony_object_literals) { | 
| + Consume(Token::LBRACK); | 
| + has_computed_names = true; | 
| + is_computed_name = true; | 
| + key = this->ParseAssignmentExpression(true, CHECK_OK); | 
| + Expect(Token::RBRACK, CHECK_OK); | 
| + break; | 
| + } | 
| + } | 
| 
 
rossberg
2014/06/18 14:13:40
Add a fall-through comment
 
 | 
| default: | 
| if (Token::IsKeyword(next)) { | 
| Consume(next); | 
| @@ -1609,13 +1625,15 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral( | 
| } | 
| // Validate the property | 
| - checker.CheckProperty(next, kValueProperty, CHECK_OK); | 
| + if (!is_computed_name) { | 
| + checker.CheckProperty(next, kValueProperty, CHECK_OK); | 
| + } | 
| Expect(Token::COLON, CHECK_OK); | 
| ExpressionT value = this->ParseAssignmentExpression(true, CHECK_OK); | 
| typename Traits::Type::ObjectLiteralProperty property = | 
| - factory()->NewObjectLiteralProperty(key, value); | 
| + factory()->NewObjectLiteralProperty(key, value, is_computed_name); | 
| // Mark top-level object literals that contain function literals and | 
| // pretenure the literal so it can be added as a constant function | 
| @@ -1624,7 +1642,7 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral( | 
| &has_function); | 
| // Count CONSTANT or COMPUTED properties to maintain the enumeration order. | 
| - if (this->IsBoilerplateProperty(property)) { | 
| + if (!has_computed_names && this->IsBoilerplateProperty(property)) { | 
| number_of_boilerplate_properties++; | 
| } | 
| properties->Add(property, zone()); |