@@ -265,6 +265,7 @@ class Parser {
265
265
Literal* GetLiteralNumber (double value);
266
266
267
267
Handle <String> ParseIdentifier (bool * ok);
268
+ Handle <String> ParseIdentifierName (bool * ok);
268
269
Handle <String> ParseIdentifierOrGetOrSet (bool * is_get,
269
270
bool * is_set,
270
271
bool * ok);
@@ -3121,7 +3122,7 @@ Expression* Parser::ParseLeftHandSideExpression(bool* ok) {
3121
3122
case Token::PERIOD: {
3122
3123
Consume (Token::PERIOD);
3123
3124
int pos = scanner ().location ().beg_pos ;
3124
- Handle <String> name = ParseIdentifier (CHECK_OK);
3125
+ Handle <String> name = ParseIdentifierName (CHECK_OK);
3125
3126
result = factory ()->NewProperty (result, NEW (Literal (name)), pos);
3126
3127
break ;
3127
3128
}
@@ -3207,7 +3208,7 @@ Expression* Parser::ParseMemberWithNewPrefixesExpression(PositionStack* stack,
3207
3208
case Token::PERIOD: {
3208
3209
Consume (Token::PERIOD);
3209
3210
int pos = scanner ().location ().beg_pos ;
3210
- Handle <String> name = ParseIdentifier (CHECK_OK);
3211
+ Handle <String> name = ParseIdentifierName (CHECK_OK);
3211
3212
result = factory ()->NewProperty (result, NEW (Literal (name)), pos);
3212
3213
break ;
3213
3214
}
@@ -3586,8 +3587,8 @@ void Parser::BuildObjectLiteralConstantProperties(
3586
3587
Expression* Parser::ParseObjectLiteral (bool * ok) {
3587
3588
// ObjectLiteral ::
3588
3589
// '{' (
3589
- // ((Identifier | String | Number) ':' AssignmentExpression)
3590
- // | (('get' | 'set') FunctionLiteral)
3590
+ // ((IdentifierName | String | Number) ':' AssignmentExpression)
3591
+ // | (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral)
3591
3592
// )*[','] '}'
3592
3593
3593
3594
ZoneListWrapper<ObjectLiteral::Property> properties =
@@ -3597,7 +3598,8 @@ Expression* Parser::ParseObjectLiteral(bool* ok) {
3597
3598
Expect (Token::LBRACE, CHECK_OK);
3598
3599
while (peek () != Token::RBRACE) {
3599
3600
Literal* key = NULL ;
3600
- switch (peek ()) {
3601
+ Token::Value next = peek ();
3602
+ switch (next) {
3601
3603
case Token::IDENTIFIER: {
3602
3604
// Store identifier keys as literal symbols to avoid
3603
3605
// resolving them when compiling code for the object
@@ -3608,15 +3610,26 @@ Expression* Parser::ParseObjectLiteral(bool* ok) {
3608
3610
ParseIdentifierOrGetOrSet (&is_getter, &is_setter, CHECK_OK);
3609
3611
if (is_getter || is_setter) {
3610
3612
// Special handling of getter and setter syntax.
3611
- if (peek () == Token::IDENTIFIER) {
3612
- Handle <String> name = ParseIdentifier (CHECK_OK);
3613
+ Handle <String> name;
3614
+ next = peek ();
3615
+ if (next == Token::IDENTIFIER ||
3616
+ next == Token::STRING ||
3617
+ next == Token::NUMBER ||
3618
+ Token::IsKeyword (next)) {
3619
+ Consume (next);
3620
+ Handle <String> name =
3621
+ factory ()->LookupSymbol (scanner_.literal_string (),
3622
+ scanner_.literal_length ());
3613
3623
FunctionLiteral* value =
3614
- ParseFunctionLiteral (name, RelocInfo::kNoPosition ,
3615
- DECLARATION, CHECK_OK);
3624
+ ParseFunctionLiteral (name,
3625
+ RelocInfo::kNoPosition ,
3626
+ DECLARATION,
3627
+ CHECK_OK);
3616
3628
ObjectLiteral::Property* property =
3617
3629
NEW (ObjectLiteral::Property (is_getter, value));
3618
- if (IsBoilerplateProperty (property))
3630
+ if (IsBoilerplateProperty (property)) {
3619
3631
number_of_boilerplate_properties++;
3632
+ }
3620
3633
properties.Add (property);
3621
3634
if (peek () != Token::RBRACE) Expect (Token::COMMA, CHECK_OK);
3622
3635
continue ; // restart the while
@@ -3625,14 +3638,20 @@ Expression* Parser::ParseObjectLiteral(bool* ok) {
3625
3638
key = NEW (Literal (id));
3626
3639
break ;
3627
3640
}
3628
-
3641
+ #define CASE_KEYWORD (name, ignore1, ignore2 ) \
3642
+ case Token::name:
3643
+ TOKEN_LIST (IGNORE_TOKEN, CASE_KEYWORD, IGNORE_TOKEN)
3644
+ #undef CASE_KEYWORD
3645
+ // FALLTHROUGH - keyword tokens fall through to the same code as strings.
3629
3646
case Token::STRING: {
3630
- Consume (Token::STRING );
3647
+ Consume (next );
3631
3648
Handle <String> string =
3632
3649
factory ()->LookupSymbol (scanner_.literal_string (),
3633
3650
scanner_.literal_length ());
3634
3651
uint32_t index ;
3635
- if (!string.is_null () && string->AsArrayIndex (&index )) {
3652
+ if (next == Token::STRING &&
3653
+ !string.is_null () &&
3654
+ string->AsArrayIndex (&index )) {
3636
3655
key = NewNumberLiteral (index );
3637
3656
} else {
3638
3657
key = NEW (Literal (string));
@@ -4008,6 +4027,19 @@ Handle<String> Parser::ParseIdentifier(bool* ok) {
4008
4027
scanner_.literal_length ());
4009
4028
}
4010
4029
4030
+
4031
+ Handle <String> Parser::ParseIdentifierName (bool * ok) {
4032
+ Token::Value next = Next ();
4033
+ if (next != Token::IDENTIFIER && !Token::IsKeyword (next)) {
4034
+ ReportUnexpectedToken (next);
4035
+ *ok = false ;
4036
+ return Handle <String>();
4037
+ }
4038
+ return factory ()->LookupSymbol (scanner_.literal_string (),
4039
+ scanner_.literal_length ());
4040
+ }
4041
+
4042
+
4011
4043
// This function reads an identifier and determines whether or not it
4012
4044
// is 'get' or 'set'. The reason for not using ParseIdentifier and
4013
4045
// checking on the output is that this involves heap allocation which
0 commit comments