| 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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 DeclarationScope* function_scope = NewFunctionScope(kind); | 225 DeclarationScope* function_scope = NewFunctionScope(kind); |
| 226 SetLanguageMode(function_scope, | 226 SetLanguageMode(function_scope, |
| 227 static_cast<LanguageMode>(language_mode | STRICT)); | 227 static_cast<LanguageMode>(language_mode | STRICT)); |
| 228 // Set start and end position to the same value | 228 // Set start and end position to the same value |
| 229 function_scope->set_start_position(pos); | 229 function_scope->set_start_position(pos); |
| 230 function_scope->set_end_position(pos); | 230 function_scope->set_end_position(pos); |
| 231 ZoneList<Statement*>* body = NULL; | 231 ZoneList<Statement*>* body = NULL; |
| 232 | 232 |
| 233 { | 233 { |
| 234 FunctionState function_state(&function_state_, &scope_state_, | 234 FunctionState function_state(&function_state_, &scope_state_, |
| 235 function_scope, kind); | 235 function_scope); |
| 236 | 236 |
| 237 body = new (zone()) ZoneList<Statement*>(call_super ? 2 : 1, zone()); | 237 body = new (zone()) ZoneList<Statement*>(call_super ? 2 : 1, zone()); |
| 238 if (call_super) { | 238 if (call_super) { |
| 239 // $super_constructor = %_GetSuperConstructor(<this-function>) | 239 // $super_constructor = %_GetSuperConstructor(<this-function>) |
| 240 // %reflect_construct( | 240 // %reflect_construct( |
| 241 // $super_constructor, InternalArray(...args), new.target) | 241 // $super_constructor, InternalArray(...args), new.target) |
| 242 auto constructor_args_name = ast_value_factory()->empty_string(); | 242 auto constructor_args_name = ast_value_factory()->empty_string(); |
| 243 bool is_duplicate; | 243 bool is_duplicate; |
| 244 bool is_rest = true; | 244 bool is_rest = true; |
| 245 bool is_optional = false; | 245 bool is_optional = false; |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 // declared at the module level but not MODULE-allocated. | 779 // declared at the module level but not MODULE-allocated. |
| 780 parsing_mode = PARSE_EAGERLY; | 780 parsing_mode = PARSE_EAGERLY; |
| 781 } | 781 } |
| 782 | 782 |
| 783 DeclarationScope* scope = outer->AsDeclarationScope(); | 783 DeclarationScope* scope = outer->AsDeclarationScope(); |
| 784 | 784 |
| 785 scope->set_start_position(0); | 785 scope->set_start_position(0); |
| 786 | 786 |
| 787 // Enter 'scope' with the given parsing mode. | 787 // Enter 'scope' with the given parsing mode. |
| 788 ParsingModeScope parsing_mode_scope(this, parsing_mode); | 788 ParsingModeScope parsing_mode_scope(this, parsing_mode); |
| 789 FunctionState function_state(&function_state_, &scope_state_, scope, | 789 FunctionState function_state(&function_state_, &scope_state_, scope); |
| 790 kNormalFunction); | |
| 791 | 790 |
| 792 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); | 791 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); |
| 793 bool ok = true; | 792 bool ok = true; |
| 794 int beg_pos = scanner()->location().beg_pos; | 793 int beg_pos = scanner()->location().beg_pos; |
| 795 parsing_module_ = info->is_module(); | 794 parsing_module_ = info->is_module(); |
| 796 if (parsing_module_) { | 795 if (parsing_module_) { |
| 797 // Declare the special module parameter. | 796 // Declare the special module parameter. |
| 798 auto name = ast_value_factory()->empty_string(); | 797 auto name = ast_value_factory()->empty_string(); |
| 799 bool is_duplicate; | 798 bool is_duplicate; |
| 800 bool is_rest = false; | 799 bool is_rest = false; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 929 | 928 |
| 930 // Place holder for the result. | 929 // Place holder for the result. |
| 931 FunctionLiteral* result = nullptr; | 930 FunctionLiteral* result = nullptr; |
| 932 | 931 |
| 933 { | 932 { |
| 934 // Parse the function literal. | 933 // Parse the function literal. |
| 935 Scope* outer = original_scope_; | 934 Scope* outer = original_scope_; |
| 936 DeclarationScope* outer_function = outer->GetClosureScope(); | 935 DeclarationScope* outer_function = outer->GetClosureScope(); |
| 937 DCHECK(outer); | 936 DCHECK(outer); |
| 938 FunctionState function_state(&function_state_, &scope_state_, | 937 FunctionState function_state(&function_state_, &scope_state_, |
| 939 outer_function, | 938 outer_function); |
| 940 outer_function->function_kind()); | |
| 941 BlockState block_state(&scope_state_, outer); | 939 BlockState block_state(&scope_state_, outer); |
| 942 DCHECK(is_sloppy(outer->language_mode()) || | 940 DCHECK(is_sloppy(outer->language_mode()) || |
| 943 is_strict(info->language_mode())); | 941 is_strict(info->language_mode())); |
| 944 FunctionLiteral::FunctionType function_type = ComputeFunctionType(info); | 942 FunctionLiteral::FunctionType function_type = ComputeFunctionType(info); |
| 945 bool ok = true; | 943 bool ok = true; |
| 946 | 944 |
| 947 if (info->is_arrow()) { | 945 if (info->is_arrow()) { |
| 948 bool is_async = allow_harmony_async_await() && info->is_async(); | 946 bool is_async = allow_harmony_async_await() && info->is_async(); |
| 949 if (is_async) { | 947 if (is_async) { |
| 950 DCHECK(!scanner()->HasAnyLineTerminatorAfterNext()); | 948 DCHECK(!scanner()->HasAnyLineTerminatorAfterNext()); |
| 951 if (!Check(Token::ASYNC)) { | 949 if (!Check(Token::ASYNC)) { |
| 952 CHECK(stack_overflow()); | 950 CHECK(stack_overflow()); |
| 953 return nullptr; | 951 return nullptr; |
| 954 } | 952 } |
| 955 if (!(peek_any_identifier() || peek() == Token::LPAREN)) { | 953 if (!(peek_any_identifier() || peek() == Token::LPAREN)) { |
| 956 CHECK(stack_overflow()); | 954 CHECK(stack_overflow()); |
| 957 return nullptr; | 955 return nullptr; |
| 958 } | 956 } |
| 959 } | 957 } |
| 960 | 958 |
| 961 // TODO(adamk): We should construct this scope from the ScopeInfo. | 959 // TODO(adamk): We should construct this scope from the ScopeInfo. |
| 962 DeclarationScope* scope = NewFunctionScope(FunctionKind::kArrowFunction); | 960 FunctionKind arrow_kind = is_async ? kAsyncArrowFunction : kArrowFunction; |
| 961 DeclarationScope* scope = NewFunctionScope(arrow_kind); |
| 963 | 962 |
| 964 // These two bits only need to be explicitly set because we're | 963 // These two bits only need to be explicitly set because we're |
| 965 // not passing the ScopeInfo to the Scope constructor. | 964 // not passing the ScopeInfo to the Scope constructor. |
| 966 // TODO(adamk): Remove these calls once the above NewScope call | 965 // TODO(adamk): Remove these calls once the above NewScope call |
| 967 // passes the ScopeInfo. | 966 // passes the ScopeInfo. |
| 968 if (info->calls_eval()) { | 967 if (info->calls_eval()) { |
| 969 scope->RecordEvalCall(); | 968 scope->RecordEvalCall(); |
| 970 } | 969 } |
| 971 SetLanguageMode(scope, info->language_mode()); | 970 SetLanguageMode(scope, info->language_mode()); |
| 972 | 971 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 987 // BindingIdentifier | 986 // BindingIdentifier |
| 988 ParseFormalParameter(&formals, &ok); | 987 ParseFormalParameter(&formals, &ok); |
| 989 if (ok) DeclareFormalParameter(formals.scope, formals.at(0)); | 988 if (ok) DeclareFormalParameter(formals.scope, formals.at(0)); |
| 990 } | 989 } |
| 991 } | 990 } |
| 992 | 991 |
| 993 if (ok) { | 992 if (ok) { |
| 994 checkpoint.Restore(&formals.materialized_literals_count); | 993 checkpoint.Restore(&formals.materialized_literals_count); |
| 995 // Pass `accept_IN=true` to ParseArrowFunctionLiteral --- This should | 994 // Pass `accept_IN=true` to ParseArrowFunctionLiteral --- This should |
| 996 // not be observable, or else the preparser would have failed. | 995 // not be observable, or else the preparser would have failed. |
| 997 Expression* expression = | 996 Expression* expression = ParseArrowFunctionLiteral(true, formals, &ok); |
| 998 ParseArrowFunctionLiteral(true, formals, is_async, &ok); | |
| 999 if (ok) { | 997 if (ok) { |
| 1000 // Scanning must end at the same position that was recorded | 998 // Scanning must end at the same position that was recorded |
| 1001 // previously. If not, parsing has been interrupted due to a stack | 999 // previously. If not, parsing has been interrupted due to a stack |
| 1002 // overflow, at which point the partially parsed arrow function | 1000 // overflow, at which point the partially parsed arrow function |
| 1003 // concise body happens to be a valid expression. This is a problem | 1001 // concise body happens to be a valid expression. This is a problem |
| 1004 // only for arrow functions with single expression bodies, since there | 1002 // only for arrow functions with single expression bodies, since there |
| 1005 // is no end token such as "}" for normal functions. | 1003 // is no end token such as "}" for normal functions. |
| 1006 if (scanner()->location().end_pos == info->end_position()) { | 1004 if (scanner()->location().end_pos == info->end_position()) { |
| 1007 // The pre-parser saw an arrow function here, so the full parser | 1005 // The pre-parser saw an arrow function here, so the full parser |
| 1008 // must produce a FunctionLiteral. | 1006 // must produce a FunctionLiteral. |
| (...skipping 1767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2776 DiscardableZoneScope zone_scope(this, &temp_zone, use_temp_zone); | 2774 DiscardableZoneScope zone_scope(this, &temp_zone, use_temp_zone); |
| 2777 | 2775 |
| 2778 DeclarationScope* scope = NewFunctionScope(kind); | 2776 DeclarationScope* scope = NewFunctionScope(kind); |
| 2779 SetLanguageMode(scope, language_mode); | 2777 SetLanguageMode(scope, language_mode); |
| 2780 if (!use_temp_zone) { | 2778 if (!use_temp_zone) { |
| 2781 main_scope = scope; | 2779 main_scope = scope; |
| 2782 } else { | 2780 } else { |
| 2783 DCHECK(main_scope->zone() != scope->zone()); | 2781 DCHECK(main_scope->zone() != scope->zone()); |
| 2784 } | 2782 } |
| 2785 | 2783 |
| 2786 FunctionState function_state(&function_state_, &scope_state_, scope, kind); | 2784 FunctionState function_state(&function_state_, &scope_state_, scope); |
| 2787 #ifdef DEBUG | 2785 #ifdef DEBUG |
| 2788 scope->SetScopeName(function_name); | 2786 scope->SetScopeName(function_name); |
| 2789 #endif | 2787 #endif |
| 2790 ExpressionClassifier formals_classifier(this, &duplicate_finder); | 2788 ExpressionClassifier formals_classifier(this, &duplicate_finder); |
| 2791 | 2789 |
| 2792 if (is_generator) { | 2790 if (is_generator) { |
| 2793 // For generators, allocating variables in contexts is currently a win | 2791 // For generators, allocating variables in contexts is currently a win |
| 2794 // because it minimizes the work needed to suspend and resume an | 2792 // because it minimizes the work needed to suspend and resume an |
| 2795 // activation. The machine code produced for generators (by full-codegen) | 2793 // activation. The machine code produced for generators (by full-codegen) |
| 2796 // relies on this forced context allocation, but not in an essential way. | 2794 // relies on this forced context allocation, but not in an essential way. |
| (...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3545 // .class-field-0-func(), | 3543 // .class-field-0-func(), |
| 3546 // DONT_ENUM, false) | 3544 // DONT_ENUM, false) |
| 3547 | 3545 |
| 3548 RaiseLanguageMode(STRICT); | 3546 RaiseLanguageMode(STRICT); |
| 3549 FunctionKind kind = FunctionKind::kConciseMethod; | 3547 FunctionKind kind = FunctionKind::kConciseMethod; |
| 3550 DeclarationScope* initializer_scope = NewFunctionScope(kind); | 3548 DeclarationScope* initializer_scope = NewFunctionScope(kind); |
| 3551 SetLanguageMode(initializer_scope, language_mode()); | 3549 SetLanguageMode(initializer_scope, language_mode()); |
| 3552 initializer_scope->set_start_position(scanner()->location().end_pos); | 3550 initializer_scope->set_start_position(scanner()->location().end_pos); |
| 3553 initializer_scope->set_end_position(scanner()->location().end_pos); | 3551 initializer_scope->set_end_position(scanner()->location().end_pos); |
| 3554 FunctionState initializer_state(&function_state_, &scope_state_, | 3552 FunctionState initializer_state(&function_state_, &scope_state_, |
| 3555 initializer_scope, kind); | 3553 initializer_scope); |
| 3556 ZoneList<Statement*>* body = new (zone()) ZoneList<Statement*>(count, zone()); | 3554 ZoneList<Statement*>* body = new (zone()) ZoneList<Statement*>(count, zone()); |
| 3557 for (int i = 0; i < count; ++i) { | 3555 for (int i = 0; i < count; ++i) { |
| 3558 const AstRawString* name = | 3556 const AstRawString* name = |
| 3559 ClassFieldVariableName(true, ast_value_factory(), i); | 3557 ClassFieldVariableName(true, ast_value_factory(), i); |
| 3560 VariableProxy* name_proxy = scope()->NewUnresolved(factory(), name); | 3558 VariableProxy* name_proxy = scope()->NewUnresolved(factory(), name); |
| 3561 const AstRawString* function_name = | 3559 const AstRawString* function_name = |
| 3562 ClassFieldVariableName(false, ast_value_factory(), i); | 3560 ClassFieldVariableName(false, ast_value_factory(), i); |
| 3563 VariableProxy* function_proxy = | 3561 VariableProxy* function_proxy = |
| 3564 scope()->NewUnresolved(factory(), function_name); | 3562 scope()->NewUnresolved(factory(), function_name); |
| 3565 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); | 3563 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); |
| (...skipping 2039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5605 | 5603 |
| 5606 return final_loop; | 5604 return final_loop; |
| 5607 } | 5605 } |
| 5608 | 5606 |
| 5609 #undef CHECK_OK | 5607 #undef CHECK_OK |
| 5610 #undef CHECK_OK_VOID | 5608 #undef CHECK_OK_VOID |
| 5611 #undef CHECK_FAILED | 5609 #undef CHECK_FAILED |
| 5612 | 5610 |
| 5613 } // namespace internal | 5611 } // namespace internal |
| 5614 } // namespace v8 | 5612 } // namespace v8 |
| OLD | NEW |