| 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 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 // via ParseInfo, and also not pass it forward. | 663 // via ParseInfo, and also not pass it forward. |
| 664 DCHECK_NULL(scope_state_); | 664 DCHECK_NULL(scope_state_); |
| 665 DCHECK_NULL(target_stack_); | 665 DCHECK_NULL(target_stack_); |
| 666 | 666 |
| 667 Mode parsing_mode = FLAG_lazy && allow_lazy() ? PARSE_LAZILY : PARSE_EAGERLY; | 667 Mode parsing_mode = FLAG_lazy && allow_lazy() ? PARSE_LAZILY : PARSE_EAGERLY; |
| 668 if (allow_natives() || extension_ != NULL) parsing_mode = PARSE_EAGERLY; | 668 if (allow_natives() || extension_ != NULL) parsing_mode = PARSE_EAGERLY; |
| 669 | 669 |
| 670 FunctionLiteral* result = NULL; | 670 FunctionLiteral* result = NULL; |
| 671 { | 671 { |
| 672 Scope* outer = original_scope_; | 672 Scope* outer = original_scope_; |
| 673 DCHECK_NOT_NULL(outer); |
| 673 // If there's a chance that there's a reference to global 'this', predeclare | 674 // If there's a chance that there's a reference to global 'this', predeclare |
| 674 // it as a dynamic global on the script scope. | 675 // it as a dynamic global on the script scope. |
| 675 if (outer->GetReceiverScope()->is_script_scope()) { | 676 if (outer->GetReceiverScope()->is_script_scope()) { |
| 676 info->script_scope()->DeclareDynamicGlobal( | 677 info->script_scope()->DeclareDynamicGlobal( |
| 677 ast_value_factory()->this_string(), Variable::THIS); | 678 ast_value_factory()->this_string(), Variable::THIS); |
| 678 } | 679 } |
| 679 DCHECK(outer); | |
| 680 if (info->is_eval()) { | 680 if (info->is_eval()) { |
| 681 if (!outer->is_script_scope() || is_strict(info->language_mode())) { | 681 if (!outer->is_script_scope() || is_strict(info->language_mode())) { |
| 682 parsing_mode = PARSE_EAGERLY; | 682 parsing_mode = PARSE_EAGERLY; |
| 683 } | 683 } |
| 684 outer = NewEvalScope(outer); | 684 outer = NewEvalScope(outer); |
| 685 } else if (info->is_module()) { | 685 } else if (info->is_module()) { |
| 686 DCHECK_EQ(outer, info->script_scope()); | 686 DCHECK_EQ(outer, info->script_scope()); |
| 687 outer = NewModuleScope(info->script_scope()); | 687 outer = NewModuleScope(info->script_scope()); |
| 688 } | 688 } |
| 689 | 689 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 fni_ = new (zone()) FuncNameInferrer(ast_value_factory(), zone()); | 832 fni_ = new (zone()) FuncNameInferrer(ast_value_factory(), zone()); |
| 833 fni_->PushEnclosingName(raw_name); | 833 fni_->PushEnclosingName(raw_name); |
| 834 | 834 |
| 835 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); | 835 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); |
| 836 | 836 |
| 837 // Place holder for the result. | 837 // Place holder for the result. |
| 838 FunctionLiteral* result = nullptr; | 838 FunctionLiteral* result = nullptr; |
| 839 | 839 |
| 840 { | 840 { |
| 841 // Parse the function literal. | 841 // Parse the function literal. |
| 842 Scope* scope = original_scope_; | 842 Scope* outer = original_scope_; |
| 843 DCHECK(scope); | 843 DCHECK(outer); |
| 844 // If there's a chance that there's a reference to global 'this', predeclare | 844 // If there's a chance that there's a reference to global 'this', predeclare |
| 845 // it as a dynamic global on the script scope. | 845 // it as a dynamic global on the script scope. |
| 846 if (info->is_arrow() && scope->GetReceiverScope()->is_script_scope()) { | 846 if (info->is_arrow() && outer->GetReceiverScope()->is_script_scope()) { |
| 847 info->script_scope()->DeclareDynamicGlobal( | 847 info->script_scope()->DeclareDynamicGlobal( |
| 848 ast_value_factory()->this_string(), Variable::THIS); | 848 ast_value_factory()->this_string(), Variable::THIS); |
| 849 } | 849 } |
| 850 FunctionState function_state(&function_state_, &scope_state_, scope, | 850 FunctionState function_state(&function_state_, &scope_state_, outer, |
| 851 info->function_kind()); | 851 info->function_kind()); |
| 852 DCHECK(is_sloppy(scope->language_mode()) || | 852 DCHECK(is_sloppy(outer->language_mode()) || |
| 853 is_strict(info->language_mode())); | 853 is_strict(info->language_mode())); |
| 854 FunctionLiteral::FunctionType function_type = ComputeFunctionType(info); | 854 FunctionLiteral::FunctionType function_type = ComputeFunctionType(info); |
| 855 bool ok = true; | 855 bool ok = true; |
| 856 | 856 |
| 857 if (info->is_arrow()) { | 857 if (info->is_arrow()) { |
| 858 bool is_async = allow_harmony_async_await() && info->is_async(); | 858 bool is_async = allow_harmony_async_await() && info->is_async(); |
| 859 if (is_async) { | 859 if (is_async) { |
| 860 DCHECK(!scanner()->HasAnyLineTerminatorAfterNext()); | 860 DCHECK(!scanner()->HasAnyLineTerminatorAfterNext()); |
| 861 if (!Check(Token::ASYNC)) { | 861 if (!Check(Token::ASYNC)) { |
| 862 CHECK(stack_overflow()); | 862 CHECK(stack_overflow()); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 // The pre-parser saw an arrow function here, so the full parser | 920 // The pre-parser saw an arrow function here, so the full parser |
| 921 // must produce a FunctionLiteral. | 921 // must produce a FunctionLiteral. |
| 922 DCHECK(expression->IsFunctionLiteral()); | 922 DCHECK(expression->IsFunctionLiteral()); |
| 923 result = expression->AsFunctionLiteral(); | 923 result = expression->AsFunctionLiteral(); |
| 924 } else { | 924 } else { |
| 925 ok = false; | 925 ok = false; |
| 926 } | 926 } |
| 927 } | 927 } |
| 928 } | 928 } |
| 929 } else if (info->is_default_constructor()) { | 929 } else if (info->is_default_constructor()) { |
| 930 DCHECK_EQ(this->scope(), scope); | 930 DCHECK_EQ(scope(), outer); |
| 931 result = DefaultConstructor( | 931 result = DefaultConstructor( |
| 932 raw_name, IsSubclassConstructor(info->function_kind()), | 932 raw_name, IsSubclassConstructor(info->function_kind()), |
| 933 info->start_position(), info->end_position(), info->language_mode()); | 933 info->start_position(), info->end_position(), info->language_mode()); |
| 934 } else { | 934 } else { |
| 935 result = ParseFunctionLiteral(raw_name, Scanner::Location::invalid(), | 935 result = ParseFunctionLiteral(raw_name, Scanner::Location::invalid(), |
| 936 kSkipFunctionNameCheck, | 936 kSkipFunctionNameCheck, |
| 937 info->function_kind(), kNoSourcePosition, | 937 info->function_kind(), kNoSourcePosition, |
| 938 function_type, info->language_mode(), &ok); | 938 function_type, info->language_mode(), &ok); |
| 939 } | 939 } |
| 940 // Make sure the results agree. | 940 // Make sure the results agree. |
| (...skipping 5717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6658 node->Print(Isolate::Current()); | 6658 node->Print(Isolate::Current()); |
| 6659 } | 6659 } |
| 6660 #endif // DEBUG | 6660 #endif // DEBUG |
| 6661 | 6661 |
| 6662 #undef CHECK_OK | 6662 #undef CHECK_OK |
| 6663 #undef CHECK_OK_VOID | 6663 #undef CHECK_OK_VOID |
| 6664 #undef CHECK_FAILED | 6664 #undef CHECK_FAILED |
| 6665 | 6665 |
| 6666 } // namespace internal | 6666 } // namespace internal |
| 6667 } // namespace v8 | 6667 } // namespace v8 |
| OLD | NEW |