| 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 |
| 138 PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) { | 150 PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) { |
| 139 Consume(Token::FUNCTION); | 151 Consume(Token::FUNCTION); |
| 140 int pos = position(); | 152 int pos = position(); |
| 141 ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal; | 153 ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal; |
| 142 if (Check(Token::MUL)) { | 154 if (Check(Token::MUL)) { |
| 143 flags |= ParseFunctionFlags::kIsGenerator; | 155 flags |= ParseFunctionFlags::kIsGenerator; |
| 144 if (allow_harmony_restrictive_declarations()) { | 156 if (allow_harmony_restrictive_declarations()) { |
| 145 ReportMessageAt(scanner()->location(), | 157 ReportMessageAt(scanner()->location(), |
| 146 MessageTemplate::kGeneratorInLegacyContext); | 158 MessageTemplate::kGeneratorInLegacyContext); |
| 147 *ok = false; | 159 *ok = false; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 int body_end = scanner()->peek_location().end_pos; | 244 int body_end = scanner()->peek_location().end_pos; |
| 233 DeclarationScope* scope = this->scope()->AsDeclarationScope(); | 245 DeclarationScope* scope = this->scope()->AsDeclarationScope(); |
| 234 DCHECK(scope->is_function_scope()); | 246 DCHECK(scope->is_function_scope()); |
| 235 log_->LogFunction(body_start, body_end, | 247 log_->LogFunction(body_start, body_end, |
| 236 function_state_->materialized_literal_count(), | 248 function_state_->materialized_literal_count(), |
| 237 function_state_->expected_property_count(), language_mode(), | 249 function_state_->expected_property_count(), language_mode(), |
| 238 scope->uses_super_property(), scope->calls_eval()); | 250 scope->uses_super_property(), scope->calls_eval()); |
| 239 return kLazyParsingComplete; | 251 return kLazyParsingComplete; |
| 240 } | 252 } |
| 241 | 253 |
| 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 |
| 242 PreParserExpression PreParser::ExpressionFromIdentifier( | 305 PreParserExpression PreParser::ExpressionFromIdentifier( |
| 243 PreParserIdentifier name, int start_position, int end_position, | 306 PreParserIdentifier name, int start_position, int end_position, |
| 244 InferName infer) { | 307 InferName infer) { |
| 245 if (track_unresolved_variables_) { | 308 if (track_unresolved_variables_) { |
| 246 AstNodeFactory factory(ast_value_factory()); | 309 AstNodeFactory factory(ast_value_factory()); |
| 247 // Setting the Zone is necessary because zone_ might be the temp Zone, and | 310 // Setting the Zone is necessary because zone_ might be the temp Zone, and |
| 248 // AstValueFactory doesn't know about it. | 311 // AstValueFactory doesn't know about it. |
| 249 factory.set_zone(zone()); | 312 factory.set_zone(zone()); |
| 250 DCHECK_NOT_NULL(name.string_); | 313 DCHECK_NOT_NULL(name.string_); |
| 251 scope()->NewUnresolved(&factory, name.string_, start_position, end_position, | 314 scope()->NewUnresolved(&factory, name.string_, start_position, end_position, |
| 252 NORMAL_VARIABLE); | 315 NORMAL_VARIABLE); |
| 253 } | 316 } |
| 254 return PreParserExpression::FromIdentifier(name); | 317 return PreParserExpression::FromIdentifier(name); |
| 255 } | 318 } |
| 256 | 319 |
| 257 #undef CHECK_OK | 320 #undef CHECK_OK |
| 258 #undef CHECK_OK_CUSTOM | 321 #undef CHECK_OK_CUSTOM |
| 259 | 322 |
| 260 | 323 |
| 261 } // namespace internal | 324 } // namespace internal |
| 262 } // namespace v8 | 325 } // namespace v8 |
| OLD | NEW |