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 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 FunctionLiteral* result = NULL; | 788 FunctionLiteral* result = NULL; |
789 { | 789 { |
790 Scope* outer = original_scope_; | 790 Scope* outer = original_scope_; |
791 DCHECK_NOT_NULL(outer); | 791 DCHECK_NOT_NULL(outer); |
792 parsing_module_ = info->is_module(); | 792 parsing_module_ = info->is_module(); |
793 if (info->is_eval()) { | 793 if (info->is_eval()) { |
794 outer = NewEvalScope(outer); | 794 outer = NewEvalScope(outer); |
795 } else if (parsing_module_) { | 795 } else if (parsing_module_) { |
796 DCHECK_EQ(outer, info->script_scope()); | 796 DCHECK_EQ(outer, info->script_scope()); |
797 outer = NewModuleScope(info->script_scope()); | 797 outer = NewModuleScope(info->script_scope()); |
798 // Never do lazy parsing in modules. If we want to support this in the | |
799 // future, we must force context-allocation for all variables that are | |
800 // declared at the module level but not MODULE-allocated. | |
801 parsing_mode = PARSE_EAGERLY; | |
802 } | 798 } |
803 | 799 |
804 DeclarationScope* scope = outer->AsDeclarationScope(); | 800 DeclarationScope* scope = outer->AsDeclarationScope(); |
805 | 801 |
806 scope->set_start_position(0); | 802 scope->set_start_position(0); |
807 | 803 |
808 // Enter 'scope' with the given parsing mode. | 804 // Enter 'scope' with the given parsing mode. |
809 ParsingModeScope parsing_mode_scope(this, parsing_mode); | 805 ParsingModeScope parsing_mode_scope(this, parsing_mode); |
810 FunctionState function_state(&function_state_, &scope_state_, scope); | 806 FunctionState function_state(&function_state_, &scope_state_, scope); |
811 | 807 |
(...skipping 1806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2618 // immediately). bar can be parsed lazily, but we need to parse it in a mode | 2614 // immediately). bar can be parsed lazily, but we need to parse it in a mode |
2619 // that tracks unresolved variables. | 2615 // that tracks unresolved variables. |
2620 DCHECK_IMPLIES(mode() == PARSE_LAZILY, FLAG_lazy); | 2616 DCHECK_IMPLIES(mode() == PARSE_LAZILY, FLAG_lazy); |
2621 DCHECK_IMPLIES(mode() == PARSE_LAZILY, allow_lazy()); | 2617 DCHECK_IMPLIES(mode() == PARSE_LAZILY, allow_lazy()); |
2622 DCHECK_IMPLIES(mode() == PARSE_LAZILY, extension_ == nullptr); | 2618 DCHECK_IMPLIES(mode() == PARSE_LAZILY, extension_ == nullptr); |
2623 | 2619 |
2624 bool can_preparse = mode() == PARSE_LAZILY && | 2620 bool can_preparse = mode() == PARSE_LAZILY && |
2625 eager_compile_hint == FunctionLiteral::kShouldLazyCompile; | 2621 eager_compile_hint == FunctionLiteral::kShouldLazyCompile; |
2626 | 2622 |
2627 bool is_lazy_top_level_function = | 2623 bool is_lazy_top_level_function = |
2628 can_preparse && scope()->AllowsLazyParsingWithoutUnresolvedVariables(); | 2624 can_preparse && impl()->AllowsLazyParsingWithoutUnresolvedVariables(); |
2629 | 2625 |
2630 // Determine whether we can still lazy parse the inner function. | 2626 // Determine whether we can still lazy parse the inner function. |
2631 // The preconditions are: | 2627 // The preconditions are: |
2632 // - Lazy compilation has to be enabled. | 2628 // - Lazy compilation has to be enabled. |
2633 // - Neither V8 natives nor native function declarations can be allowed, | 2629 // - Neither V8 natives nor native function declarations can be allowed, |
2634 // since parsing one would retroactively force the function to be | 2630 // since parsing one would retroactively force the function to be |
2635 // eagerly compiled. | 2631 // eagerly compiled. |
2636 // - The invoker of this parser can't depend on the AST being eagerly | 2632 // - The invoker of this parser can't depend on the AST being eagerly |
2637 // built (either because the function is about to be compiled, or | 2633 // built (either because the function is about to be compiled, or |
2638 // because the AST is going to be inspected for some reason). | 2634 // because the AST is going to be inspected for some reason). |
(...skipping 2813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5452 | 5448 |
5453 return final_loop; | 5449 return final_loop; |
5454 } | 5450 } |
5455 | 5451 |
5456 #undef CHECK_OK | 5452 #undef CHECK_OK |
5457 #undef CHECK_OK_VOID | 5453 #undef CHECK_OK_VOID |
5458 #undef CHECK_FAILED | 5454 #undef CHECK_FAILED |
5459 | 5455 |
5460 } // namespace internal | 5456 } // namespace internal |
5461 } // namespace v8 | 5457 } // namespace v8 |
OLD | NEW |