Chromium Code Reviews| 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(outer); | |
|
marja
2016/08/30 11:28:21
Nit: DCHECK_NOT_NULL
| |
| 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()); |
| 863 return nullptr; | 863 return nullptr; |
| 864 } | 864 } |
| 865 if (!(peek_any_identifier() || peek() == Token::LPAREN)) { | 865 if (!(peek_any_identifier() || peek() == Token::LPAREN)) { |
| 866 CHECK(stack_overflow()); | 866 CHECK(stack_overflow()); |
| 867 return nullptr; | 867 return nullptr; |
| 868 } | 868 } |
| 869 } | 869 } |
| 870 | 870 |
| 871 // TODO(adamk): We should construct this scope from the ScopeInfo. | 871 // TODO(adamk): We should construct this scope from the ScopeInfo. |
| 872 DeclarationScope* scope = NewFunctionScope(FunctionKind::kArrowFunction); | 872 DeclarationScope* scope = NewFunctionScope(FunctionKind::kArrowFunction); |
|
jochen (gone - plz use gerrit)
2016/08/30 11:25:56
here ^^^ the name is reused, which is confusing
| |
| 873 | 873 |
| 874 // These two bits only need to be explicitly set because we're | 874 // These two bits only need to be explicitly set because we're |
| 875 // not passing the ScopeInfo to the Scope constructor. | 875 // not passing the ScopeInfo to the Scope constructor. |
| 876 // TODO(adamk): Remove these calls once the above NewScope call | 876 // TODO(adamk): Remove these calls once the above NewScope call |
| 877 // passes the ScopeInfo. | 877 // passes the ScopeInfo. |
| 878 if (info->calls_eval()) { | 878 if (info->calls_eval()) { |
| 879 scope->RecordEvalCall(); | 879 scope->RecordEvalCall(); |
| 880 } | 880 } |
| 881 SetLanguageMode(scope, info->language_mode()); | 881 SetLanguageMode(scope, info->language_mode()); |
| 882 | 882 |
| (...skipping 37 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(this->scope(), outer); |
|
marja
2016/08/30 11:28:21
Can this now be scope() instead of this->scope() o
| |
| 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 5800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6741 node->Print(Isolate::Current()); | 6741 node->Print(Isolate::Current()); |
| 6742 } | 6742 } |
| 6743 #endif // DEBUG | 6743 #endif // DEBUG |
| 6744 | 6744 |
| 6745 #undef CHECK_OK | 6745 #undef CHECK_OK |
| 6746 #undef CHECK_OK_VOID | 6746 #undef CHECK_OK_VOID |
| 6747 #undef CHECK_FAILED | 6747 #undef CHECK_FAILED |
| 6748 | 6748 |
| 6749 } // namespace internal | 6749 } // namespace internal |
| 6750 } // namespace v8 | 6750 } // namespace v8 |
| OLD | NEW |