OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 "src/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/ast/ast-expression-rewriter.h" | 10 #include "src/ast/ast-expression-rewriter.h" |
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 Parser::Parser(ParseInfo* info) | 589 Parser::Parser(ParseInfo* info) |
590 : ParserBase<Parser>(info->zone(), &scanner_, info->stack_limit(), | 590 : ParserBase<Parser>(info->zone(), &scanner_, info->stack_limit(), |
591 info->extension(), info->ast_value_factory(), NULL), | 591 info->extension(), info->ast_value_factory(), NULL), |
592 scanner_(info->unicode_cache()), | 592 scanner_(info->unicode_cache()), |
593 reusable_preparser_(NULL), | 593 reusable_preparser_(NULL), |
594 original_scope_(NULL), | 594 original_scope_(NULL), |
595 target_stack_(NULL), | 595 target_stack_(NULL), |
596 compile_options_(info->compile_options()), | 596 compile_options_(info->compile_options()), |
597 cached_parse_data_(nullptr), | 597 cached_parse_data_(nullptr), |
598 total_preparse_skipped_(0), | 598 total_preparse_skipped_(0), |
| 599 parameters_end_pos_(info->parameters_end_pos()), |
599 parsing_on_main_thread_(true) { | 600 parsing_on_main_thread_(true) { |
600 // Even though we were passed ParseInfo, we should not store it in | 601 // Even though we were passed ParseInfo, we should not store it in |
601 // Parser - this makes sure that Isolate is not accidentally accessed via | 602 // Parser - this makes sure that Isolate is not accidentally accessed via |
602 // ParseInfo during background parsing. | 603 // ParseInfo during background parsing. |
603 DCHECK(!info->script().is_null() || info->source_stream() != nullptr || | 604 DCHECK(!info->script().is_null() || info->source_stream() != nullptr || |
604 info->character_stream() != nullptr); | 605 info->character_stream() != nullptr); |
605 // Determine if functions can be lazily compiled. This is necessary to | 606 // Determine if functions can be lazily compiled. This is necessary to |
606 // allow some of our builtin JS files to be lazily compiled. These | 607 // allow some of our builtin JS files to be lazily compiled. These |
607 // builtins cannot be handled lazily by the parser, since we have to know | 608 // builtins cannot be handled lazily by the parser, since we have to know |
608 // if a function uses the special natives syntax, which is something the | 609 // if a function uses the special natives syntax, which is something the |
(...skipping 1914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2523 // Getter :: | 2524 // Getter :: |
2524 // '(' ')' '{' FunctionBody '}' | 2525 // '(' ')' '{' FunctionBody '}' |
2525 // | 2526 // |
2526 // Setter :: | 2527 // Setter :: |
2527 // '(' PropertySetParameterList ')' '{' FunctionBody '}' | 2528 // '(' PropertySetParameterList ')' '{' FunctionBody '}' |
2528 | 2529 |
2529 int pos = function_token_pos == kNoSourcePosition ? peek_position() | 2530 int pos = function_token_pos == kNoSourcePosition ? peek_position() |
2530 : function_token_pos; | 2531 : function_token_pos; |
2531 | 2532 |
2532 bool is_generator = IsGeneratorFunction(kind); | 2533 bool is_generator = IsGeneratorFunction(kind); |
| 2534 int expected_parameters_end_pos = parameters_end_pos_; |
| 2535 if (expected_parameters_end_pos != kNoSourcePosition) { |
| 2536 // This is the first function literal encountered in an only-single-function |
| 2537 // eval. |
| 2538 parameters_end_pos_ = kNoSourcePosition; |
| 2539 // The function name should have been ignored, giving us null here. |
| 2540 DCHECK_NULL(function_name); |
| 2541 } |
2533 | 2542 |
2534 // Anonymous functions were passed either the empty symbol or a null | 2543 // Anonymous functions were passed either the empty symbol or a null |
2535 // handle as the function name. Remember if we were passed a non-empty | 2544 // handle as the function name. Remember if we were passed a non-empty |
2536 // handle to decide whether to invoke function name inference. | 2545 // handle to decide whether to invoke function name inference. |
2537 bool should_infer_name = function_name == NULL; | 2546 bool should_infer_name = function_name == NULL; |
2538 | 2547 |
2539 // We want a non-null handle as the function name. | 2548 // We want a non-null handle as the function name. |
2540 if (should_infer_name) { | 2549 if (should_infer_name) { |
2541 function_name = ast_value_factory()->empty_string(); | 2550 function_name = ast_value_factory()->empty_string(); |
2542 } | 2551 } |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2635 | 2644 |
2636 ExpressionClassifier formals_classifier(this, &duplicate_finder); | 2645 ExpressionClassifier formals_classifier(this, &duplicate_finder); |
2637 | 2646 |
2638 if (is_generator) PrepareGeneratorVariables(&function_state); | 2647 if (is_generator) PrepareGeneratorVariables(&function_state); |
2639 | 2648 |
2640 Expect(Token::LPAREN, CHECK_OK); | 2649 Expect(Token::LPAREN, CHECK_OK); |
2641 int start_position = scanner()->location().beg_pos; | 2650 int start_position = scanner()->location().beg_pos; |
2642 this->scope()->set_start_position(start_position); | 2651 this->scope()->set_start_position(start_position); |
2643 ParserFormalParameters formals(scope); | 2652 ParserFormalParameters formals(scope); |
2644 ParseFormalParameterList(&formals, CHECK_OK); | 2653 ParseFormalParameterList(&formals, CHECK_OK); |
| 2654 if (expected_parameters_end_pos != kNoSourcePosition) { |
| 2655 // Check for '(' or ')' shenanigans in the parameter string for dynamic |
| 2656 // functions. |
| 2657 if (peek_position() != expected_parameters_end_pos) { |
| 2658 ReportMessageAt(Scanner::Location(expected_parameters_end_pos, |
| 2659 expected_parameters_end_pos + 1), |
| 2660 MessageTemplate::kExpectedEndOfParameters); |
| 2661 *ok = false; |
| 2662 return nullptr; |
| 2663 } |
| 2664 } |
2645 Expect(Token::RPAREN, CHECK_OK); | 2665 Expect(Token::RPAREN, CHECK_OK); |
2646 int formals_end_position = scanner()->location().end_pos; | 2666 int formals_end_position = scanner()->location().end_pos; |
2647 | 2667 |
2648 CheckArityRestrictions(formals.arity, kind, formals.has_rest, start_position, | 2668 CheckArityRestrictions(formals.arity, kind, formals.has_rest, start_position, |
2649 formals_end_position, CHECK_OK); | 2669 formals_end_position, CHECK_OK); |
2650 Expect(Token::LBRACE, CHECK_OK); | 2670 Expect(Token::LBRACE, CHECK_OK); |
2651 | 2671 |
2652 { | 2672 { |
2653 // Temporary zones can nest. When we migrate free variables (see below), we | 2673 // Temporary zones can nest. When we migrate free variables (see below), we |
2654 // need to recreate them in the previous Zone. | 2674 // need to recreate them in the previous Zone. |
(...skipping 2754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5409 | 5429 |
5410 return final_loop; | 5430 return final_loop; |
5411 } | 5431 } |
5412 | 5432 |
5413 #undef CHECK_OK | 5433 #undef CHECK_OK |
5414 #undef CHECK_OK_VOID | 5434 #undef CHECK_OK_VOID |
5415 #undef CHECK_FAILED | 5435 #undef CHECK_FAILED |
5416 | 5436 |
5417 } // namespace internal | 5437 } // namespace internal |
5418 } // namespace v8 | 5438 } // namespace v8 |
OLD | NEW |