| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 return kPreParseAbort; | 94 return kPreParseAbort; |
| 95 } else if (stack_overflow()) { | 95 } else if (stack_overflow()) { |
| 96 return kPreParseStackOverflow; | 96 return kPreParseStackOverflow; |
| 97 } else if (!ok) { | 97 } else if (!ok) { |
| 98 ReportUnexpectedToken(scanner()->current_token()); | 98 ReportUnexpectedToken(scanner()->current_token()); |
| 99 } else { | 99 } else { |
| 100 DCHECK_EQ(Token::RBRACE, scanner()->peek()); | 100 DCHECK_EQ(Token::RBRACE, scanner()->peek()); |
| 101 if (is_strict(scope()->language_mode())) { | 101 if (is_strict(scope()->language_mode())) { |
| 102 int end_pos = scanner()->location().end_pos; | 102 int end_pos = scanner()->location().end_pos; |
| 103 CheckStrictOctalLiteral(start_position, end_pos, &ok); | 103 CheckStrictOctalLiteral(start_position, end_pos, &ok); |
| 104 CheckDecimalLiteralWithLeadingZero(use_counts, start_position, end_pos); | 104 CheckDecimalLiteralWithLeadingZero(start_position, end_pos); |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 return kPreParseSuccess; | 107 return kPreParseSuccess; |
| 108 } | 108 } |
| 109 | 109 |
| 110 | 110 |
| 111 // Preparsing checks a JavaScript program and emits preparse-data that helps | 111 // Preparsing checks a JavaScript program and emits preparse-data that helps |
| 112 // a later parsing to be faster. | 112 // a later parsing to be faster. |
| 113 // See preparser-data.h for the data. | 113 // See preparser-data.h for the data. |
| 114 | 114 |
| 115 // The PreParser checks that the syntax follows the grammar for JavaScript, | 115 // The PreParser checks that the syntax follows the grammar for JavaScript, |
| 116 // and collects some information about the program along the way. | 116 // and collects some information about the program along the way. |
| 117 // The grammar check is only performed in order to understand the program | 117 // The grammar check is only performed in order to understand the program |
| 118 // sufficiently to deduce some information about it, that can be used | 118 // sufficiently to deduce some information about it, that can be used |
| 119 // to speed up later parsing. Finding errors is not the goal of pre-parsing, | 119 // to speed up later parsing. Finding errors is not the goal of pre-parsing, |
| 120 // rather it is to speed up properly written and correct programs. | 120 // rather it is to speed up properly written and correct programs. |
| 121 // That means that contextual checks (like a label being declared where | 121 // That means that contextual checks (like a label being declared where |
| 122 // it is used) are generally omitted. | 122 // it is used) are generally omitted. |
| 123 | 123 |
| 124 | |
| 125 PreParser::Statement PreParser::ParseScopedStatement(bool legacy, bool* ok) { | |
| 126 if (is_strict(language_mode()) || peek() != Token::FUNCTION || | |
| 127 (legacy && allow_harmony_restrictive_declarations())) { | |
| 128 return ParseStatement(nullptr, kDisallowLabelledFunctionStatement, ok); | |
| 129 } else { | |
| 130 BlockState block_state(&scope_state_); | |
| 131 return ParseFunctionDeclaration(ok); | |
| 132 } | |
| 133 } | |
| 134 | |
| 135 PreParser::Statement PreParser::ParseHoistableDeclaration( | 124 PreParser::Statement PreParser::ParseHoistableDeclaration( |
| 136 int pos, ParseFunctionFlags flags, ZoneList<const AstRawString*>* names, | 125 int pos, ParseFunctionFlags flags, ZoneList<const AstRawString*>* names, |
| 137 bool default_export, bool* ok) { | 126 bool default_export, bool* ok) { |
| 138 const bool is_generator = flags & ParseFunctionFlags::kIsGenerator; | 127 const bool is_generator = flags & ParseFunctionFlags::kIsGenerator; |
| 139 const bool is_async = flags & ParseFunctionFlags::kIsAsync; | 128 const bool is_async = flags & ParseFunctionFlags::kIsAsync; |
| 140 DCHECK(!is_generator || !is_async); | 129 DCHECK(!is_generator || !is_async); |
| 141 | 130 |
| 142 bool is_strict_reserved = false; | 131 bool is_strict_reserved = false; |
| 143 Identifier name = ParseIdentifierOrStrictReservedWord( | 132 Identifier name = ParseIdentifierOrStrictReservedWord( |
| 144 &is_strict_reserved, CHECK_OK); | 133 &is_strict_reserved, CHECK_OK); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 int pos = position(); | 177 int pos = position(); |
| 189 bool is_strict_reserved = false; | 178 bool is_strict_reserved = false; |
| 190 Identifier name = | 179 Identifier name = |
| 191 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); | 180 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); |
| 192 ExpressionClassifier no_classifier(this); | 181 ExpressionClassifier no_classifier(this); |
| 193 ParseClassLiteral(name, scanner()->location(), is_strict_reserved, pos, | 182 ParseClassLiteral(name, scanner()->location(), is_strict_reserved, pos, |
| 194 CHECK_OK); | 183 CHECK_OK); |
| 195 return Statement::Default(); | 184 return Statement::Default(); |
| 196 } | 185 } |
| 197 | 186 |
| 198 PreParser::Statement PreParser::ParseVariableStatement( | |
| 199 VariableDeclarationContext var_context, | |
| 200 ZoneList<const AstRawString*>* names, bool* ok) { | |
| 201 // VariableStatement :: | |
| 202 // VariableDeclarations ';' | |
| 203 | |
| 204 Statement result = | |
| 205 ParseVariableDeclarations(var_context, nullptr, names, CHECK_OK); | |
| 206 ExpectSemicolon(CHECK_OK); | |
| 207 return result; | |
| 208 } | |
| 209 | |
| 210 PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) { | 187 PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) { |
| 211 Consume(Token::FUNCTION); | 188 Consume(Token::FUNCTION); |
| 212 int pos = position(); | 189 int pos = position(); |
| 213 ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal; | 190 ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal; |
| 214 if (Check(Token::MUL)) { | 191 if (Check(Token::MUL)) { |
| 215 flags |= ParseFunctionFlags::kIsGenerator; | 192 flags |= ParseFunctionFlags::kIsGenerator; |
| 216 if (allow_harmony_restrictive_declarations()) { | 193 if (allow_harmony_restrictive_declarations()) { |
| 217 ReportMessageAt(scanner()->location(), | 194 ReportMessageAt(scanner()->location(), |
| 218 MessageTemplate::kGeneratorInLegacyContext); | 195 MessageTemplate::kGeneratorInLegacyContext); |
| 219 *ok = false; | 196 *ok = false; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 DCHECK(!expr.AsIdentifier().IsEnum()); | 234 DCHECK(!expr.AsIdentifier().IsEnum()); |
| 258 DCHECK(!parsing_module_ || !expr.AsIdentifier().IsAwait()); | 235 DCHECK(!parsing_module_ || !expr.AsIdentifier().IsAwait()); |
| 259 DCHECK(is_sloppy(language_mode()) || | 236 DCHECK(is_sloppy(language_mode()) || |
| 260 !IsFutureStrictReserved(expr.AsIdentifier())); | 237 !IsFutureStrictReserved(expr.AsIdentifier())); |
| 261 Consume(Token::COLON); | 238 Consume(Token::COLON); |
| 262 // ES#sec-labelled-function-declarations Labelled Function Declarations | 239 // ES#sec-labelled-function-declarations Labelled Function Declarations |
| 263 if (peek() == Token::FUNCTION && is_sloppy(language_mode())) { | 240 if (peek() == Token::FUNCTION && is_sloppy(language_mode())) { |
| 264 if (allow_function == kAllowLabelledFunctionStatement) { | 241 if (allow_function == kAllowLabelledFunctionStatement) { |
| 265 return ParseFunctionDeclaration(ok); | 242 return ParseFunctionDeclaration(ok); |
| 266 } else { | 243 } else { |
| 267 return ParseScopedStatement(true, ok); | 244 return ParseScopedStatement(names, true, ok); |
| 268 } | 245 } |
| 269 } | 246 } |
| 270 Statement statement = | 247 Statement statement = |
| 271 ParseStatement(nullptr, kDisallowLabelledFunctionStatement, ok); | 248 ParseStatement(nullptr, kDisallowLabelledFunctionStatement, ok); |
| 272 return statement.IsJumpStatement() ? Statement::Default() : statement; | 249 return statement.IsJumpStatement() ? Statement::Default() : statement; |
| 273 // Preparsing is disabled for extensions (because the extension details | 250 // Preparsing is disabled for extensions (because the extension details |
| 274 // aren't passed to lazily compiled functions), so we don't | 251 // aren't passed to lazily compiled functions), so we don't |
| 275 // accept "native function" in the preparser. | 252 // accept "native function" in the preparser. |
| 276 } | 253 } |
| 277 // Parsed expression statement. | 254 // Parsed expression statement. |
| 278 ExpectSemicolon(CHECK_OK); | 255 ExpectSemicolon(CHECK_OK); |
| 279 return Statement::ExpressionStatement(expr); | 256 return Statement::ExpressionStatement(expr); |
| 280 } | 257 } |
| 281 | 258 |
| 282 PreParser::Statement PreParser::ParseIfStatement( | 259 PreParser::Statement PreParser::ParseIfStatement( |
| 283 ZoneList<const AstRawString*>* labels, bool* ok) { | 260 ZoneList<const AstRawString*>* labels, bool* ok) { |
| 284 // IfStatement :: | 261 // IfStatement :: |
| 285 // 'if' '(' Expression ')' Statement ('else' Statement)? | 262 // 'if' '(' Expression ')' Statement ('else' Statement)? |
| 286 | 263 |
| 287 Expect(Token::IF, CHECK_OK); | 264 Expect(Token::IF, CHECK_OK); |
| 288 Expect(Token::LPAREN, CHECK_OK); | 265 Expect(Token::LPAREN, CHECK_OK); |
| 289 ParseExpression(true, CHECK_OK); | 266 ParseExpression(true, CHECK_OK); |
| 290 Expect(Token::RPAREN, CHECK_OK); | 267 Expect(Token::RPAREN, CHECK_OK); |
| 291 Statement stat = ParseScopedStatement(false, CHECK_OK); | 268 Statement stat = ParseScopedStatement(labels, false, CHECK_OK); |
| 292 if (peek() == Token::ELSE) { | 269 if (peek() == Token::ELSE) { |
| 293 Next(); | 270 Next(); |
| 294 Statement else_stat = ParseScopedStatement(false, CHECK_OK); | 271 Statement else_stat = ParseScopedStatement(labels, false, CHECK_OK); |
| 295 stat = (stat.IsJumpStatement() && else_stat.IsJumpStatement()) ? | 272 stat = (stat.IsJumpStatement() && else_stat.IsJumpStatement()) ? |
| 296 Statement::Jump() : Statement::Default(); | 273 Statement::Jump() : Statement::Default(); |
| 297 } else { | 274 } else { |
| 298 stat = Statement::Default(); | 275 stat = Statement::Default(); |
| 299 } | 276 } |
| 300 return stat; | 277 return stat; |
| 301 } | 278 } |
| 302 | 279 |
| 303 | 280 |
| 304 PreParser::Statement PreParser::ParseContinueStatement(bool* ok) { | 281 PreParser::Statement PreParser::ParseContinueStatement(bool* ok) { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 ReportMessageAt(scanner()->location(), MessageTemplate::kStrictWith); | 358 ReportMessageAt(scanner()->location(), MessageTemplate::kStrictWith); |
| 382 *ok = false; | 359 *ok = false; |
| 383 return Statement::Default(); | 360 return Statement::Default(); |
| 384 } | 361 } |
| 385 Expect(Token::LPAREN, CHECK_OK); | 362 Expect(Token::LPAREN, CHECK_OK); |
| 386 ParseExpression(true, CHECK_OK); | 363 ParseExpression(true, CHECK_OK); |
| 387 Expect(Token::RPAREN, CHECK_OK); | 364 Expect(Token::RPAREN, CHECK_OK); |
| 388 | 365 |
| 389 Scope* with_scope = NewScope(WITH_SCOPE); | 366 Scope* with_scope = NewScope(WITH_SCOPE); |
| 390 BlockState block_state(&scope_state_, with_scope); | 367 BlockState block_state(&scope_state_, with_scope); |
| 391 ParseScopedStatement(true, CHECK_OK); | 368 ParseScopedStatement(labels, true, CHECK_OK); |
| 392 return Statement::Default(); | 369 return Statement::Default(); |
| 393 } | 370 } |
| 394 | 371 |
| 395 PreParser::Statement PreParser::ParseSwitchStatement( | 372 PreParser::Statement PreParser::ParseSwitchStatement( |
| 396 ZoneList<const AstRawString*>* labels, bool* ok) { | 373 ZoneList<const AstRawString*>* labels, bool* ok) { |
| 397 // SwitchStatement :: | 374 // SwitchStatement :: |
| 398 // 'switch' '(' Expression ')' '{' CaseClause* '}' | 375 // 'switch' '(' Expression ')' '{' CaseClause* '}' |
| 399 | 376 |
| 400 Expect(Token::SWITCH, CHECK_OK); | 377 Expect(Token::SWITCH, CHECK_OK); |
| 401 Expect(Token::LPAREN, CHECK_OK); | 378 Expect(Token::LPAREN, CHECK_OK); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 427 Expect(Token::RBRACE, ok); | 404 Expect(Token::RBRACE, ok); |
| 428 return Statement::Default(); | 405 return Statement::Default(); |
| 429 } | 406 } |
| 430 | 407 |
| 431 PreParser::Statement PreParser::ParseDoWhileStatement( | 408 PreParser::Statement PreParser::ParseDoWhileStatement( |
| 432 ZoneList<const AstRawString*>* labels, bool* ok) { | 409 ZoneList<const AstRawString*>* labels, bool* ok) { |
| 433 // DoStatement :: | 410 // DoStatement :: |
| 434 // 'do' Statement 'while' '(' Expression ')' ';' | 411 // 'do' Statement 'while' '(' Expression ')' ';' |
| 435 | 412 |
| 436 Expect(Token::DO, CHECK_OK); | 413 Expect(Token::DO, CHECK_OK); |
| 437 ParseScopedStatement(true, CHECK_OK); | 414 ParseScopedStatement(nullptr, true, CHECK_OK); |
| 438 Expect(Token::WHILE, CHECK_OK); | 415 Expect(Token::WHILE, CHECK_OK); |
| 439 Expect(Token::LPAREN, CHECK_OK); | 416 Expect(Token::LPAREN, CHECK_OK); |
| 440 ParseExpression(true, CHECK_OK); | 417 ParseExpression(true, CHECK_OK); |
| 441 Expect(Token::RPAREN, ok); | 418 Expect(Token::RPAREN, ok); |
| 442 if (peek() == Token::SEMICOLON) Consume(Token::SEMICOLON); | 419 if (peek() == Token::SEMICOLON) Consume(Token::SEMICOLON); |
| 443 return Statement::Default(); | 420 return Statement::Default(); |
| 444 } | 421 } |
| 445 | 422 |
| 446 PreParser::Statement PreParser::ParseWhileStatement( | 423 PreParser::Statement PreParser::ParseWhileStatement( |
| 447 ZoneList<const AstRawString*>* labels, bool* ok) { | 424 ZoneList<const AstRawString*>* labels, bool* ok) { |
| 448 // WhileStatement :: | 425 // WhileStatement :: |
| 449 // 'while' '(' Expression ')' Statement | 426 // 'while' '(' Expression ')' Statement |
| 450 | 427 |
| 451 Expect(Token::WHILE, CHECK_OK); | 428 Expect(Token::WHILE, CHECK_OK); |
| 452 Expect(Token::LPAREN, CHECK_OK); | 429 Expect(Token::LPAREN, CHECK_OK); |
| 453 ParseExpression(true, CHECK_OK); | 430 ParseExpression(true, CHECK_OK); |
| 454 Expect(Token::RPAREN, CHECK_OK); | 431 Expect(Token::RPAREN, CHECK_OK); |
| 455 ParseScopedStatement(true, ok); | 432 ParseScopedStatement(nullptr, true, ok); |
| 456 return Statement::Default(); | 433 return Statement::Default(); |
| 457 } | 434 } |
| 458 | 435 |
| 459 PreParser::Statement PreParser::ParseForStatement( | 436 PreParser::Statement PreParser::ParseForStatement( |
| 460 ZoneList<const AstRawString*>* labels, bool* ok) { | 437 ZoneList<const AstRawString*>* labels, bool* ok) { |
| 461 // ForStatement :: | 438 // ForStatement :: |
| 462 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement | 439 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement |
| 463 | 440 |
| 464 // Create an in-between scope for let-bound iteration variables. | 441 // Create an in-between scope for let-bound iteration variables. |
| 465 bool has_lexical = false; | 442 bool has_lexical = false; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 ParseAssignmentExpression(true, CHECK_OK); | 488 ParseAssignmentExpression(true, CHECK_OK); |
| 512 RewriteNonPattern(CHECK_OK); | 489 RewriteNonPattern(CHECK_OK); |
| 513 } else { | 490 } else { |
| 514 ParseExpression(true, CHECK_OK); | 491 ParseExpression(true, CHECK_OK); |
| 515 } | 492 } |
| 516 | 493 |
| 517 Expect(Token::RPAREN, CHECK_OK); | 494 Expect(Token::RPAREN, CHECK_OK); |
| 518 { | 495 { |
| 519 ReturnExprScope no_tail_calls(function_state_, | 496 ReturnExprScope no_tail_calls(function_state_, |
| 520 ReturnExprContext::kInsideForInOfBody); | 497 ReturnExprContext::kInsideForInOfBody); |
| 521 ParseScopedStatement(true, CHECK_OK); | 498 ParseScopedStatement(nullptr, true, CHECK_OK); |
| 522 } | 499 } |
| 523 return Statement::Default(); | 500 return Statement::Default(); |
| 524 } | 501 } |
| 525 } else { | 502 } else { |
| 526 int lhs_beg_pos = peek_position(); | 503 int lhs_beg_pos = peek_position(); |
| 527 ExpressionClassifier classifier(this); | 504 ExpressionClassifier classifier(this); |
| 528 Expression lhs = ParseExpressionCoverGrammar(false, CHECK_OK); | 505 Expression lhs = ParseExpressionCoverGrammar(false, CHECK_OK); |
| 529 int lhs_end_pos = scanner()->location().end_pos; | 506 int lhs_end_pos = scanner()->location().end_pos; |
| 530 bool is_for_each = CheckInOrOf(&mode); | 507 bool is_for_each = CheckInOrOf(&mode); |
| 531 bool is_destructuring = is_for_each && | 508 bool is_destructuring = is_for_each && |
| (...skipping 16 matching lines...) Expand all Loading... |
| 548 ExpressionClassifier classifier(this); | 525 ExpressionClassifier classifier(this); |
| 549 ParseAssignmentExpression(true, CHECK_OK); | 526 ParseAssignmentExpression(true, CHECK_OK); |
| 550 RewriteNonPattern(CHECK_OK); | 527 RewriteNonPattern(CHECK_OK); |
| 551 } else { | 528 } else { |
| 552 ParseExpression(true, CHECK_OK); | 529 ParseExpression(true, CHECK_OK); |
| 553 } | 530 } |
| 554 | 531 |
| 555 Expect(Token::RPAREN, CHECK_OK); | 532 Expect(Token::RPAREN, CHECK_OK); |
| 556 { | 533 { |
| 557 BlockState block_state(&scope_state_); | 534 BlockState block_state(&scope_state_); |
| 558 ParseScopedStatement(true, CHECK_OK); | 535 ParseScopedStatement(nullptr, true, CHECK_OK); |
| 559 } | 536 } |
| 560 return Statement::Default(); | 537 return Statement::Default(); |
| 561 } | 538 } |
| 562 } | 539 } |
| 563 } | 540 } |
| 564 | 541 |
| 565 // Parsed initializer at this point. | 542 // Parsed initializer at this point. |
| 566 Expect(Token::SEMICOLON, CHECK_OK); | 543 Expect(Token::SEMICOLON, CHECK_OK); |
| 567 | 544 |
| 568 // If there are let bindings, then condition and the next statement of the | 545 // If there are let bindings, then condition and the next statement of the |
| 569 // for loop must be parsed in a new scope. | 546 // for loop must be parsed in a new scope. |
| 570 Scope* inner_scope = scope(); | 547 Scope* inner_scope = scope(); |
| 571 // TODO(verwaest): Allocate this through a ScopeState as well. | 548 // TODO(verwaest): Allocate this through a ScopeState as well. |
| 572 if (has_lexical) inner_scope = NewScopeWithParent(inner_scope, BLOCK_SCOPE); | 549 if (has_lexical) inner_scope = NewScopeWithParent(inner_scope, BLOCK_SCOPE); |
| 573 | 550 |
| 574 { | 551 { |
| 575 BlockState block_state(&scope_state_, inner_scope); | 552 BlockState block_state(&scope_state_, inner_scope); |
| 576 | 553 |
| 577 if (peek() != Token::SEMICOLON) { | 554 if (peek() != Token::SEMICOLON) { |
| 578 ParseExpression(true, CHECK_OK); | 555 ParseExpression(true, CHECK_OK); |
| 579 } | 556 } |
| 580 Expect(Token::SEMICOLON, CHECK_OK); | 557 Expect(Token::SEMICOLON, CHECK_OK); |
| 581 | 558 |
| 582 if (peek() != Token::RPAREN) { | 559 if (peek() != Token::RPAREN) { |
| 583 ParseExpression(true, CHECK_OK); | 560 ParseExpression(true, CHECK_OK); |
| 584 } | 561 } |
| 585 Expect(Token::RPAREN, CHECK_OK); | 562 Expect(Token::RPAREN, CHECK_OK); |
| 586 | 563 |
| 587 ParseScopedStatement(true, ok); | 564 ParseScopedStatement(nullptr, true, ok); |
| 588 } | 565 } |
| 589 return Statement::Default(); | 566 return Statement::Default(); |
| 590 } | 567 } |
| 591 | 568 |
| 592 | 569 |
| 593 PreParser::Statement PreParser::ParseThrowStatement(bool* ok) { | 570 PreParser::Statement PreParser::ParseThrowStatement(bool* ok) { |
| 594 // ThrowStatement :: | 571 // ThrowStatement :: |
| 595 // 'throw' [no line terminator] Expression ';' | 572 // 'throw' [no line terminator] Expression ';' |
| 596 | 573 |
| 597 Expect(Token::THROW, CHECK_OK); | 574 Expect(Token::THROW, CHECK_OK); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 ReportMessageAt(tail_call_expressions_in_catch_block.location(), | 642 ReportMessageAt(tail_call_expressions_in_catch_block.location(), |
| 666 MessageTemplate::kUnexpectedTailCallInCatchBlock); | 643 MessageTemplate::kUnexpectedTailCallInCatchBlock); |
| 667 *ok = false; | 644 *ok = false; |
| 668 return Statement::Default(); | 645 return Statement::Default(); |
| 669 } | 646 } |
| 670 } | 647 } |
| 671 return Statement::Default(); | 648 return Statement::Default(); |
| 672 } | 649 } |
| 673 | 650 |
| 674 | 651 |
| 675 PreParser::Statement PreParser::ParseDebuggerStatement(bool* ok) { | |
| 676 // In ECMA-262 'debugger' is defined as a reserved keyword. In some browser | |
| 677 // contexts this is used as a statement which invokes the debugger as if a | |
| 678 // break point is present. | |
| 679 // DebuggerStatement :: | |
| 680 // 'debugger' ';' | |
| 681 | |
| 682 Expect(Token::DEBUGGER, CHECK_OK); | |
| 683 ExpectSemicolon(ok); | |
| 684 return Statement::Default(); | |
| 685 } | |
| 686 | |
| 687 | |
| 688 // Redefinition of CHECK_OK for parsing expressions. | 652 // Redefinition of CHECK_OK for parsing expressions. |
| 689 #undef CHECK_OK | 653 #undef CHECK_OK |
| 690 #define CHECK_OK CHECK_OK_VALUE(Expression::Default()) | 654 #define CHECK_OK CHECK_OK_VALUE(Expression::Default()) |
| 691 | 655 |
| 692 PreParser::Expression PreParser::ParseFunctionLiteral( | 656 PreParser::Expression PreParser::ParseFunctionLiteral( |
| 693 Identifier function_name, Scanner::Location function_name_location, | 657 Identifier function_name, Scanner::Location function_name_location, |
| 694 FunctionNameValidity function_name_validity, FunctionKind kind, | 658 FunctionNameValidity function_name_validity, FunctionKind kind, |
| 695 int function_token_pos, FunctionLiteral::FunctionType function_type, | 659 int function_token_pos, FunctionLiteral::FunctionType function_type, |
| 696 LanguageMode language_mode, bool* ok) { | 660 LanguageMode language_mode, bool* ok) { |
| 697 // Function :: | 661 // Function :: |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 // function, since the function can declare itself strict. | 702 // function, since the function can declare itself strict. |
| 739 CheckFunctionName(language_mode, function_name, function_name_validity, | 703 CheckFunctionName(language_mode, function_name, function_name_validity, |
| 740 function_name_location, CHECK_OK); | 704 function_name_location, CHECK_OK); |
| 741 const bool allow_duplicate_parameters = | 705 const bool allow_duplicate_parameters = |
| 742 is_sloppy(language_mode) && formals.is_simple && !IsConciseMethod(kind); | 706 is_sloppy(language_mode) && formals.is_simple && !IsConciseMethod(kind); |
| 743 ValidateFormalParameters(language_mode, allow_duplicate_parameters, CHECK_OK); | 707 ValidateFormalParameters(language_mode, allow_duplicate_parameters, CHECK_OK); |
| 744 | 708 |
| 745 if (is_strict(language_mode)) { | 709 if (is_strict(language_mode)) { |
| 746 int end_position = scanner()->location().end_pos; | 710 int end_position = scanner()->location().end_pos; |
| 747 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); | 711 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); |
| 748 CheckDecimalLiteralWithLeadingZero(use_counts_, start_position, | 712 CheckDecimalLiteralWithLeadingZero(start_position, end_position); |
| 749 end_position); | |
| 750 } | 713 } |
| 751 | 714 |
| 752 return Expression::Default(); | 715 return Expression::Default(); |
| 753 } | 716 } |
| 754 | 717 |
| 755 PreParser::Expression PreParser::ParseAsyncFunctionExpression(bool* ok) { | 718 PreParser::Expression PreParser::ParseAsyncFunctionExpression(bool* ok) { |
| 756 // AsyncFunctionDeclaration :: | 719 // AsyncFunctionDeclaration :: |
| 757 // async [no LineTerminator here] function ( FormalParameters[Await] ) | 720 // async [no LineTerminator here] function ( FormalParameters[Await] ) |
| 758 // { AsyncFunctionBody } | 721 // { AsyncFunctionBody } |
| 759 // | 722 // |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 &has_seen_constructor, CHECK_OK); | 807 &has_seen_constructor, CHECK_OK); |
| 845 ValidateExpression(CHECK_OK); | 808 ValidateExpression(CHECK_OK); |
| 846 impl()->AccumulateFormalParameterContainmentErrors(); | 809 impl()->AccumulateFormalParameterContainmentErrors(); |
| 847 } | 810 } |
| 848 | 811 |
| 849 Expect(Token::RBRACE, CHECK_OK); | 812 Expect(Token::RBRACE, CHECK_OK); |
| 850 | 813 |
| 851 return Expression::Default(); | 814 return Expression::Default(); |
| 852 } | 815 } |
| 853 | 816 |
| 854 | |
| 855 PreParser::Expression PreParser::ParseV8Intrinsic(bool* ok) { | |
| 856 // CallRuntime :: | |
| 857 // '%' Identifier Arguments | |
| 858 Expect(Token::MOD, CHECK_OK); | |
| 859 if (!allow_natives()) { | |
| 860 *ok = false; | |
| 861 return Expression::Default(); | |
| 862 } | |
| 863 // Allow "eval" or "arguments" for backward compatibility. | |
| 864 ParseIdentifier(kAllowRestrictedIdentifiers, CHECK_OK); | |
| 865 Scanner::Location spread_pos; | |
| 866 ExpressionClassifier classifier(this); | |
| 867 ParseArguments(&spread_pos, ok); | |
| 868 ValidateExpression(CHECK_OK); | |
| 869 | |
| 870 DCHECK(!spread_pos.IsValid()); | |
| 871 | |
| 872 return Expression::Default(); | |
| 873 } | |
| 874 | |
| 875 | |
| 876 PreParserExpression PreParser::ParseDoExpression(bool* ok) { | 817 PreParserExpression PreParser::ParseDoExpression(bool* ok) { |
| 877 // AssignmentExpression :: | 818 // AssignmentExpression :: |
| 878 // do '{' StatementList '}' | 819 // do '{' StatementList '}' |
| 879 Expect(Token::DO, CHECK_OK); | 820 Expect(Token::DO, CHECK_OK); |
| 880 Expect(Token::LBRACE, CHECK_OK); | 821 Expect(Token::LBRACE, CHECK_OK); |
| 881 while (peek() != Token::RBRACE) { | 822 while (peek() != Token::RBRACE) { |
| 882 ParseStatementListItem(CHECK_OK); | 823 ParseStatementListItem(CHECK_OK); |
| 883 } | 824 } |
| 884 Expect(Token::RBRACE, CHECK_OK); | 825 Expect(Token::RBRACE, CHECK_OK); |
| 885 return PreParserExpression::Default(); | 826 return PreParserExpression::Default(); |
| 886 } | 827 } |
| 887 | 828 |
| 888 void PreParser::ParseAsyncArrowSingleExpressionBody(PreParserStatementList body, | 829 void PreParser::ParseAsyncArrowSingleExpressionBody(PreParserStatementList body, |
| 889 bool accept_IN, int pos, | 830 bool accept_IN, int pos, |
| 890 bool* ok) { | 831 bool* ok) { |
| 891 scope()->ForceContextAllocation(); | 832 scope()->ForceContextAllocation(); |
| 892 | 833 |
| 893 PreParserExpression return_value = | 834 PreParserExpression return_value = |
| 894 ParseAssignmentExpression(accept_IN, CHECK_OK_VOID); | 835 ParseAssignmentExpression(accept_IN, CHECK_OK_VOID); |
| 895 | 836 |
| 896 body->Add(PreParserStatement::ExpressionStatement(return_value), zone()); | 837 body->Add(PreParserStatement::ExpressionStatement(return_value), zone()); |
| 897 } | 838 } |
| 898 | 839 |
| 899 #undef CHECK_OK | 840 #undef CHECK_OK |
| 900 #undef CHECK_OK_CUSTOM | 841 #undef CHECK_OK_CUSTOM |
| 901 | 842 |
| 902 | 843 |
| 903 } // namespace internal | 844 } // namespace internal |
| 904 } // namespace v8 | 845 } // namespace v8 |
| OLD | NEW |