Index: src/preparser.h |
diff --git a/src/preparser.h b/src/preparser.h |
index 828f284c1648717b073bf125a54cb64a65ab6293..c6085655f1aaba40edc45913efed7dff898360e8 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,14 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral( |
factory()); |
break; |
} |
+ case Token::LBRACK: { |
+ Consume(Token::LBRACK); |
+ has_computed_names = true; |
+ is_computed_name = true; |
Michael Starzinger
2014/06/13 08:14:18
Shouldn't the detection of this syntax live behind
rossberg
2014/06/13 15:19:24
I agree, we should have --harmony-object-literals
wingo
2014/06/16 08:32:27
Done.
|
+ key = this->ParseAssignmentExpression(true, CHECK_OK); |
+ Expect(Token::RBRACK, CHECK_OK); |
+ break; |
+ } |
default: |
if (Token::IsKeyword(next)) { |
Consume(next); |
@@ -1609,13 +1623,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 +1640,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()); |