| 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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 } | 187 } |
| 188 break; | 188 break; |
| 189 case Token::LET: | 189 case Token::LET: |
| 190 if (IsNextLetKeyword()) { | 190 if (IsNextLetKeyword()) { |
| 191 return ParseVariableStatement(kStatementListItem, ok); | 191 return ParseVariableStatement(kStatementListItem, ok); |
| 192 } | 192 } |
| 193 break; | 193 break; |
| 194 default: | 194 default: |
| 195 break; | 195 break; |
| 196 } | 196 } |
| 197 return ParseStatement(ok); | 197 return ParseStatement(kAllowLabelledFunctionStatement, ok); |
| 198 } | 198 } |
| 199 | 199 |
| 200 | 200 |
| 201 void PreParser::ParseStatementList(int end_token, bool* ok, | 201 void PreParser::ParseStatementList(int end_token, bool* ok, |
| 202 Scanner::BookmarkScope* bookmark) { | 202 Scanner::BookmarkScope* bookmark) { |
| 203 // SourceElements :: | 203 // SourceElements :: |
| 204 // (Statement)* <end_token> | 204 // (Statement)* <end_token> |
| 205 | 205 |
| 206 // Bookkeeping for trial parse if bookmark is set: | 206 // Bookkeeping for trial parse if bookmark is set: |
| 207 DCHECK_IMPLIES(bookmark, bookmark->HasBeenSet()); | 207 DCHECK_IMPLIES(bookmark, bookmark->HasBeenSet()); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 } | 256 } |
| 257 } | 257 } |
| 258 | 258 |
| 259 | 259 |
| 260 #define CHECK_OK ok); \ | 260 #define CHECK_OK ok); \ |
| 261 if (!*ok) return Statement::Default(); \ | 261 if (!*ok) return Statement::Default(); \ |
| 262 ((void)0 | 262 ((void)0 |
| 263 #define DUMMY ) // to make indentation work | 263 #define DUMMY ) // to make indentation work |
| 264 #undef DUMMY | 264 #undef DUMMY |
| 265 | 265 |
| 266 | 266 PreParser::Statement PreParser::ParseStatement( |
| 267 PreParser::Statement PreParser::ParseStatement(bool* ok) { | 267 AllowLabelledFunctionStatement allow_function, bool* ok) { |
| 268 // Statement :: | 268 // Statement :: |
| 269 // EmptyStatement | 269 // EmptyStatement |
| 270 // ... | 270 // ... |
| 271 | 271 |
| 272 if (peek() == Token::SEMICOLON) { | 272 if (peek() == Token::SEMICOLON) { |
| 273 Next(); | 273 Next(); |
| 274 return Statement::Default(); | 274 return Statement::Default(); |
| 275 } | 275 } |
| 276 return ParseSubStatement(ok); | 276 return ParseSubStatement(allow_function, ok); |
| 277 } | 277 } |
| 278 | 278 |
| 279 PreParser::Statement PreParser::ParseScopedStatement(bool legacy, bool* ok) { | 279 PreParser::Statement PreParser::ParseScopedStatement(bool legacy, bool* ok) { |
| 280 if (is_strict(language_mode()) || peek() != Token::FUNCTION || | 280 if (is_strict(language_mode()) || peek() != Token::FUNCTION || |
| 281 (legacy && allow_harmony_restrictive_declarations())) { | 281 (legacy && allow_harmony_restrictive_declarations())) { |
| 282 return ParseSubStatement(ok); | 282 return ParseSubStatement(kDisallowLabelledFunctionStatement, ok); |
| 283 } else { | 283 } else { |
| 284 return ParseFunctionDeclaration(CHECK_OK); | 284 return ParseFunctionDeclaration(CHECK_OK); |
| 285 } | 285 } |
| 286 } | 286 } |
| 287 | 287 |
| 288 PreParser::Statement PreParser::ParseSubStatement(bool* ok) { | 288 PreParser::Statement PreParser::ParseSubStatement( |
| 289 AllowLabelledFunctionStatement allow_function, bool* ok) { |
| 289 // Statement :: | 290 // Statement :: |
| 290 // Block | 291 // Block |
| 291 // VariableStatement | 292 // VariableStatement |
| 292 // EmptyStatement | 293 // EmptyStatement |
| 293 // ExpressionStatement | 294 // ExpressionStatement |
| 294 // IfStatement | 295 // IfStatement |
| 295 // IterationStatement | 296 // IterationStatement |
| 296 // ContinueStatement | 297 // ContinueStatement |
| 297 // BreakStatement | 298 // BreakStatement |
| 298 // ReturnStatement | 299 // ReturnStatement |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 *ok = false; | 366 *ok = false; |
| 366 return Statement::Default(); | 367 return Statement::Default(); |
| 367 | 368 |
| 368 case Token::DEBUGGER: | 369 case Token::DEBUGGER: |
| 369 return ParseDebuggerStatement(ok); | 370 return ParseDebuggerStatement(ok); |
| 370 | 371 |
| 371 case Token::VAR: | 372 case Token::VAR: |
| 372 return ParseVariableStatement(kStatement, ok); | 373 return ParseVariableStatement(kStatement, ok); |
| 373 | 374 |
| 374 default: | 375 default: |
| 375 return ParseExpressionOrLabelledStatement(ok); | 376 return ParseExpressionOrLabelledStatement(allow_function, ok); |
| 376 } | 377 } |
| 377 } | 378 } |
| 378 | 379 |
| 379 | 380 |
| 380 PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) { | 381 PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) { |
| 381 // FunctionDeclaration :: | 382 // FunctionDeclaration :: |
| 382 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' | 383 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' |
| 383 // GeneratorDeclaration :: | 384 // GeneratorDeclaration :: |
| 384 // 'function' '*' Identifier '(' FormalParameterListopt ')' | 385 // 'function' '*' Identifier '(' FormalParameterListopt ')' |
| 385 // '{' FunctionBody '}' | 386 // '{' FunctionBody '}' |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 *bindings_loc = | 549 *bindings_loc = |
| 549 Scanner::Location(bindings_start, scanner()->location().end_pos); | 550 Scanner::Location(bindings_start, scanner()->location().end_pos); |
| 550 } | 551 } |
| 551 | 552 |
| 552 if (num_decl != nullptr) *num_decl = nvars; | 553 if (num_decl != nullptr) *num_decl = nvars; |
| 553 if (is_lexical != nullptr) *is_lexical = lexical; | 554 if (is_lexical != nullptr) *is_lexical = lexical; |
| 554 if (is_binding_pattern != nullptr) *is_binding_pattern = is_pattern; | 555 if (is_binding_pattern != nullptr) *is_binding_pattern = is_pattern; |
| 555 return Statement::Default(); | 556 return Statement::Default(); |
| 556 } | 557 } |
| 557 | 558 |
| 558 | 559 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement( |
| 559 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) { | 560 AllowLabelledFunctionStatement allow_function, bool* ok) { |
| 560 // ExpressionStatement | LabelledStatement :: | 561 // ExpressionStatement | LabelledStatement :: |
| 561 // Expression ';' | 562 // Expression ';' |
| 562 // Identifier ':' Statement | 563 // Identifier ':' Statement |
| 563 | 564 |
| 564 switch (peek()) { | 565 switch (peek()) { |
| 565 case Token::FUNCTION: | 566 case Token::FUNCTION: |
| 566 case Token::LBRACE: | 567 case Token::LBRACE: |
| 567 UNREACHABLE(); // Always handled by the callers. | 568 UNREACHABLE(); // Always handled by the callers. |
| 568 case Token::CLASS: | 569 case Token::CLASS: |
| 569 ReportUnexpectedToken(Next()); | 570 ReportUnexpectedToken(Next()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 584 // an identifier. | 585 // an identifier. |
| 585 if (starts_with_identifier && expr.IsIdentifier() && peek() == Token::COLON) { | 586 if (starts_with_identifier && expr.IsIdentifier() && peek() == Token::COLON) { |
| 586 // Expression is a single identifier, and not, e.g., a parenthesized | 587 // Expression is a single identifier, and not, e.g., a parenthesized |
| 587 // identifier. | 588 // identifier. |
| 588 DCHECK(!expr.AsIdentifier().IsFutureReserved()); | 589 DCHECK(!expr.AsIdentifier().IsFutureReserved()); |
| 589 DCHECK(is_sloppy(language_mode()) || | 590 DCHECK(is_sloppy(language_mode()) || |
| 590 !IsFutureStrictReserved(expr.AsIdentifier())); | 591 !IsFutureStrictReserved(expr.AsIdentifier())); |
| 591 Consume(Token::COLON); | 592 Consume(Token::COLON); |
| 592 // ES#sec-labelled-function-declarations Labelled Function Declarations | 593 // ES#sec-labelled-function-declarations Labelled Function Declarations |
| 593 if (peek() == Token::FUNCTION && is_sloppy(language_mode())) { | 594 if (peek() == Token::FUNCTION && is_sloppy(language_mode())) { |
| 594 return ParseFunctionDeclaration(ok); | 595 if (allow_function == kAllowLabelledFunctionStatement) { |
| 596 return ParseFunctionDeclaration(ok); |
| 597 } else { |
| 598 return ParseScopedStatement(true, ok); |
| 599 } |
| 595 } | 600 } |
| 596 Statement statement = ParseStatement(ok); | 601 Statement statement = |
| 602 ParseStatement(kDisallowLabelledFunctionStatement, ok); |
| 597 return statement.IsJumpStatement() ? Statement::Default() : statement; | 603 return statement.IsJumpStatement() ? Statement::Default() : statement; |
| 598 // Preparsing is disabled for extensions (because the extension details | 604 // Preparsing is disabled for extensions (because the extension details |
| 599 // aren't passed to lazily compiled functions), so we don't | 605 // aren't passed to lazily compiled functions), so we don't |
| 600 // accept "native function" in the preparser. | 606 // accept "native function" in the preparser. |
| 601 } | 607 } |
| 602 // Parsed expression statement. | 608 // Parsed expression statement. |
| 603 // Detect attempts at 'let' declarations in sloppy mode. | 609 // Detect attempts at 'let' declarations in sloppy mode. |
| 604 if (!allow_harmony_sloppy_let() && peek() == Token::IDENTIFIER && | 610 if (!allow_harmony_sloppy_let() && peek() == Token::IDENTIFIER && |
| 605 is_sloppy(language_mode()) && expr.IsIdentifier() && | 611 is_sloppy(language_mode()) && expr.IsIdentifier() && |
| 606 expr.AsIdentifier().IsLet()) { | 612 expr.AsIdentifier().IsLet()) { |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1146 Expect(Token::RBRACE, CHECK_OK); | 1152 Expect(Token::RBRACE, CHECK_OK); |
| 1147 return PreParserExpression::Default(); | 1153 return PreParserExpression::Default(); |
| 1148 } | 1154 } |
| 1149 } | 1155 } |
| 1150 | 1156 |
| 1151 #undef CHECK_OK | 1157 #undef CHECK_OK |
| 1152 | 1158 |
| 1153 | 1159 |
| 1154 } // namespace internal | 1160 } // namespace internal |
| 1155 } // namespace v8 | 1161 } // namespace v8 |
| OLD | NEW |