| 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 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 compile_options_(info->compile_options()), | 631 compile_options_(info->compile_options()), |
| 632 cached_parse_data_(NULL), | 632 cached_parse_data_(NULL), |
| 633 total_preparse_skipped_(0), | 633 total_preparse_skipped_(0), |
| 634 pre_parse_timer_(NULL), | 634 pre_parse_timer_(NULL), |
| 635 parsing_on_main_thread_(true) { | 635 parsing_on_main_thread_(true) { |
| 636 // Even though we were passed ParseInfo, we should not store it in | 636 // Even though we were passed ParseInfo, we should not store it in |
| 637 // Parser - this makes sure that Isolate is not accidentally accessed via | 637 // Parser - this makes sure that Isolate is not accidentally accessed via |
| 638 // ParseInfo during background parsing. | 638 // ParseInfo during background parsing. |
| 639 DCHECK(!info->script().is_null() || info->source_stream() != nullptr || | 639 DCHECK(!info->script().is_null() || info->source_stream() != nullptr || |
| 640 info->character_stream() != nullptr); | 640 info->character_stream() != nullptr); |
| 641 set_allow_lazy(info->allow_lazy_parsing()); | 641 set_allow_lazy(FLAG_lazy && info->allow_lazy_parsing() && |
| 642 !info->is_native() && info->extension() == nullptr); |
| 642 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); | 643 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); |
| 643 set_allow_tailcalls(FLAG_harmony_tailcalls && !info->is_native() && | 644 set_allow_tailcalls(FLAG_harmony_tailcalls && !info->is_native() && |
| 644 info->isolate()->is_tail_call_elimination_enabled()); | 645 info->isolate()->is_tail_call_elimination_enabled()); |
| 645 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions); | 646 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions); |
| 646 set_allow_harmony_for_in(FLAG_harmony_for_in); | 647 set_allow_harmony_for_in(FLAG_harmony_for_in); |
| 647 set_allow_harmony_function_sent(FLAG_harmony_function_sent); | 648 set_allow_harmony_function_sent(FLAG_harmony_function_sent); |
| 648 set_allow_harmony_restrictive_declarations( | 649 set_allow_harmony_restrictive_declarations( |
| 649 FLAG_harmony_restrictive_declarations); | 650 FLAG_harmony_restrictive_declarations); |
| 650 set_allow_harmony_async_await(FLAG_harmony_async_await); | 651 set_allow_harmony_async_await(FLAG_harmony_async_await); |
| 651 set_allow_harmony_restrictive_generators(FLAG_harmony_restrictive_generators); | 652 set_allow_harmony_restrictive_generators(FLAG_harmony_restrictive_generators); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 } | 747 } |
| 747 | 748 |
| 748 | 749 |
| 749 FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) { | 750 FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) { |
| 750 // Note that this function can be called from the main thread or from a | 751 // Note that this function can be called from the main thread or from a |
| 751 // background thread. We should not access anything Isolate / heap dependent | 752 // background thread. We should not access anything Isolate / heap dependent |
| 752 // via ParseInfo, and also not pass it forward. | 753 // via ParseInfo, and also not pass it forward. |
| 753 DCHECK_NULL(scope_state_); | 754 DCHECK_NULL(scope_state_); |
| 754 DCHECK_NULL(target_stack_); | 755 DCHECK_NULL(target_stack_); |
| 755 | 756 |
| 756 Mode parsing_mode = FLAG_lazy && allow_lazy() ? PARSE_LAZILY : PARSE_EAGERLY; | 757 Mode parsing_mode = allow_lazy() ? PARSE_LAZILY : PARSE_EAGERLY; |
| 757 if (allow_natives() || extension_ != NULL) parsing_mode = PARSE_EAGERLY; | |
| 758 | 758 |
| 759 FunctionLiteral* result = NULL; | 759 FunctionLiteral* result = NULL; |
| 760 { | 760 { |
| 761 Scope* outer = original_scope_; | 761 Scope* outer = original_scope_; |
| 762 DCHECK_NOT_NULL(outer); | 762 DCHECK_NOT_NULL(outer); |
| 763 if (info->is_eval()) { | 763 if (info->is_eval()) { |
| 764 if (!outer->is_script_scope() || is_strict(info->language_mode())) { | 764 if (!outer->is_script_scope() || is_strict(info->language_mode())) { |
| 765 parsing_mode = PARSE_EAGERLY; | 765 parsing_mode = PARSE_EAGERLY; |
| 766 } | 766 } |
| 767 outer = NewEvalScope(outer); | 767 outer = NewEvalScope(outer); |
| (...skipping 2161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2929 // - The invoker of this parser can't depend on the AST being eagerly | 2929 // - The invoker of this parser can't depend on the AST being eagerly |
| 2930 // built (either because the function is about to be compiled, or | 2930 // built (either because the function is about to be compiled, or |
| 2931 // because the AST is going to be inspected for some reason). | 2931 // because the AST is going to be inspected for some reason). |
| 2932 // - Because of the above, we can't be attempting to parse a | 2932 // - Because of the above, we can't be attempting to parse a |
| 2933 // FunctionExpression; even without enclosing parentheses it might be | 2933 // FunctionExpression; even without enclosing parentheses it might be |
| 2934 // immediately invoked. | 2934 // immediately invoked. |
| 2935 // - The function literal shouldn't be hinted to eagerly compile. | 2935 // - The function literal shouldn't be hinted to eagerly compile. |
| 2936 // - For asm.js functions the body needs to be available when module | 2936 // - For asm.js functions the body needs to be available when module |
| 2937 // validation is active, because we examine the entire module at once. | 2937 // validation is active, because we examine the entire module at once. |
| 2938 bool use_temp_zone = | 2938 bool use_temp_zone = |
| 2939 !is_lazily_parsed && FLAG_lazy && !allow_natives() && | 2939 !is_lazily_parsed && allow_lazy() && |
| 2940 extension_ == NULL && allow_lazy() && | |
| 2941 function_type == FunctionLiteral::kDeclaration && | 2940 function_type == FunctionLiteral::kDeclaration && |
| 2942 eager_compile_hint != FunctionLiteral::kShouldEagerCompile && | 2941 eager_compile_hint != FunctionLiteral::kShouldEagerCompile && |
| 2943 !(FLAG_validate_asm && scope()->IsAsmModule()); | 2942 !(FLAG_validate_asm && scope()->IsAsmModule()); |
| 2944 | 2943 |
| 2945 DeclarationScope* main_scope = nullptr; | 2944 DeclarationScope* main_scope = nullptr; |
| 2946 if (use_temp_zone) { | 2945 if (use_temp_zone) { |
| 2947 // This Scope lives in the main Zone; we'll migrate data into it later. | 2946 // This Scope lives in the main Zone; we'll migrate data into it later. |
| 2948 main_scope = NewFunctionScope(kind); | 2947 main_scope = NewFunctionScope(kind); |
| 2949 } | 2948 } |
| 2950 | 2949 |
| (...skipping 2846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5797 node->Print(Isolate::Current()); | 5796 node->Print(Isolate::Current()); |
| 5798 } | 5797 } |
| 5799 #endif // DEBUG | 5798 #endif // DEBUG |
| 5800 | 5799 |
| 5801 #undef CHECK_OK | 5800 #undef CHECK_OK |
| 5802 #undef CHECK_OK_VOID | 5801 #undef CHECK_OK_VOID |
| 5803 #undef CHECK_FAILED | 5802 #undef CHECK_FAILED |
| 5804 | 5803 |
| 5805 } // namespace internal | 5804 } // namespace internal |
| 5806 } // namespace v8 | 5805 } // namespace v8 |
| OLD | NEW |