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 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 log_ = &recorder; | 717 log_ = &recorder; |
718 } else if (consume_cached_parse_data()) { | 718 } else if (consume_cached_parse_data()) { |
719 cached_parse_data_->Initialize(); | 719 cached_parse_data_->Initialize(); |
720 } | 720 } |
721 | 721 |
722 DeserializeScopeChain(info, info->maybe_outer_scope_info()); | 722 DeserializeScopeChain(info, info->maybe_outer_scope_info()); |
723 | 723 |
724 source = String::Flatten(source); | 724 source = String::Flatten(source); |
725 FunctionLiteral* result; | 725 FunctionLiteral* result; |
726 | 726 |
| 727 int start_position = info->start_position(); |
| 728 int end_position = info->end_position(); |
| 729 if (start_position == 0 && end_position == 0) { |
| 730 end_position = source->length(); |
| 731 } |
| 732 |
727 { | 733 { |
728 std::unique_ptr<Utf16CharacterStream> stream(ScannerStream::For(source)); | 734 std::unique_ptr<Utf16CharacterStream> stream( |
| 735 ScannerStream::For(source, start_position, end_position)); |
729 scanner_.Initialize(stream.get()); | 736 scanner_.Initialize(stream.get()); |
730 result = DoParseProgram(info); | 737 result = DoParseProgram(info); |
731 } | 738 } |
732 if (result != NULL) { | 739 if (result != NULL) { |
733 DCHECK_EQ(scanner_.peek_location().beg_pos, source->length()); | 740 DCHECK_EQ(scanner_.peek_location().beg_pos, end_position); |
734 } | 741 } |
735 HandleSourceURLComments(isolate, info->script()); | 742 HandleSourceURLComments(isolate, info->script()); |
736 | 743 |
737 if (FLAG_trace_parse && result != NULL) { | 744 if (FLAG_trace_parse && result != NULL) { |
738 double ms = timer.Elapsed().InMillisecondsF(); | 745 double ms = timer.Elapsed().InMillisecondsF(); |
739 if (info->is_eval()) { | 746 if (info->is_eval()) { |
740 PrintF("[parsing eval"); | 747 PrintF("[parsing eval"); |
741 } else if (info->script()->name()->IsString()) { | 748 } else if (info->script()->name()->IsString()) { |
742 String* name = String::cast(info->script()->name()); | 749 String* name = String::cast(info->script()->name()); |
743 std::unique_ptr<char[]> name_chars = name->ToCString(); | 750 std::unique_ptr<char[]> name_chars = name->ToCString(); |
(...skipping 1871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2615 // - Neither V8 natives nor native function declarations can be allowed, | 2622 // - Neither V8 natives nor native function declarations can be allowed, |
2616 // since parsing one would retroactively force the function to be | 2623 // since parsing one would retroactively force the function to be |
2617 // eagerly compiled. | 2624 // eagerly compiled. |
2618 // - The invoker of this parser can't depend on the AST being eagerly | 2625 // - The invoker of this parser can't depend on the AST being eagerly |
2619 // built (either because the function is about to be compiled, or | 2626 // built (either because the function is about to be compiled, or |
2620 // because the AST is going to be inspected for some reason). | 2627 // because the AST is going to be inspected for some reason). |
2621 // - Because of the above, we can't be attempting to parse a | 2628 // - Because of the above, we can't be attempting to parse a |
2622 // FunctionExpression; even without enclosing parentheses it might be | 2629 // FunctionExpression; even without enclosing parentheses it might be |
2623 // immediately invoked. | 2630 // immediately invoked. |
2624 // - The function literal shouldn't be hinted to eagerly compile. | 2631 // - The function literal shouldn't be hinted to eagerly compile. |
2625 // - For asm.js functions the body needs to be available when module | |
2626 // validation is active, because we examine the entire module at once. | |
2627 | |
2628 // Inner functions will be parsed using a temporary Zone. After parsing, we | |
2629 // will migrate unresolved variable into a Scope in the main Zone. | |
2630 // TODO(marja): Refactor parsing modes: simplify this. | |
2631 bool use_temp_zone = | 2632 bool use_temp_zone = |
2632 allow_lazy() && function_type == FunctionLiteral::kDeclaration && | 2633 allow_lazy() && function_type == FunctionLiteral::kDeclaration && |
2633 eager_compile_hint != FunctionLiteral::kShouldEagerCompile && | 2634 eager_compile_hint != FunctionLiteral::kShouldEagerCompile; |
2634 !(FLAG_validate_asm && scope()->IsAsmModule()); | |
2635 bool is_lazy_inner_function = | 2635 bool is_lazy_inner_function = |
2636 use_temp_zone && FLAG_lazy_inner_functions && !is_lazy_top_level_function; | 2636 use_temp_zone && FLAG_lazy_inner_functions && !is_lazy_top_level_function; |
2637 | 2637 |
2638 // This Scope lives in the main zone. We'll migrate data into that zone later. | 2638 // This Scope lives in the main zone. We'll migrate data into that zone later. |
2639 DeclarationScope* scope = NewFunctionScope(kind); | 2639 DeclarationScope* scope = NewFunctionScope(kind); |
2640 SetLanguageMode(scope, language_mode); | 2640 SetLanguageMode(scope, language_mode); |
2641 | 2641 |
2642 ZoneList<Statement*>* body = nullptr; | 2642 ZoneList<Statement*>* body = nullptr; |
2643 int arity = -1; | 2643 int arity = -1; |
2644 int materialized_literal_count = -1; | 2644 int materialized_literal_count = -1; |
(...skipping 2797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5442 | 5442 |
5443 return final_loop; | 5443 return final_loop; |
5444 } | 5444 } |
5445 | 5445 |
5446 #undef CHECK_OK | 5446 #undef CHECK_OK |
5447 #undef CHECK_OK_VOID | 5447 #undef CHECK_OK_VOID |
5448 #undef CHECK_FAILED | 5448 #undef CHECK_FAILED |
5449 | 5449 |
5450 } // namespace internal | 5450 } // namespace internal |
5451 } // namespace v8 | 5451 } // namespace v8 |
OLD | NEW |