OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <cmath> | 5 #include <cmath> |
6 | 6 |
7 #include "src/allocation.h" | 7 #include "src/allocation.h" |
8 #include "src/base/logging.h" | 8 #include "src/base/logging.h" |
9 #include "src/conversions-inl.h" | 9 #include "src/conversions-inl.h" |
10 #include "src/conversions.h" | 10 #include "src/conversions.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 | 128 |
129 // The PreParser checks that the syntax follows the grammar for JavaScript, | 129 // The PreParser checks that the syntax follows the grammar for JavaScript, |
130 // and collects some information about the program along the way. | 130 // and collects some information about the program along the way. |
131 // The grammar check is only performed in order to understand the program | 131 // The grammar check is only performed in order to understand the program |
132 // sufficiently to deduce some information about it, that can be used | 132 // sufficiently to deduce some information about it, that can be used |
133 // to speed up later parsing. Finding errors is not the goal of pre-parsing, | 133 // to speed up later parsing. Finding errors is not the goal of pre-parsing, |
134 // rather it is to speed up properly written and correct programs. | 134 // rather it is to speed up properly written and correct programs. |
135 // That means that contextual checks (like a label being declared where | 135 // That means that contextual checks (like a label being declared where |
136 // it is used) are generally omitted. | 136 // it is used) are generally omitted. |
137 | 137 |
138 PreParser::Statement PreParser::ParseClassDeclaration( | |
139 ZoneList<const AstRawString*>* names, bool default_export, bool* ok) { | |
140 int pos = position(); | |
141 bool is_strict_reserved = false; | |
142 Identifier name = | |
143 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); | |
144 ExpressionClassifier no_classifier(this); | |
145 ParseClassLiteral(name, scanner()->location(), is_strict_reserved, pos, | |
146 CHECK_OK); | |
147 return Statement::Default(); | |
148 } | |
149 | |
150 PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) { | 138 PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) { |
151 Consume(Token::FUNCTION); | 139 Consume(Token::FUNCTION); |
152 int pos = position(); | 140 int pos = position(); |
153 ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal; | 141 ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal; |
154 if (Check(Token::MUL)) { | 142 if (Check(Token::MUL)) { |
155 flags |= ParseFunctionFlags::kIsGenerator; | 143 flags |= ParseFunctionFlags::kIsGenerator; |
156 if (allow_harmony_restrictive_declarations()) { | 144 if (allow_harmony_restrictive_declarations()) { |
157 ReportMessageAt(scanner()->location(), | 145 ReportMessageAt(scanner()->location(), |
158 MessageTemplate::kGeneratorInLegacyContext); | 146 MessageTemplate::kGeneratorInLegacyContext); |
159 *ok = false; | 147 *ok = false; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 int body_end = scanner()->peek_location().end_pos; | 232 int body_end = scanner()->peek_location().end_pos; |
245 DeclarationScope* scope = this->scope()->AsDeclarationScope(); | 233 DeclarationScope* scope = this->scope()->AsDeclarationScope(); |
246 DCHECK(scope->is_function_scope()); | 234 DCHECK(scope->is_function_scope()); |
247 log_->LogFunction(body_start, body_end, | 235 log_->LogFunction(body_start, body_end, |
248 function_state_->materialized_literal_count(), | 236 function_state_->materialized_literal_count(), |
249 function_state_->expected_property_count(), language_mode(), | 237 function_state_->expected_property_count(), language_mode(), |
250 scope->uses_super_property(), scope->calls_eval()); | 238 scope->uses_super_property(), scope->calls_eval()); |
251 return kLazyParsingComplete; | 239 return kLazyParsingComplete; |
252 } | 240 } |
253 | 241 |
254 PreParserExpression PreParser::ParseClassLiteral( | |
255 PreParserIdentifier name, Scanner::Location class_name_location, | |
256 bool name_is_strict_reserved, int pos, bool* ok) { | |
257 // All parts of a ClassDeclaration and ClassExpression are strict code. | |
258 if (name_is_strict_reserved) { | |
259 ReportMessageAt(class_name_location, | |
260 MessageTemplate::kUnexpectedStrictReserved); | |
261 *ok = false; | |
262 return EmptyExpression(); | |
263 } | |
264 if (IsEvalOrArguments(name)) { | |
265 ReportMessageAt(class_name_location, MessageTemplate::kStrictEvalArguments); | |
266 *ok = false; | |
267 return EmptyExpression(); | |
268 } | |
269 | |
270 LanguageMode class_language_mode = language_mode(); | |
271 BlockState block_state(zone(), &scope_state_); | |
272 scope()->SetLanguageMode( | |
273 static_cast<LanguageMode>(class_language_mode | STRICT)); | |
274 // TODO(marja): Make PreParser use scope names too. | |
275 // this->scope()->SetScopeName(name); | |
276 | |
277 bool has_extends = Check(Token::EXTENDS); | |
278 if (has_extends) { | |
279 ExpressionClassifier extends_classifier(this); | |
280 ParseLeftHandSideExpression(CHECK_OK); | |
281 ValidateExpression(CHECK_OK); | |
282 impl()->AccumulateFormalParameterContainmentErrors(); | |
283 } | |
284 | |
285 ClassLiteralChecker checker(this); | |
286 bool has_seen_constructor = false; | |
287 | |
288 Expect(Token::LBRACE, CHECK_OK); | |
289 while (peek() != Token::RBRACE) { | |
290 if (Check(Token::SEMICOLON)) continue; | |
291 bool is_computed_name = false; // Classes do not care about computed | |
292 // property names here. | |
293 ExpressionClassifier property_classifier(this); | |
294 ParseClassPropertyDefinition(&checker, has_extends, &is_computed_name, | |
295 &has_seen_constructor, CHECK_OK); | |
296 ValidateExpression(CHECK_OK); | |
297 impl()->AccumulateFormalParameterContainmentErrors(); | |
298 } | |
299 | |
300 Expect(Token::RBRACE, CHECK_OK); | |
301 | |
302 return Expression::Default(); | |
303 } | |
304 | |
305 PreParserExpression PreParser::ExpressionFromIdentifier( | 242 PreParserExpression PreParser::ExpressionFromIdentifier( |
306 PreParserIdentifier name, int start_position, int end_position, | 243 PreParserIdentifier name, int start_position, int end_position, |
307 InferName infer) { | 244 InferName infer) { |
308 if (track_unresolved_variables_) { | 245 if (track_unresolved_variables_) { |
309 AstNodeFactory factory(ast_value_factory()); | 246 AstNodeFactory factory(ast_value_factory()); |
310 // Setting the Zone is necessary because zone_ might be the temp Zone, and | 247 // Setting the Zone is necessary because zone_ might be the temp Zone, and |
311 // AstValueFactory doesn't know about it. | 248 // AstValueFactory doesn't know about it. |
312 factory.set_zone(zone()); | 249 factory.set_zone(zone()); |
313 DCHECK_NOT_NULL(name.string_); | 250 DCHECK_NOT_NULL(name.string_); |
314 scope()->NewUnresolved(&factory, name.string_, start_position, end_position, | 251 scope()->NewUnresolved(&factory, name.string_, start_position, end_position, |
315 NORMAL_VARIABLE); | 252 NORMAL_VARIABLE); |
316 } | 253 } |
317 return PreParserExpression::FromIdentifier(name); | 254 return PreParserExpression::FromIdentifier(name); |
318 } | 255 } |
319 | 256 |
320 #undef CHECK_OK | 257 #undef CHECK_OK |
321 #undef CHECK_OK_CUSTOM | 258 #undef CHECK_OK_CUSTOM |
322 | 259 |
323 | 260 |
324 } // namespace internal | 261 } // namespace internal |
325 } // namespace v8 | 262 } // namespace v8 |
OLD | NEW |