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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 DCHECK_EQ(Token::RBRACE, scanner()->peek()); | 133 DCHECK_EQ(Token::RBRACE, scanner()->peek()); |
134 if (is_strict(scope_->language_mode())) { | 134 if (is_strict(scope_->language_mode())) { |
135 int end_pos = scanner()->location().end_pos; | 135 int end_pos = scanner()->location().end_pos; |
136 CheckStrictOctalLiteral(start_position, end_pos, &ok); | 136 CheckStrictOctalLiteral(start_position, end_pos, &ok); |
137 if (!ok) return kPreParseSuccess; | 137 if (!ok) return kPreParseSuccess; |
138 } | 138 } |
139 } | 139 } |
140 return kPreParseSuccess; | 140 return kPreParseSuccess; |
141 } | 141 } |
142 | 142 |
143 | |
144 PreParserExpression PreParserTraits::ParseClassLiteral( | 143 PreParserExpression PreParserTraits::ParseClassLiteral( |
145 PreParserIdentifier name, Scanner::Location class_name_location, | 144 Type::ExpressionClassifier* classifier, PreParserIdentifier name, |
146 bool name_is_strict_reserved, int pos, bool* ok) { | 145 Scanner::Location class_name_location, bool name_is_strict_reserved, |
147 return pre_parser_->ParseClassLiteral(name, class_name_location, | 146 int pos, bool* ok) { |
| 147 return pre_parser_->ParseClassLiteral(classifier, name, class_name_location, |
148 name_is_strict_reserved, pos, ok); | 148 name_is_strict_reserved, pos, ok); |
149 } | 149 } |
150 | 150 |
151 | 151 |
152 // Preparsing checks a JavaScript program and emits preparse-data that helps | 152 // Preparsing checks a JavaScript program and emits preparse-data that helps |
153 // a later parsing to be faster. | 153 // a later parsing to be faster. |
154 // See preparser-data.h for the data. | 154 // See preparser-data.h for the data. |
155 | 155 |
156 // The PreParser checks that the syntax follows the grammar for JavaScript, | 156 // The PreParser checks that the syntax follows the grammar for JavaScript, |
157 // and collects some information about the program along the way. | 157 // and collects some information about the program along the way. |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 } | 411 } |
412 | 412 |
413 | 413 |
414 PreParser::Statement PreParser::ParseClassDeclaration(bool* ok) { | 414 PreParser::Statement PreParser::ParseClassDeclaration(bool* ok) { |
415 Expect(Token::CLASS, CHECK_OK); | 415 Expect(Token::CLASS, CHECK_OK); |
416 | 416 |
417 int pos = position(); | 417 int pos = position(); |
418 bool is_strict_reserved = false; | 418 bool is_strict_reserved = false; |
419 Identifier name = | 419 Identifier name = |
420 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); | 420 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); |
421 ParseClassLiteral(name, scanner()->location(), is_strict_reserved, pos, | 421 ParseClassLiteral(nullptr, name, scanner()->location(), is_strict_reserved, |
422 CHECK_OK); | 422 pos, CHECK_OK); |
423 return Statement::Default(); | 423 return Statement::Default(); |
424 } | 424 } |
425 | 425 |
426 | 426 |
427 PreParser::Statement PreParser::ParseBlock(bool* ok) { | 427 PreParser::Statement PreParser::ParseBlock(bool* ok) { |
428 // Block :: | 428 // Block :: |
429 // '{' StatementList '}' | 429 // '{' StatementList '}' |
430 | 430 |
431 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); | 431 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); |
432 Expect(Token::LBRACE, CHECK_OK); | 432 Expect(Token::LBRACE, CHECK_OK); |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1129 | 1129 |
1130 // Position right after terminal '}'. | 1130 // Position right after terminal '}'. |
1131 DCHECK_EQ(Token::RBRACE, scanner()->peek()); | 1131 DCHECK_EQ(Token::RBRACE, scanner()->peek()); |
1132 int body_end = scanner()->peek_location().end_pos; | 1132 int body_end = scanner()->peek_location().end_pos; |
1133 log_->LogFunction(body_start, body_end, | 1133 log_->LogFunction(body_start, body_end, |
1134 function_state_->materialized_literal_count(), | 1134 function_state_->materialized_literal_count(), |
1135 function_state_->expected_property_count(), language_mode(), | 1135 function_state_->expected_property_count(), language_mode(), |
1136 scope_->uses_super_property(), scope_->calls_eval()); | 1136 scope_->uses_super_property(), scope_->calls_eval()); |
1137 } | 1137 } |
1138 | 1138 |
1139 | |
1140 PreParserExpression PreParser::ParseClassLiteral( | 1139 PreParserExpression PreParser::ParseClassLiteral( |
1141 PreParserIdentifier name, Scanner::Location class_name_location, | 1140 ExpressionClassifier* classifier, PreParserIdentifier name, |
1142 bool name_is_strict_reserved, int pos, bool* ok) { | 1141 Scanner::Location class_name_location, bool name_is_strict_reserved, |
| 1142 int pos, bool* ok) { |
1143 // All parts of a ClassDeclaration and ClassExpression are strict code. | 1143 // All parts of a ClassDeclaration and ClassExpression are strict code. |
1144 if (name_is_strict_reserved) { | 1144 if (name_is_strict_reserved) { |
1145 ReportMessageAt(class_name_location, | 1145 ReportMessageAt(class_name_location, |
1146 MessageTemplate::kUnexpectedStrictReserved); | 1146 MessageTemplate::kUnexpectedStrictReserved); |
1147 *ok = false; | 1147 *ok = false; |
1148 return EmptyExpression(); | 1148 return EmptyExpression(); |
1149 } | 1149 } |
1150 if (IsEvalOrArguments(name)) { | 1150 if (IsEvalOrArguments(name)) { |
1151 ReportMessageAt(class_name_location, MessageTemplate::kStrictEvalArguments); | 1151 ReportMessageAt(class_name_location, MessageTemplate::kStrictEvalArguments); |
1152 *ok = false; | 1152 *ok = false; |
1153 return EmptyExpression(); | 1153 return EmptyExpression(); |
1154 } | 1154 } |
1155 | 1155 |
1156 LanguageMode class_language_mode = language_mode(); | 1156 LanguageMode class_language_mode = language_mode(); |
1157 Scope* scope = NewScope(scope_, BLOCK_SCOPE); | 1157 Scope* scope = NewScope(scope_, BLOCK_SCOPE); |
1158 BlockState block_state(&scope_, scope); | 1158 BlockState block_state(&scope_, scope); |
1159 scope_->SetLanguageMode( | 1159 scope_->SetLanguageMode( |
1160 static_cast<LanguageMode>(class_language_mode | STRICT)); | 1160 static_cast<LanguageMode>(class_language_mode | STRICT)); |
1161 // TODO(marja): Make PreParser use scope names too. | 1161 // TODO(marja): Make PreParser use scope names too. |
1162 // scope_->SetScopeName(name); | 1162 // scope_->SetScopeName(name); |
1163 | 1163 |
1164 bool has_extends = Check(Token::EXTENDS); | 1164 bool has_extends = Check(Token::EXTENDS); |
1165 if (has_extends) { | 1165 if (has_extends) { |
1166 ExpressionClassifier classifier(this); | 1166 ExpressionClassifier extends_classifier(this); |
1167 ParseLeftHandSideExpression(&classifier, CHECK_OK); | 1167 ParseLeftHandSideExpression(&extends_classifier, CHECK_OK); |
1168 ValidateExpression(&classifier, CHECK_OK); | 1168 ValidateExpression(&extends_classifier, CHECK_OK); |
| 1169 if (classifier != nullptr) { |
| 1170 classifier->Accumulate(&extends_classifier, |
| 1171 ExpressionClassifier::ExpressionProductions); |
| 1172 } |
1169 } | 1173 } |
1170 | 1174 |
1171 ClassLiteralChecker checker(this); | 1175 ClassLiteralChecker checker(this); |
1172 bool has_seen_constructor = false; | 1176 bool has_seen_constructor = false; |
1173 | 1177 |
1174 Expect(Token::LBRACE, CHECK_OK); | 1178 Expect(Token::LBRACE, CHECK_OK); |
1175 while (peek() != Token::RBRACE) { | 1179 while (peek() != Token::RBRACE) { |
1176 if (Check(Token::SEMICOLON)) continue; | 1180 if (Check(Token::SEMICOLON)) continue; |
1177 const bool in_class = true; | 1181 const bool in_class = true; |
1178 const bool is_static = false; | 1182 const bool is_static = false; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1223 } | 1227 } |
1224 Expect(Token::RBRACE, CHECK_OK); | 1228 Expect(Token::RBRACE, CHECK_OK); |
1225 return PreParserExpression::Default(); | 1229 return PreParserExpression::Default(); |
1226 } | 1230 } |
1227 | 1231 |
1228 #undef CHECK_OK | 1232 #undef CHECK_OK |
1229 | 1233 |
1230 | 1234 |
1231 } // namespace internal | 1235 } // namespace internal |
1232 } // namespace v8 | 1236 } // namespace v8 |
OLD | NEW |