OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1117 return expression; | 1117 return expression; |
1118 } | 1118 } |
1119 } | 1119 } |
1120 ASSERT(false); | 1120 ASSERT(false); |
1121 return PreParserExpression::Default(); | 1121 return PreParserExpression::Default(); |
1122 } | 1122 } |
1123 | 1123 |
1124 | 1124 |
1125 PreParser::Expression PreParser::ParseObjectLiteral(bool* ok) { | 1125 PreParser::Expression PreParser::ParseObjectLiteral(bool* ok) { |
1126 // ObjectLiteral :: | 1126 // ObjectLiteral :: |
1127 // '{' ( | 1127 // '{' (( |
1128 // ((IdentifierName | String | Number) ':' AssignmentExpression) | 1128 // ((IdentifierName | String | Number) ':' AssignmentExpression) | |
1129 // | (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral) | 1129 // (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral) |
1130 // )*[','] '}' | 1130 // ) ',')* '}' |
| 1131 // (Except that trailing comma is not required and not allowed.) |
1131 | 1132 |
1132 ObjectLiteralChecker checker(this, scope_->language_mode()); | 1133 ObjectLiteralChecker checker(this, scope_->language_mode()); |
1133 | 1134 |
1134 Expect(Token::LBRACE, CHECK_OK); | 1135 Expect(Token::LBRACE, CHECK_OK); |
1135 while (peek() != Token::RBRACE) { | 1136 while (peek() != Token::RBRACE) { |
1136 Token::Value next = peek(); | 1137 Token::Value next = peek(); |
1137 switch (next) { | 1138 switch (next) { |
1138 case Token::IDENTIFIER: | 1139 case Token::IDENTIFIER: |
1139 case Token::FUTURE_RESERVED_WORD: | 1140 case Token::FUTURE_RESERVED_WORD: |
1140 case Token::FUTURE_STRICT_RESERVED_WORD: { | 1141 case Token::FUTURE_STRICT_RESERVED_WORD: { |
1141 bool is_getter = false; | 1142 bool is_getter = false; |
1142 bool is_setter = false; | 1143 bool is_setter = false; |
1143 ParseIdentifierNameOrGetOrSet(&is_getter, &is_setter, CHECK_OK); | 1144 ParseIdentifierNameOrGetOrSet(&is_getter, &is_setter, CHECK_OK); |
1144 if ((is_getter || is_setter) && peek() != Token::COLON) { | 1145 if ((is_getter || is_setter) && peek() != Token::COLON) { |
1145 Token::Value name = Next(); | 1146 Token::Value next = Next(); |
1146 bool is_keyword = Token::IsKeyword(name); | 1147 if (next != Token::IDENTIFIER && |
1147 if (name != Token::IDENTIFIER && | 1148 next != Token::FUTURE_RESERVED_WORD && |
1148 name != Token::FUTURE_RESERVED_WORD && | 1149 next != Token::FUTURE_STRICT_RESERVED_WORD && |
1149 name != Token::FUTURE_STRICT_RESERVED_WORD && | 1150 next != Token::NUMBER && |
1150 name != Token::NUMBER && | 1151 next != Token::STRING && |
1151 name != Token::STRING && | 1152 !Token::IsKeyword(next)) { |
1152 !is_keyword) { | 1153 ReportUnexpectedToken(next); |
1153 *ok = false; | 1154 *ok = false; |
1154 return Expression::Default(); | 1155 return Expression::Default(); |
1155 } | 1156 } |
1156 if (!is_keyword) { | 1157 // Validate the property |
1157 LogSymbol(); | |
1158 } | |
1159 PropertyKind type = is_getter ? kGetterProperty : kSetterProperty; | 1158 PropertyKind type = is_getter ? kGetterProperty : kSetterProperty; |
1160 checker.CheckProperty(name, type, CHECK_OK); | 1159 checker.CheckProperty(next, type, CHECK_OK); |
1161 ParseFunctionLiteral(Identifier::Default(), | 1160 PreParserIdentifier name = GetSymbol(scanner()); |
| 1161 ParseFunctionLiteral(name, |
1162 scanner()->location(), | 1162 scanner()->location(), |
1163 false, // reserved words are allowed here | 1163 false, // reserved words are allowed here |
1164 false, // not a generator | 1164 false, // not a generator |
1165 CHECK_OK); | 1165 CHECK_OK); |
1166 if (peek() != Token::RBRACE) { | 1166 if (peek() != Token::RBRACE) { |
1167 Expect(Token::COMMA, CHECK_OK); | 1167 Expect(Token::COMMA, CHECK_OK); |
1168 } | 1168 } |
1169 continue; // restart the while | 1169 continue; // restart the while |
1170 } | 1170 } |
1171 checker.CheckProperty(next, kValueProperty, CHECK_OK); | |
1172 break; | 1171 break; |
1173 } | 1172 } |
1174 case Token::STRING: | 1173 case Token::STRING: |
1175 Consume(next); | 1174 Consume(next); |
1176 checker.CheckProperty(next, kValueProperty, CHECK_OK); | |
1177 LogSymbol(); | 1175 LogSymbol(); |
1178 break; | 1176 break; |
1179 case Token::NUMBER: | 1177 case Token::NUMBER: |
1180 Consume(next); | 1178 Consume(next); |
1181 checker.CheckProperty(next, kValueProperty, CHECK_OK); | |
1182 break; | 1179 break; |
1183 default: | 1180 default: |
1184 if (Token::IsKeyword(next)) { | 1181 if (Token::IsKeyword(next)) { |
1185 Consume(next); | 1182 Consume(next); |
1186 checker.CheckProperty(next, kValueProperty, CHECK_OK); | |
1187 LogSymbol(); | 1183 LogSymbol(); |
1188 } else { | 1184 } else { |
1189 // Unexpected token. | 1185 Token::Value next = Next(); |
| 1186 ReportUnexpectedToken(next); |
1190 *ok = false; | 1187 *ok = false; |
1191 return Expression::Default(); | 1188 return Expression::Default(); |
1192 } | 1189 } |
1193 } | 1190 } |
1194 | 1191 |
| 1192 // Validate the property |
| 1193 checker.CheckProperty(next, kValueProperty, CHECK_OK); |
| 1194 |
1195 Expect(Token::COLON, CHECK_OK); | 1195 Expect(Token::COLON, CHECK_OK); |
1196 ParseAssignmentExpression(true, CHECK_OK); | 1196 ParseAssignmentExpression(true, CHECK_OK); |
1197 | 1197 |
1198 // TODO(1240767): Consider allowing trailing comma. | 1198 // TODO(1240767): Consider allowing trailing comma. |
1199 if (peek() != Token::RBRACE) Expect(Token::COMMA, CHECK_OK); | 1199 if (peek() != Token::RBRACE) Expect(Token::COMMA, CHECK_OK); |
1200 } | 1200 } |
1201 Expect(Token::RBRACE, CHECK_OK); | 1201 Expect(Token::RBRACE, CHECK_OK); |
1202 | 1202 |
1203 function_state_->NextMaterializedLiteralIndex(); | 1203 function_state_->NextMaterializedLiteralIndex(); |
1204 return Expression::Default(); | 1204 return Expression::Default(); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1377 int identifier_pos = position(); | 1377 int identifier_pos = position(); |
1378 if (scanner()->is_literal_ascii()) { | 1378 if (scanner()->is_literal_ascii()) { |
1379 log_->LogAsciiSymbol(identifier_pos, scanner()->literal_ascii_string()); | 1379 log_->LogAsciiSymbol(identifier_pos, scanner()->literal_ascii_string()); |
1380 } else { | 1380 } else { |
1381 log_->LogUtf16Symbol(identifier_pos, scanner()->literal_utf16_string()); | 1381 log_->LogUtf16Symbol(identifier_pos, scanner()->literal_utf16_string()); |
1382 } | 1382 } |
1383 } | 1383 } |
1384 | 1384 |
1385 | 1385 |
1386 } } // v8::internal | 1386 } } // v8::internal |
OLD | NEW |