Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: src/preparser.cc

Issue 192993002: Move ParseObjectLiteral to ParserBase. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased on top of rossberg@s changes Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/preparser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 scanner->literal_length() == kUseStrictLength && 115 scanner->literal_length() == kUseStrictLength &&
116 !scanner->literal_contains_escapes() && 116 !scanner->literal_contains_escapes() &&
117 !strncmp(scanner->literal_ascii_string().start(), kUseStrictChars, 117 !strncmp(scanner->literal_ascii_string().start(), kUseStrictChars,
118 kUseStrictLength)) { 118 kUseStrictLength)) {
119 return PreParserExpression::UseStrictStringLiteral(); 119 return PreParserExpression::UseStrictStringLiteral();
120 } 120 }
121 return PreParserExpression::StringLiteral(); 121 return PreParserExpression::StringLiteral();
122 } 122 }
123 123
124 124
125 PreParserExpression PreParserTraits::ParseObjectLiteral(bool* ok) {
126 return pre_parser_->ParseObjectLiteral(ok);
127 }
128
129
130 PreParserExpression PreParserTraits::ParseAssignmentExpression(bool accept_IN, 125 PreParserExpression PreParserTraits::ParseAssignmentExpression(bool accept_IN,
131 bool* ok) { 126 bool* ok) {
132 return pre_parser_->ParseAssignmentExpression(accept_IN, ok); 127 return pre_parser_->ParseAssignmentExpression(accept_IN, ok);
133 } 128 }
134 129
135 130
136 PreParserExpression PreParserTraits::ParseV8Intrinsic(bool* ok) { 131 PreParserExpression PreParserTraits::ParseV8Intrinsic(bool* ok) {
137 return pre_parser_->ParseV8Intrinsic(ok); 132 return pre_parser_->ParseV8Intrinsic(ok);
138 } 133 }
139 134
140 135
136 PreParserExpression PreParserTraits::ParseFunctionLiteral(
137 PreParserIdentifier name,
138 Scanner::Location function_name_location,
139 bool name_is_strict_reserved,
140 bool is_generator,
141 int function_token_position,
142 FunctionLiteral::FunctionType type,
143 bool* ok) {
144 return pre_parser_->ParseFunctionLiteral(
145 name, function_name_location, name_is_strict_reserved, is_generator,
146 function_token_position, type, ok);
147 }
148
149
141 PreParser::PreParseResult PreParser::PreParseLazyFunction( 150 PreParser::PreParseResult PreParser::PreParseLazyFunction(
142 StrictMode strict_mode, bool is_generator, ParserRecorder* log) { 151 StrictMode strict_mode, bool is_generator, ParserRecorder* log) {
143 log_ = log; 152 log_ = log;
144 // Lazy functions always have trivial outer scopes (no with/catch scopes). 153 // Lazy functions always have trivial outer scopes (no with/catch scopes).
145 PreParserScope top_scope(scope_, GLOBAL_SCOPE); 154 PreParserScope top_scope(scope_, GLOBAL_SCOPE);
146 FunctionState top_state(&function_state_, &scope_, &top_scope); 155 FunctionState top_state(&function_state_, &scope_, &top_scope);
147 scope_->SetStrictMode(strict_mode); 156 scope_->SetStrictMode(strict_mode);
148 PreParserScope function_scope(scope_, FUNCTION_SCOPE); 157 PreParserScope function_scope(scope_, FUNCTION_SCOPE);
149 FunctionState function_state(&function_state_, &scope_, &function_scope); 158 FunctionState function_state(&function_state_, &scope_, &function_scope);
150 function_state.set_is_generator(is_generator); 159 function_state.set_is_generator(is_generator);
(...skipping 968 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 } 1128 }
1120 default: 1129 default:
1121 return expression; 1130 return expression;
1122 } 1131 }
1123 } 1132 }
1124 ASSERT(false); 1133 ASSERT(false);
1125 return PreParserExpression::Default(); 1134 return PreParserExpression::Default();
1126 } 1135 }
1127 1136
1128 1137
1129 PreParser::Expression PreParser::ParseObjectLiteral(bool* ok) {
1130 // ObjectLiteral ::
1131 // '{' ((
1132 // ((IdentifierName | String | Number) ':' AssignmentExpression) |
1133 // (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral)
1134 // ) ',')* '}'
1135 // (Except that trailing comma is not required and not allowed.)
1136
1137 ObjectLiteralChecker checker(this, strict_mode());
1138
1139 Expect(Token::LBRACE, CHECK_OK);
1140 while (peek() != Token::RBRACE) {
1141 Token::Value next = peek();
1142 switch (next) {
1143 case Token::IDENTIFIER:
1144 case Token::FUTURE_RESERVED_WORD:
1145 case Token::FUTURE_STRICT_RESERVED_WORD: {
1146 bool is_getter = false;
1147 bool is_setter = false;
1148 ParseIdentifierNameOrGetOrSet(&is_getter, &is_setter, CHECK_OK);
1149 if ((is_getter || is_setter) && peek() != Token::COLON) {
1150 Token::Value next = Next();
1151 if (next != Token::IDENTIFIER &&
1152 next != Token::FUTURE_RESERVED_WORD &&
1153 next != Token::FUTURE_STRICT_RESERVED_WORD &&
1154 next != Token::NUMBER &&
1155 next != Token::STRING &&
1156 !Token::IsKeyword(next)) {
1157 ReportUnexpectedToken(next);
1158 *ok = false;
1159 return Expression::Default();
1160 }
1161 // Validate the property
1162 PropertyKind type = is_getter ? kGetterProperty : kSetterProperty;
1163 checker.CheckProperty(next, type, CHECK_OK);
1164 PreParserIdentifier name = GetSymbol(scanner());
1165 ParseFunctionLiteral(name,
1166 scanner()->location(),
1167 false, // reserved words are allowed here
1168 false, // not a generator
1169 RelocInfo::kNoPosition,
1170 FunctionLiteral::ANONYMOUS_EXPRESSION,
1171 CHECK_OK);
1172 if (peek() != Token::RBRACE) {
1173 Expect(Token::COMMA, CHECK_OK);
1174 }
1175 continue; // restart the while
1176 }
1177 break;
1178 }
1179 case Token::STRING:
1180 Consume(next);
1181 LogSymbol();
1182 break;
1183 case Token::NUMBER:
1184 Consume(next);
1185 break;
1186 default:
1187 if (Token::IsKeyword(next)) {
1188 Consume(next);
1189 LogSymbol();
1190 } else {
1191 Token::Value next = Next();
1192 ReportUnexpectedToken(next);
1193 *ok = false;
1194 return Expression::Default();
1195 }
1196 }
1197
1198 // Validate the property
1199 checker.CheckProperty(next, kValueProperty, CHECK_OK);
1200
1201 Expect(Token::COLON, CHECK_OK);
1202 ParseAssignmentExpression(true, CHECK_OK);
1203
1204 // TODO(1240767): Consider allowing trailing comma.
1205 if (peek() != Token::RBRACE) Expect(Token::COMMA, CHECK_OK);
1206 }
1207 Expect(Token::RBRACE, CHECK_OK);
1208
1209 function_state_->NextMaterializedLiteralIndex();
1210 return Expression::Default();
1211 }
1212
1213
1214 PreParser::Arguments PreParser::ParseArguments(bool* ok) { 1138 PreParser::Arguments PreParser::ParseArguments(bool* ok) {
1215 // Arguments :: 1139 // Arguments ::
1216 // '(' (AssignmentExpression)*[','] ')' 1140 // '(' (AssignmentExpression)*[','] ')'
1217 1141
1218 Expect(Token::LPAREN, ok); 1142 Expect(Token::LPAREN, ok);
1219 if (!*ok) return -1; 1143 if (!*ok) return -1;
1220 bool done = (peek() == Token::RPAREN); 1144 bool done = (peek() == Token::RPAREN);
1221 int argc = 0; 1145 int argc = 0;
1222 while (!done) { 1146 while (!done) {
1223 ParseAssignmentExpression(true, ok); 1147 ParseAssignmentExpression(true, ok);
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 int identifier_pos = position(); 1309 int identifier_pos = position();
1386 if (scanner()->is_literal_ascii()) { 1310 if (scanner()->is_literal_ascii()) {
1387 log_->LogAsciiSymbol(identifier_pos, scanner()->literal_ascii_string()); 1311 log_->LogAsciiSymbol(identifier_pos, scanner()->literal_ascii_string());
1388 } else { 1312 } else {
1389 log_->LogUtf16Symbol(identifier_pos, scanner()->literal_utf16_string()); 1313 log_->LogUtf16Symbol(identifier_pos, scanner()->literal_utf16_string());
1390 } 1314 }
1391 } 1315 }
1392 1316
1393 1317
1394 } } // v8::internal 1318 } } // v8::internal
OLDNEW
« no previous file with comments | « src/preparser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698